From 4111f2f01f32e57658123be798bf78b5317e4c5f Mon Sep 17 00:00:00 2001 From: Jesse R Codling Date: Fri, 9 Feb 2024 16:36:30 -0500 Subject: [PATCH] enable Playlists for oauth login flow Several places use the `backend.auth` flag to check if we're logged in or not. Since the API responds simlarly whether using the OAuth login or the old cookie login, this unifies those checks back under the `backend.auth` flag. To simplify setting it the flag, and since `_ytmusicapi_oauth_json` was only used for one function, I replaced it with direct references to the original `config['ytmusic']['oauth_json']`. Finally, checking before reading from `config` avoids crashes when only one or the other of `auth_json` or `oauth_json` is present in the config file --- mopidy_ytmusic/backend.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/mopidy_ytmusic/backend.py b/mopidy_ytmusic/backend.py index cab38c9..a2ed7fc 100644 --- a/mopidy_ytmusic/backend.py +++ b/mopidy_ytmusic/backend.py @@ -36,7 +36,6 @@ def __init__(self, config, audio): self.audio = audio self.uri_schemes = ["ytmusic"] self.auth = False - self.oauth = False self._auto_playlist_refresh_rate = ( config["ytmusic"]["auto_playlist_refresh"] * 60 @@ -58,18 +57,12 @@ def __init__(self, config, audio): self.stream_preference = config["ytmusic"]["stream_preference"] self.verify_track_url = config["ytmusic"]["verify_track_url"] - if config["ytmusic"]["auth_json"]: - self._ytmusicapi_auth_json = config["ytmusic"]["auth_json"] + if "oauth_json" in config["ytmusic"]: + self.api = YTMusic(auth=config["ytmusic"]["oauth_json"]) + self.auth = True + elif "auth_json" in config["ytmusic"]: + self.api = YTMusic(config["ytmusic"]["auth_json"]) self.auth = True - - if config["ytmusic"]["oauth_json"]: - self._ytmusicapi_oauth_json = config["ytmusic"]["oauth_json"] - self.oauth = True - - if self.auth and not self.oauth: - self.api = YTMusic(auth=self._ytmusicapi_auth_json) - elif self.oauth: - self.api = YTMusic(auth=self._ytmusicapi_oauth_json) else: self.api = YTMusic()