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):
|
def test_get_lyrics(self):
|
||||||
playlist = youtube.get_watch_playlist("ZrOKjDZOtkA")
|
playlist = youtube.get_watch_playlist("ZrOKjDZOtkA")
|
||||||
lyrics_song = youtube.get_lyrics(playlist["lyrics"])
|
lyrics_song = youtube.get_lyrics(playlist["lyrics"])
|
||||||
self.assertTrue(lyrics_song["lyricsFound"])
|
|
||||||
self.assertIsNotNone(lyrics_song["lyrics"])
|
self.assertIsNotNone(lyrics_song["lyrics"])
|
||||||
self.assertIsNotNone(lyrics_song["source"])
|
self.assertIsNotNone(lyrics_song["source"])
|
||||||
|
|
||||||
browseId = youtube.get_watch_playlist("9TnpB8WgW4s")
|
playlist = youtube.get_watch_playlist("9TnpB8WgW4s")
|
||||||
self.assertIsNone(browseId)
|
self.assertIsNone(playlist["lyrics"])
|
||||||
|
self.assertRaises(Exception, youtube.get_lyrics, playlist["lyrics"])
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# WATCH
|
# WATCH
|
||||||
|
|
|
||||||
|
|
@ -669,16 +669,17 @@ class BrowsingMixin:
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
{
|
{
|
||||||
"lyricsFound": True,
|
|
||||||
"lyrics": "Today is gonna be the day\\nThat they're gonna throw it back to you\\n",
|
"lyrics": "Today is gonna be the day\\nThat they're gonna throw it back to you\\n",
|
||||||
"source": "Source: LyricFind"
|
"source": "Source: LyricFind"
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
lyrics = {}
|
lyrics = {}
|
||||||
|
if not browseId:
|
||||||
|
raise Exception("Invalid browseId provided. This song might not have lyrics.")
|
||||||
|
|
||||||
response = self._send_request('browse', {'browseId': browseId})
|
response = self._send_request('browse', {'browseId': browseId})
|
||||||
if 'sectionListRenderer' in response['contents'].keys():
|
if 'sectionListRenderer' in response['contents'].keys():
|
||||||
lyrics['lyricsFound'] = True
|
|
||||||
lyrics['lyrics'] = response['contents']['sectionListRenderer']['contents'][0][
|
lyrics['lyrics'] = response['contents']['sectionListRenderer']['contents'][0][
|
||||||
'musicDescriptionShelfRenderer']['description']['runs'][0]['text']
|
'musicDescriptionShelfRenderer']['description']['runs'][0]['text']
|
||||||
lyrics['source'] = response['contents']['sectionListRenderer']['contents'][0][
|
lyrics['source'] = response['contents']['sectionListRenderer']['contents'][0][
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue