Skip to content

Commit 151f67d

Browse files
v1.13.1; add hotfix for Spotify random queue playback issue
hotfix for spotify client not playing random queue; cause: when spotify's api has problems, client doesn't see any tracks in playlist unless manually clicked; fix requires killing and autorunning spotify enabled
1 parent 2fd9d6d commit 151f67d

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.13.1
4+
### Added:
5+
- hotfix for spotify client not playing random queue; cause: when spotify's api has problems, client doesn't see any tracks in playlist unless manually clicked; fix requires killing and autorunning spotify enabled
6+
37
## 1.13.0
48
### Added:
59
- import/export playlists feature

spotifyscheduler.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from tkinter.messagebox import askyesno
2626
import random
2727

28-
VER="1.13.0"
28+
VER="1.13.1"
2929
CONFIG_FILE="config.json"
3030
SCHEDULE_FILE="schedule.txt"
3131
DEFAULT_SCHEDULE_FILE='default-schedule.txt'
@@ -1234,6 +1234,7 @@ def pauseandauto():
12341234
control_frame = ttk.Frame(root)
12351235
control_frame.pack(side="top", fill="x", padx=10, pady=5)
12361236
def run_spotify():
1237+
timestamped_print("Trying to run spotify.")
12371238
if os.name == 'nt':
12381239
try:
12391240
if shutil.which('spotify'):
@@ -1977,8 +1978,10 @@ def is_within_schedule():
19771978

19781979
last_playlist=''
19791980
last_randomqueue=None
1981+
randomqueuefix_playlist=None
1982+
randomqueuefix_run=False
19801983
def play_music():
1981-
global last_playlist, last_spotify_run, closest_start_time, last_randomqueue, user_id
1984+
global last_playlist, last_spotify_run, closest_start_time, last_randomqueue, user_id, randomqueuefix_playlist, randomqueuefix_run
19821985
try:
19831986
if target_device:
19841987
PLAYLIST_ID=get_value_for_schedule(value="playlist")
@@ -1987,34 +1990,46 @@ def play_music():
19871990
randomqueue=get_value_for_schedule(value="randomqueue")
19881991
playlist_info=get_playlist_info(PLAYLIST_ID)
19891992
if (randomqueue and "37i9dQ" not in PLAYLIST_ID):
1990-
name=playlist_info['name']
1991-
tracks = []
1992-
limit = 100
1993-
offset = 0
1994-
1995-
while True:
1996-
results = sp.playlist_items(
1997-
PLAYLIST_ID,
1998-
fields="items(track(uri)),total",
1999-
additional_types=['track'],
2000-
limit=limit,
2001-
offset=offset
2002-
)
2003-
tracks.extend([item['track']['uri'] for item in results['items']])
2004-
offset += limit
2005-
if len(results['items']) < limit:
2006-
break
2007-
track_uris = [track for track in tracks if ":local:" not in track] # remove local tracks
2008-
if not track_uris:
2009-
status.set(_("No tracks found in playlist"))
2010-
return
2011-
random.shuffle(track_uris)
2012-
if not user_id:
2013-
user_id = sp.me()['id']
2014-
temp_playlist = sp.user_playlist_create(user=user_id, name=f"{name} ({_("Random queue")})", description=f"🔀 Generated by Spotify Scheduler v{VER} on {datetime.now()}", public=False)
2015-
sp.current_user_unfollow_playlist(temp_playlist['id'])
2016-
sp.playlist_add_items(temp_playlist['id'], track_uris[:100])
2017-
sp.start_playback(device_id=target_device["id"], context_uri=f"spotify:playlist:{temp_playlist['id']}")
1993+
if (last_playlist==PLAYLIST_ID and randomqueuefix_playlist) and (spotify_button_check() and config['AUTO_SPOTIFY'] and config['KILLSWITCH_ON']): # hotfix for spotify client not playing random queue; cause: when spotify's api has problems, client doesn't see any tracks in playlist unless manually clicked; fix requires killing and autorunning spotify enabled; fix doesn't work when different playlist was playing before without any pause - spotify's api reports that music is playing, but actually it's not
1994+
if not randomqueuefix_run: #restart only once
1995+
killswitch("Spotify not playing random queue, restarting client.")
1996+
run_spotify()
1997+
randomqueuefix_run=True
1998+
timestamped_print("Spotify client restarted, waiting 5 seconds...")
1999+
t.sleep(5)
2000+
sp.start_playback(device_id=target_device["id"], context_uri=f"spotify:playlist:{randomqueuefix_playlist}")
2001+
t.sleep(2.5) # give spotify some time to start playback, specially when api is slow
2002+
else:
2003+
name=playlist_info['name']
2004+
tracks = []
2005+
limit = 100
2006+
offset = 0
2007+
2008+
while True:
2009+
results = sp.playlist_items(
2010+
PLAYLIST_ID,
2011+
fields="items(track(uri)),total",
2012+
additional_types=['track'],
2013+
limit=limit,
2014+
offset=offset
2015+
)
2016+
tracks.extend([item['track']['uri'] for item in results['items']])
2017+
offset += limit
2018+
if len(results['items']) < limit:
2019+
break
2020+
track_uris = [track for track in tracks if ":local:" not in track] # remove local tracks
2021+
if not track_uris:
2022+
status.set(_("No tracks found in playlist"))
2023+
return
2024+
random.shuffle(track_uris)
2025+
if not user_id:
2026+
user_id = sp.me()['id']
2027+
temp_playlist = sp.user_playlist_create(user=user_id, name=f"{name} ({_("Random queue")})", description=f"🔀 Generated by Spotify Scheduler v{VER} on {datetime.now()}", public=False)
2028+
sp.current_user_unfollow_playlist(temp_playlist['id'])
2029+
sp.playlist_add_items(temp_playlist['id'], track_uris[:100])
2030+
randomqueuefix_playlist=temp_playlist['id']
2031+
sp.start_playback(device_id=target_device["id"], context_uri=f"spotify:playlist:{temp_playlist['id']}")
2032+
20182033
else:
20192034
sp.start_playback(device_id=target_device["id"], context_uri=f"spotify:playlist:{PLAYLIST_ID}")
20202035

