Skip to content

Commit

Permalink
enable Playlists for oauth login flow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jclds139 committed Feb 16, 2024
1 parent d5e1f56 commit 4111f2f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions mopidy_ytmusic/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit 4111f2f

Please sign in to comment.