From 2fa06036948769cd270b8085ab8dc786b1636560 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 25 May 2020 17:00:22 +0200 Subject: [PATCH] Add likeStatus for uploaded songs --- tests/test.cfg.example | 4 +++- tests/test.py | 16 ++++------------ ytmusicapi/parsers.py | 9 +++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/test.cfg.example b/tests/test.cfg.example index 3f7fcce..e143df0 100644 --- a/tests/test.cfg.example +++ b/tests/test.cfg.example @@ -8,4 +8,6 @@ headers_raw = raw_headers_pasted_from_browser own = owned_playlist_id [uploads] -file = song_in_tests_directory.mp3 \ No newline at end of file +file = song_in_tests_directory.mp3 +private_album_id = sample_id_of_private_album +private_artist_id = sample_id_of_private_artist \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index 90000da..94f8207 100644 --- a/tests/test.py +++ b/tests/test.py @@ -183,20 +183,12 @@ class TestYTMusic(unittest.TestCase): self.assertEqual(response, 'STATUS_SUCCEEDED') def test_get_library_upload_album(self): - songs = youtube_auth.get_library_upload_songs() - for song in songs: - if song['album']: - album = youtube_auth.get_library_upload_album(song['album']['id']) - self.assertGreater(len(album['tracks']), 0) - break + album = youtube_auth.get_library_upload_album(config['uploads']['private_album_id']) + self.assertGreater(len(album['tracks']), 0) def test_get_library_upload_artist(self): - songs = youtube_auth.get_library_upload_songs() - for song in songs: - if song['artist']: - tracks = youtube_auth.get_library_upload_artist(song['artist'][0]['id']) - self.assertGreater(len(tracks), 0) - break + tracks = youtube_auth.get_library_upload_artist(config['uploads']['private_artist_id']) + self.assertGreater(len(tracks), 0) if __name__ == '__main__': diff --git a/ytmusicapi/parsers.py b/ytmusicapi/parsers.py index 403c8d5..32fa791 100644 --- a/ytmusicapi/parsers.py +++ b/ytmusicapi/parsers.py @@ -7,6 +7,7 @@ ITEM_SECTION = ['itemSectionRenderer', 'contents', 0] MUSIC_SHELF = [0, 'musicShelfRenderer'] CONTINUATION = ['continuations', 0, 'nextContinuationData', 'continuation'] MENU_ITEMS = ['menu', 'menuRenderer', 'items'] +MENU_LIKE_STATUS = ['menu', 'menuRenderer', 'topLevelButtons', 0, 'likeButtonRenderer', 'likeStatus'] MENU_SERVICE = ['menuServiceItemRenderer', 'serviceEndpoint'] PLAY_BUTTON = [ 'overlay', 'musicItemThumbnailOverlayRenderer', 'content', 'musicPlayButtonRenderer' @@ -135,8 +136,7 @@ def parse_playlist_items(results): like = None if 'menu' in data: - like = data['menu']['menuRenderer']['topLevelButtons'][0]['likeButtonRenderer'][ - 'likeStatus'] + like = nav(data, MENU_LIKE_STATUS) song = { 'videoId': videoId, @@ -172,13 +172,14 @@ def parse_uploaded_items(results): + MENU_SERVICE)['queueAddEndpoint']['queueTarget']['videoId'] title = get_item_text(data, 0) - + like = nav(data, MENU_LIKE_STATUS) song = { 'entityId': entityId, 'videoId': videoId, 'title': title, 'artist': None, - 'album': None + 'album': None, + 'likeStatus': like } if get_flex_column_item(data, 1): song['artist'] = parse_song_artists(data, 1)