@@ -2029,7 +2044,6 @@ def play_music():
20292044
else:
20302045
status.set(_( "no_active_device"))
20312046
if spotify_button_check() and config['AUTO_SPOTIFY'] and not last_spotify_run:
2032-
timestamped_print("Trying to run spotify.")
20332047
run_spotify()
20342048
last_spotify_run = True
20352049
return
@@ -2075,7 +2089,7 @@ def pause_music(retries=3, delay=2):
20752089
killswitch("Pausing music - Failed to pause music.")
20762090

20772091
def spotify_main():
2078-
global last_playlist, target_device
2092+
global last_playlist, target_device, randomqueuefix_playlist, randomqueuefix_run
20792093
if not is_paused:
20802094
if not sp or not spstatus:
20812095
initialize_sp()
@@ -2102,6 +2116,8 @@ def spotify_main():
21022116
status.set(_("Playlist not set"))
21032117
else:
21042118
status.set(_("Music is currently playing."))
2119+
randomqueuefix_playlist=None
2120+
randomqueuefix_run=False
21052121
try:
21062122
if config['SKIP_EXPLICIT'] and current_playback and current_playback["item"].get("explicit"):
21072123
sp.next_track(device_id=target_device["id"])

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ StringFileInfo(
3636
StringStruct(u'LegalCopyright', u'MIT License - (c) 2025 Szymon Andrzejewski'),
3737
StringStruct(u'OriginalFilename', u'spotify-scheduler.exe'),
3838
StringStruct(u'ProductName', u'Spotify Scheduler'),
39-
StringStruct(u'ProductVersion', u'1.13.0')])
39+
StringStruct(u'ProductVersion', u'1.13.1')])
4040
]),
4141
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
4242
]

0 commit comments

Comments
 (0)