From 69a419f0bda430a0b51221861d521c5a060bc2dc Mon Sep 17 00:00:00 2001 From: sigma67 Date: Thu, 6 Apr 2023 23:00:04 +0200 Subject: [PATCH] oauth: add safeguard exception to upload_song --- tests/test.cfg.example | 3 +++ tests/test.py | 1 + ytmusicapi/mixins/uploads.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/test.cfg.example b/tests/test.cfg.example index d2dd8e9..25cf53e 100644 --- a/tests/test.cfg.example +++ b/tests/test.cfg.example @@ -4,6 +4,9 @@ brand_account_empty = 1123456629123420379537 headers = headers_auth_json_as_string headers_empty = headers_account_with_empty_library_as_json_as_string headers_file = ./headers_auth.json +headers_oauth = ./oauth.json +oauth_code = {"device_code":"","user_code":"","expires_in":1800,"interval":5,"verification_url":"https://www.google.com/device"} +oauth_token = {"access_token":"","expires_in":1000,"refresh_token":"","scope":"https://www.googleapis.com/auth/youtube","token_type":"Bearer"} headers_raw = raw_headers_pasted_from_browser [playlists] diff --git a/tests/test.py b/tests/test.py index 706beed..522d2d6 100644 --- a/tests/test.py +++ b/tests/test.py @@ -466,6 +466,7 @@ class TestYTMusic(unittest.TestCase): def test_upload_song(self): self.assertRaises(Exception, self.yt_auth.upload_song, 'song.wav') + self.assertRaises(Exception, self.yt_oauth.upload_song, config['uploads']['file']) response = self.yt_auth.upload_song(get_resource(config['uploads']['file'])) self.assertEqual(response.status_code, 409) diff --git a/ytmusicapi/mixins/uploads.py b/ytmusicapi/mixins/uploads.py index 7f49d21..e63bb19 100644 --- a/ytmusicapi/mixins/uploads.py +++ b/ytmusicapi/mixins/uploads.py @@ -194,6 +194,8 @@ class UploadsMixin: :return: Status String or full response """ self._check_auth() + if not self.is_browser_auth: + raise Exception("Please provide authentication before using this function") if not os.path.isfile(filepath): raise Exception("The provided file does not exist.")