Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -34,11 +34,16 @@ def get_all_tracks_from_playlists(sp, playlist_uris, verbose=False):
|
|
34 |
if verbose: print(f'Extracting all tracks from {len(playlist_uris)} playlists.')
|
35 |
# load data
|
36 |
cache_path = './cache_track_features_tmp.json'
|
37 |
-
if not os.path.exists(cache_path):
|
38 |
with open(cache_path, 'w') as f:
|
39 |
json.dump(dict(), f)
|
40 |
with open(cache_path, 'r') as f:
|
41 |
data = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
42 |
if verbose: print(f'\t{len(data.keys())} tracks loaded from cache')
|
43 |
|
44 |
# for each playlist, extract all tracks, remove doubles
|
@@ -134,17 +139,6 @@ def get_all_tracks_from_user(sp, user_id='bkayf', verbose=False):
|
|
134 |
json.dump(data, f)
|
135 |
return data
|
136 |
|
137 |
-
def get_audio_features_from_tracks(sp, data_tracks):
|
138 |
-
uris = list(data_tracks.keys())
|
139 |
-
offset = 0
|
140 |
-
done = False
|
141 |
-
while not done:
|
142 |
-
# extract audio features by groups of 100
|
143 |
-
|
144 |
-
for i_t, x in enumerate(tracks):
|
145 |
-
print(i_t)
|
146 |
-
output[info].append(sp.audio_features(x["track"]["uri"]))
|
147 |
-
|
148 |
|
149 |
def get_uri_from_link(link):
|
150 |
return link.split("?")[0].split("/")[-1]
|
|
|
34 |
if verbose: print(f'Extracting all tracks from {len(playlist_uris)} playlists.')
|
35 |
# load data
|
36 |
cache_path = './cache_track_features_tmp.json'
|
37 |
+
if True: #not os.path.exists(cache_path):
|
38 |
with open(cache_path, 'w') as f:
|
39 |
json.dump(dict(), f)
|
40 |
with open(cache_path, 'r') as f:
|
41 |
data = json.load(f)
|
42 |
+
for k in list(data.keys()).copy():
|
43 |
+
if k not in playlist_uris:
|
44 |
+
data.pop(k)
|
45 |
+
else:
|
46 |
+
print(k)
|
47 |
if verbose: print(f'\t{len(data.keys())} tracks loaded from cache')
|
48 |
|
49 |
# for each playlist, extract all tracks, remove doubles
|
|
|
139 |
json.dump(data, f)
|
140 |
return data
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
def get_uri_from_link(link):
|
144 |
return link.split("?")[0].split("/")[-1]
|