INNER CODE UNIT · Python
download_data
mdeff/fma · creation.py:74
def download_data(dst_dir):
dst_dir = os.path.abspath(dst_dir)
tracks = pd.read_csv('raw_tracks.csv', index_col=0)
_create_subdirs(dst_dir, tracks)
fma = utils.FreeMusicArchive(os.environ.get('FMA_KEY'))
not_found = pickle.load(open('not_found.pickle', 'rb'))
not_found['audio'] = []
# Download missing tracks.
for tid in tqdm(tracks.index):
dst = utils.get_audio_path(dst_dir, tid)
if not os.path.exists(dst):
try:
fma.download_track(tracks.at[tid, 'track_file'], dst)
except: # requests.HTTPError
not_found['audio'].append(tid)