|
|
@ -14,10 +14,16 @@ def transferLibrary(gpm_api, mudbase_api): |
|
|
|
songs = gpm_api.get_all_songs() |
|
|
|
songs = gpm_api.get_all_songs() |
|
|
|
|
|
|
|
|
|
|
|
# Determine all unique artists |
|
|
|
# Determine all unique artists |
|
|
|
artists = sorted(set([song['artist'] for song in songs])) |
|
|
|
artists = sorted(set([song['artist'] for song in songs if 'artist' in song])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Determine all genres |
|
|
|
|
|
|
|
genres = sorted(set([song['genre'] for song in songs if 'genre' in song])) |
|
|
|
|
|
|
|
|
|
|
|
# Store the artist index of each song |
|
|
|
# Store the artist index of each song |
|
|
|
songArtistIdxs = [ artists.index(song['artist']) for song in songs ] |
|
|
|
songArtistIdxs = [ artists.index(song['artist']) for song in songs ] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Store the genre index of each song |
|
|
|
|
|
|
|
songArtistIdxs = [ genres.index(song['genre']) for song in songs ] |
|
|
|
|
|
|
|
|
|
|
|
# Determine all unique albums per artist |
|
|
|
# Determine all unique albums per artist |
|
|
|
artistAlbums = [ sorted(set([ song['album'] for song in songs if song['artist'] == artist ])) for artist in artists ] |
|
|
|
artistAlbums = [ sorted(set([ song['album'] for song in songs if song['artist'] == artist ])) for artist in artists ] |
|
|
@ -29,10 +35,23 @@ def transferLibrary(gpm_api, mudbase_api): |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
artistStoreIds = [ [ getArtistStoreIds(song) for song in songs if song['artist'] == artist ][0] for artist in artists ] |
|
|
|
artistStoreIds = [ [ getArtistStoreIds(song) for song in songs if song['artist'] == artist ][0] for artist in artists ] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create genres and store their mudbase Ids |
|
|
|
|
|
|
|
genreRootResponse = requests.post(mudbase_api + '/tag', data = { |
|
|
|
|
|
|
|
'name': 'Genre' |
|
|
|
|
|
|
|
}).json() |
|
|
|
|
|
|
|
print(f"Created tag \"Genre\", response: {genreRootResponse}") |
|
|
|
|
|
|
|
genreMudbaseIds = [] |
|
|
|
|
|
|
|
for idx,genre in enumerate(genres): |
|
|
|
|
|
|
|
response = requests.post(mudbase_api + '/tag', data = { |
|
|
|
|
|
|
|
'name': genre, |
|
|
|
|
|
|
|
'parentId': genreRootResponse['id'] |
|
|
|
|
|
|
|
}).json() |
|
|
|
|
|
|
|
print(f"Created tag \"Genre/{genre}\", response: {response}") |
|
|
|
|
|
|
|
genreMudbaseIds.append(response['id']) |
|
|
|
|
|
|
|
|
|
|
|
# Create artists and store their mudbase Ids |
|
|
|
# Create artists and store their mudbase Ids |
|
|
|
artistMudbaseIds = [] |
|
|
|
artistMudbaseIds = [] |
|
|
|
for idx,artist in enumerate(artists): |
|
|
|
for idx,artist in enumerate(artists): |
|
|
|
print(artistStoreIds[idx]) |
|
|
|
|
|
|
|
response = requests.post(mudbase_api + '/artist', data = { |
|
|
|
response = requests.post(mudbase_api + '/artist', data = { |
|
|
|
'name': artist, |
|
|
|
'name': artist, |
|
|
|
'storeLinks': [ 'https://play.google.com/music/m/' + id for id in artistStoreIds[idx] ] |
|
|
|
'storeLinks': [ 'https://play.google.com/music/m/' + id for id in artistStoreIds[idx] ] |
|
|
@ -47,9 +66,11 @@ def transferLibrary(gpm_api, mudbase_api): |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
for song in songs: |
|
|
|
for song in songs: |
|
|
|
artistMudbaseId = artistMudbaseIds[ artists.index(song['artist']) ] |
|
|
|
artistMudbaseId = artistMudbaseIds[ artists.index(song['artist']) ] |
|
|
|
|
|
|
|
genreMudbaseId = genreMudbaseIds[ genres.index(song['genre']) ] |
|
|
|
response = requests.post(mudbase_api + '/song', json = { |
|
|
|
response = requests.post(mudbase_api + '/song', json = { |
|
|
|
'title': song['title'], |
|
|
|
'title': song['title'], |
|
|
|
'artistIds': [ artistMudbaseId ], |
|
|
|
'artistIds': [ artistMudbaseId ], |
|
|
|
|
|
|
|
'tagIds' : [ genreMudbaseId ], |
|
|
|
'storeLinks': [ 'https://play.google.com/music/m/' + id for id in getSongStoreIds(song) ], |
|
|
|
'storeLinks': [ 'https://play.google.com/music/m/' + id for id in getSongStoreIds(song) ], |
|
|
|
}).json() |
|
|
|
}).json() |
|
|
|
print(f"Created song \"{song['title']}\" with artist ID {artistMudbaseId}, response: {response}") |
|
|
|
print(f"Created song \"{song['title']}\" with artist ID {artistMudbaseId}, response: {response}") |
|
|
|