From eec1ff1d2962d39e784b6d27b87c6cbcb3e40298 Mon Sep 17 00:00:00 2001 From: alexmercerind Date: Fri, 4 Dec 2020 21:20:22 +0530 Subject: [PATCH] Added lyricsFound key to get_lyrics result & updated tests --- tests/test.py | 2 ++ ytmusicapi/mixins/browsing.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/tests/test.py b/tests/test.py index a5689a7..78113ad 100644 --- a/tests/test.py +++ b/tests/test.py @@ -94,11 +94,13 @@ class TestYTMusic(unittest.TestCase): def test_get_lyrics(self): lyrics_song = youtube.get_lyrics("ZrOKjDZOtkA") + self.assertTrue(lyrics_song["lyricsFound"]) self.assertIsNotNone(lyrics_song["browseId"]) self.assertIsNotNone(lyrics_song["lyrics"]) self.assertIsNotNone(lyrics_song["source"]) no_lyrics_song = youtube.get_lyrics("9TnpB8WgW4s") + self.assertFalse(lyrics_song["lyricsFound"]) self.assertIsNotNone(no_lyrics_song["browseId"]) self.assertIsNotNone(no_lyrics_song["lyrics"]) self.assertIsNotNone(no_lyrics_song["source"]) diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index ecc36ae..4db838d 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -649,6 +649,7 @@ class BrowsingMixin: { "videoId": "ZrOKjDZOtkA", "browseId": "MPLYt_9nqEki4ZDpp-3", + "lyricsFound": true, "lyrics": "Today is gonna be the day\nThat they're gonna throw it back to you\nBy now you should've somehow\nRealized what you gotta do\nI don't believe that anybody\nFeels the way I do, about you now\n\nBackbeat, the word was on the street\nThat the fire in your heart is out\nI'm sure you've heard it all before\nBut you never really had a doubt\nI don't believe that anybody\nFeels the way I do about you now\n\nAnd all the roads we have to walk are winding\nAnd all the lights that lead us there are blinding\nThere are many things that I\nWould like to say to you but I don't know how\n\nBecause maybe, you're gonna be the one that saves me\nAnd after all, you're my wonderwall\n\nToday was gonna be the day\nBut they'll never throw it back to you\nBy now you should've somehow\nRealized what you're not to do\nI don't believe that anybody\nFeels the way I do, about you now\n\nAnd all the roads that lead you there are winding\nAnd all the lights that light the way are blinding\nThere are many things that I\nWould like to say to you but I don't know how\n\nI said maybe, you're gonna be the one that saves me\nAnd after all, you're my wonderwall\n\nI said maybe, you're gonna be the one that saves me\nAnd after all, you're my wonderwall\n\nI said maybe, you're gonna be the one that saves me\nyou're gonna be the one that saves me\nyou're gonna be the one that saves me" "source": "Source: LyricFind" } @@ -657,6 +658,7 @@ class BrowsingMixin: body = { 'videoId': videoId, 'browseId': None, + 'lyricsFound': None, 'lyrics': None, 'source': None, } @@ -664,12 +666,15 @@ class BrowsingMixin: for tab in browseIdResponse['contents']['singleColumnMusicWatchNextResultsRenderer']['tabbedRenderer']['watchNextTabbedResultsRenderer']['tabs']: if tab['tabRenderer']['title'] == 'Lyrics': body['browseId'] = tab['tabRenderer']['endpoint']['browseEndpoint']['browseId'] + break if body['browseId'] != None: response = self._send_request('browse', body) if 'sectionListRenderer' in response['contents'].keys(): + body['lyricsFound'] = True body['lyrics'] = response['contents']['sectionListRenderer']['contents'][0]['musicDescriptionShelfRenderer']['description']['runs'][0]['text'] body['source'] = response['contents']['sectionListRenderer']['contents'][0]['musicDescriptionShelfRenderer']['footer']['runs'][0]['text'] else: + body['lyricsFound'] = False body['lyrics'] = response['contents']['messageRenderer']['subtext']['messageSubtextRenderer']['text']['runs'][0]['text'] body['source'] = response['contents']['messageRenderer']['text']['runs'][0]['text'] body.pop('context', None)