From ffb82d6784b0a5ce1afde6813c3f5b351689370e Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Wed, 22 Jul 2020 13:01:10 +0200 Subject: [PATCH] GPM retrieve script puts genres --- scripts/gpm_retrieve/gpm_retrieve.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/gpm_retrieve/gpm_retrieve.py b/scripts/gpm_retrieve/gpm_retrieve.py index 3ce1838..fba8965 100755 --- a/scripts/gpm_retrieve/gpm_retrieve.py +++ b/scripts/gpm_retrieve/gpm_retrieve.py @@ -14,10 +14,16 @@ def transferLibrary(gpm_api, mudbase_api): songs = gpm_api.get_all_songs() # 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 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 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 []; 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 artistMudbaseIds = [] for idx,artist in enumerate(artists): - print(artistStoreIds[idx]) response = requests.post(mudbase_api + '/artist', data = { 'name': artist, 'storeLinks': [ 'https://play.google.com/music/m/' + id for id in artistStoreIds[idx] ] @@ -47,9 +66,11 @@ def transferLibrary(gpm_api, mudbase_api): return []; for song in songs: artistMudbaseId = artistMudbaseIds[ artists.index(song['artist']) ] + genreMudbaseId = genreMudbaseIds[ genres.index(song['genre']) ] response = requests.post(mudbase_api + '/song', json = { 'title': song['title'], 'artistIds': [ artistMudbaseId ], + 'tagIds' : [ genreMudbaseId ], 'storeLinks': [ 'https://play.google.com/music/m/' + id for id in getSongStoreIds(song) ], }).json() print(f"Created song \"{song['title']}\" with artist ID {artistMudbaseId}, response: {response}")