Skip to content

Commit b1aef85

Browse files
committed
Minor improvements
1 parent 0fb777c commit b1aef85

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

demo_telebot_lcd_now_playing.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,20 @@ def get_date():
9191

9292
# Spotify now playing
9393
def get_spotify_now_playing(sp):
94-
current_track = sp.current_playback()
95-
if current_track is not None and 'is_playing' in current_track and not current_track['is_playing']:
96-
is_playing = 0
97-
music = '0'
98-
elif current_track is not None and 'item' in current_track:
99-
is_playing = 1
100-
track_name = current_track['item']['name']
101-
artists = ', '.join([artist['name'] for artist in current_track['item']['artists']])
102-
music = f"{track_name}-{artists}"
103-
else:
94+
try:
95+
current_track = sp.current_playback()
96+
if current_track.get('is_playing', False):
97+
is_playing = 1
98+
track_name = current_track['item']['name']
99+
artists = ', '.join([artist['name'] for artist in current_track['item']['artists']])
100+
music = f"{track_name}-{artists}"
101+
else:
102+
is_playing = 0
103+
music = None
104+
except Exception as e:
105+
print(f"Error Spotify API: {e}")
104106
is_playing = 0
105-
music = '0'
107+
music = None
106108

107109
return is_playing, music
108110

@@ -132,8 +134,9 @@ def get_trakt_now_playing():
132134
trakt_playing = f"{show_title} S{season_number}E{episode_number}"
133135
is_playing = 1
134136
except Exception as e:
137+
print(f"Error Trakt API: {e}")
135138
is_playing = 0
136-
trakt_playing = '0'
139+
trakt_playing = None
137140

138141
return is_playing, trakt_playing
139142

0 commit comments

Comments
 (0)