From 063af84a5f06b6553992bba1b2142625e603e005 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 26 Nov 2020 15:03:58 +0100 Subject: [PATCH] get_streaming_data: handle unplayable videos --- tests/test.py | 2 +- ytmusicapi/mixins/browsing.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test.py b/tests/test.py index c0210be..f26c032 100644 --- a/tests/test.py +++ b/tests/test.py @@ -84,7 +84,7 @@ class TestYTMusic(unittest.TestCase): self.assertGreaterEqual(len(song), 16) def test_get_streaming_data(self): - streaming_data = youtube.get_streaming_data("NRUVdGLf2GI") + streaming_data = youtube_auth.get_streaming_data("ZrOKjDZOtkA") self.assertEqual(len(streaming_data), 3) ############### diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index 658ac31..ab03614 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -620,6 +620,9 @@ class BrowsingMixin: text = parse_qs(response.text) if 'player_response' not in text: return text + player_response = json.loads(text['player_response'][0]) - streaming_data = player_response['streamingData'] - return streaming_data + if 'streamingData' not in player_response: + raise Exception('This video is not playable.') + + return player_response['streamingData']