Michaël Defferrard, Kirell Benzi, Pierre Vandergheynst, Xavier Bresson, EPFL LTS2.
Free Music Archive web API
All the data in the raw_*.csv
tables was collected from the Free Music Archive public API. With this notebook, you can:
- reconstruct the original data,
- update some fields, e.g. the
track listens
(play count), - augment the data with newer fields wich may have been introduced in their API,
- update the dataset with new songs added to the archive.
Notes:
- You need a key to access the API, which you can request online and write into your
.env
file as a new line readingFMA_KEY=MYPERSONALKEY
. - Requests take some hunderd milliseconds to complete.
In [1]:
import os
import IPython.display as ipd
import utils
In [2]:
fma = utils.FreeMusicArchive(os.environ.get('FMA_KEY'))
In [3]:
for track_id, artist_name, date_created in zip(*fma.get_recent_tracks()):
print(track_id, date_created, artist_name)
2 Get metadata about tracks, albums and artists
Given IDs, we can get information about tracks, albums and artists. See the available fields in the API documentation.
In [4]:
fma.get_track(track_id=2, fields=['track_title', 'track_date_created',
'track_duration', 'track_bit_rate',
'track_listens', 'track_interest', 'track_comments', 'track_favorites',
'artist_id', 'album_id'])
Out[4]:
In [5]:
fma.get_track_genres(track_id=20)
Out[5]:
In [6]:
fma.get_album(album_id=1, fields=['album_title', 'album_tracks',
'album_listens', 'album_comments', 'album_favorites',
'album_date_created', 'album_date_released'])
Out[6]:
In [7]:
fma.get_artist(artist_id=1, fields=['artist_name', 'artist_location',
'artist_comments', 'artist_favorites'])
Out[7]:
In [8]:
track_file = fma.get_track(2, 'track_file')
fma.download_track(track_file, path='track.mp3')
In [9]:
genres = fma.get_all_genres()
print('{} genres'.format(genres.shape[0]))
genres[10:25]
Out[9]:
And look for genres related to Rock.
In [10]:
genres[['Rock' in title for title in genres['genre_title']]]
Out[10]:
In [11]:
genres[genres['genre_parent_id'] == '12']
Out[11]:
Michaël Defferrard, Kirell Benzi, Pierre Vandergheynst, Xavier Bresson, EPFL LTS2.
Free Music Archive web API
All the data in the raw_*.csv
tables was collected from the Free Music Archive public API. With this notebook, you can:
- reconstruct the original data,
- update some fields, e.g. the
track listens
(play count), - augment the data with newer fields wich may have been introduced in their API,
- update the dataset with new songs added to the archive.
Notes:
- You need a key to access the API, which you can request online and write into your
.env
file as a new line readingFMA_KEY=MYPERSONALKEY
. - Requests take some hunderd milliseconds to complete.
In [1]:
import os
import IPython.display as ipd
import utils
In [2]:
fma = utils.FreeMusicArchive(os.environ.get('FMA_KEY'))
In [3]:
for track_id, artist_name, date_created in zip(*fma.get_recent_tracks()):
print(track_id, date_created, artist_name)
2 Get metadata about tracks, albums and artists
Given IDs, we can get information about tracks, albums and artists. See the available fields in the API documentation.
In [4]:
fma.get_track(track_id=2, fields=['track_title', 'track_date_created',
'track_duration', 'track_bit_rate',
'track_listens', 'track_interest', 'track_comments', 'track_favorites',
'artist_id', 'album_id'])
Out[4]:
In [5]:
fma.get_track_genres(track_id=20)
Out[5]:
In [6]:
fma.get_album(album_id=1, fields=['album_title', 'album_tracks',
'album_listens', 'album_comments', 'album_favorites',
'album_date_created', 'album_date_released'])
Out[6]:
In [7]:
fma.get_artist(artist_id=1, fields=['artist_name', 'artist_location',
'artist_comments', 'artist_favorites'])
Out[7]:
In [8]:
track_file = fma.get_track(2, 'track_file')
fma.download_track(track_file, path='track.mp3')
In [9]:
genres = fma.get_all_genres()
print('{} genres'.format(genres.shape[0]))
genres[10:25]
Out[9]:
And look for genres related to Rock.
In [10]:
genres[['Rock' in title for title in genres['genre_title']]]
Out[10]:
In [11]:
genres[genres['genre_parent_id'] == '12']
Out[11]: