Add exception if browseId None is passed to avoid confusing errors
This commit is contained in:
parent
bfbbcc5859
commit
5ce1f4bd50
2 changed files with 6 additions and 5 deletions
|
|
@ -97,12 +97,12 @@ class TestYTMusic(unittest.TestCase):
|
|||
def test_get_lyrics(self):
|
||||
playlist = youtube.get_watch_playlist("ZrOKjDZOtkA")
|
||||
lyrics_song = youtube.get_lyrics(playlist["lyrics"])
|
||||
self.assertTrue(lyrics_song["lyricsFound"])
|
||||
self.assertIsNotNone(lyrics_song["lyrics"])
|
||||
self.assertIsNotNone(lyrics_song["source"])
|
||||
|
||||
browseId = youtube.get_watch_playlist("9TnpB8WgW4s")
|
||||
self.assertIsNone(browseId)
|
||||
playlist = youtube.get_watch_playlist("9TnpB8WgW4s")
|
||||
self.assertIsNone(playlist["lyrics"])
|
||||
self.assertRaises(Exception, youtube.get_lyrics, playlist["lyrics"])
|
||||
|
||||
###############
|
||||
# WATCH
|
||||
|
|
|
|||
|
|
@ -669,16 +669,17 @@ class BrowsingMixin:
|
|||
Example::
|
||||
|
||||
{
|
||||
"lyricsFound": True,
|
||||
"lyrics": "Today is gonna be the day\\nThat they're gonna throw it back to you\\n",
|
||||
"source": "Source: LyricFind"
|
||||
}
|
||||
|
||||
"""
|
||||
lyrics = {}
|
||||
if not browseId:
|
||||
raise Exception("Invalid browseId provided. This song might not have lyrics.")
|
||||
|
||||
response = self._send_request('browse', {'browseId': browseId})
|
||||
if 'sectionListRenderer' in response['contents'].keys():
|
||||
lyrics['lyricsFound'] = True
|
||||
lyrics['lyrics'] = response['contents']['sectionListRenderer']['contents'][0][
|
||||
'musicDescriptionShelfRenderer']['description']['runs'][0]['text']
|
||||
lyrics['source'] = response['contents']['sectionListRenderer']['contents'][0][
|
||||
|
|
|
|||
Loading…
Reference in a new issue