Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 5ffa455

Browse files
authored
Merge pull request #162 from sindrig/fix-web-api-login
Fix web api login for users that have not authenticated.
2 parents 0ceb8b7 + e604a31 commit 5ffa455

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

spoppy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def get_version():
13-
return '2.1.2'
13+
return '2.1.3'
1414

1515

1616
if click:

spoppy/loaders/loader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import threading
33

4+
from appdirs import user_cache_dir
45
from .search import Search
56

67
logger = logging.getLogger(__name__)
@@ -28,10 +29,10 @@ def __getitem__(self, key):
2829
'probably due to your access token being expired. I\'ve attempted to '
2930
'automatically refresh you access, so you can retry this operation. '
3031
'If that didn\'t work, try restarting spoppy, and if that doesn\'t work '
31-
'try removing the file ~/.cache/spoppy/spotipy_token.cache, restart '
32+
'try removing the file %s/spotipy_token.cache, restart '
3233
'spoppy and log in to spotify web API again. For more information on this '
3334
'issue, see https://github.com/sindrig/spoppy/issues/127'
34-
)
35+
) % (user_cache_dir(appname='spoppy'), )
3536

3637

3738
class Loader(Search):

spoppy/menus.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,6 @@ class MainMenu(Menu):
270270

271271
def get_options(self):
272272
res = {
273-
'vp': MenuValue(
274-
'View playlists',
275-
MyPlaylists(self.navigator)
276-
),
277-
'fp': MenuValue(
278-
'Featured playlists',
279-
FeaturedPlaylists(self.navigator)
280-
),
281273
'st': MenuValue(
282274
'Search for tracks',
283275
TrackSearch(self.navigator)
@@ -295,11 +287,20 @@ def get_options(self):
295287
ArtistSearch(self.navigator)
296288
),
297289
}
298-
if not self.navigator.spotipy_client:
290+
if not self.navigator.spotipy_client.is_authenticated():
299291
res['li'] = MenuValue(
300292
'Log in to spotify web api',
301293
LogIntoSpotipy(self.navigator)
302294
)
295+
else:
296+
res['vp'] = MenuValue(
297+
'View playlists',
298+
MyPlaylists(self.navigator)
299+
)
300+
res['fp'] = MenuValue(
301+
'Featured playlists',
302+
FeaturedPlaylists(self.navigator)
303+
)
303304
return res
304305

305306

@@ -1089,7 +1090,7 @@ def get_ui(self):
10891090
else:
10901091
res = [
10911092
(
1092-
'Opening an authorization page in your browser, please'
1093+
'Opening an authorization page in your browser, please '
10931094
'follow the instructions there to finalize the '
10941095
'authorization process'
10951096
)

spoppy/navigation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def __init__(self, username, password):
4040
logger.debug('Leifur initialized')
4141

4242
def refresh_spotipy_client(self):
43-
self.spotipy_client = self.lifecycle.refresh_and_get_spotipy_client()
43+
self.spotipy_client = SpotipyWrapper(
44+
self,
45+
self.lifecycle.refresh_and_get_spotipy_client()
46+
)
4447

4548
def refresh_spotipy_client_and_token(self):
4649
self.lifecycle.check_spotipy_logged_in()

spoppy/radio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
import threading
44

5+
from appdirs import user_cache_dir
56
from spotify.track import Track
67

78
from .loaders.search import Search
@@ -31,10 +32,10 @@ def __getitem__(self, key):
3132
'probably due to your access token being expired. I\'ve attempted to '
3233
'automatically refresh you access, so you can retry this operation. '
3334
'If that didn\'t work, try restarting spoppy, and if that doesn\'t work '
34-
'try removing the file ~/.cache/spoppy/spotipy_token.cache, restart '
35+
'try removing the file %s/spotipy_token.cache, restart '
3536
'spoppy and log in to spotify web API again. For more information on this '
3637
'issue, see https://github.com/sindrig/spoppy/issues/127'
37-
)
38+
) % (user_cache_dir(appname='spoppy'), )
3839

3940

4041
class Recommendations(Search):

spoppy/spotipy_wrapper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ def __init__(self, navigator, client):
88
self.client = client
99
self.navigator = navigator
1010

11+
def is_authenticated(self):
12+
return bool(self.client._auth)
13+
1114
def __getattr__(self, func_name):
1215
def wrapped(*args, **kwargs):
1316
try:

0 commit comments

Comments
 (0)