Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def try_login(current_url, filter_keyword):
|
|
32 |
|
33 |
if "?code=" not in current_url:
|
34 |
return (
|
35 |
-
|
36 |
gr.update(visible=False),
|
37 |
gr.update(visible=False),
|
38 |
gr.update(visible=False),
|
@@ -57,14 +57,14 @@ def try_login(current_url, filter_keyword):
|
|
57 |
|
58 |
if not device_map:
|
59 |
return (
|
60 |
-
|
61 |
gr.update(visible=False),
|
62 |
gr.update(visible=False),
|
63 |
gr.update(visible=False),
|
64 |
)
|
65 |
|
66 |
return (
|
67 |
-
|
68 |
gr.update(visible=True, choices=list(user_playlists.keys())),
|
69 |
gr.update(visible=True, choices=list(device_map.keys())),
|
70 |
gr.update(visible=True),
|
@@ -89,10 +89,9 @@ def shuffle_and_play(playlist_name, device_name):
|
|
89 |
|
90 |
try:
|
91 |
sp.start_playback(device_id=device_id, uris=uris[:100])
|
92 |
-
# queue remaining
|
93 |
for uri in uris[100:]:
|
94 |
sp.add_to_queue(uri, device_id=device_id)
|
95 |
-
time.sleep(0.1)
|
96 |
return f"βΆοΈ Now playing **{playlist_name}** on **{device_name}**."
|
97 |
except Exception as e:
|
98 |
return f"β Playback failed: {str(e)}"
|
@@ -110,7 +109,7 @@ def now_playing():
|
|
110 |
image = track["album"]["images"][0]["url"]
|
111 |
html = f"""
|
112 |
<img src='{image}' width='300'><br>
|
113 |
-
<b>{name}</b> by {artist}<br
|
114 |
<i>{album}</i>
|
115 |
"""
|
116 |
return html
|
@@ -135,7 +134,7 @@ with gr.Blocks() as demo:
|
|
135 |
fn=try_login,
|
136 |
inputs=[url_state, filter_txt],
|
137 |
outputs=[status, playlist_dd, device_dd, shuffle_btn],
|
138 |
-
js="() => window.location.href"
|
139 |
)
|
140 |
|
141 |
shuffle_btn.click(shuffle_and_play, [playlist_dd, device_dd], [result])
|
|
|
32 |
|
33 |
if "?code=" not in current_url:
|
34 |
return (
|
35 |
+
"π Please login to Spotify.",
|
36 |
gr.update(visible=False),
|
37 |
gr.update(visible=False),
|
38 |
gr.update(visible=False),
|
|
|
57 |
|
58 |
if not device_map:
|
59 |
return (
|
60 |
+
"β οΈ No active Spotify devices found.",
|
61 |
gr.update(visible=False),
|
62 |
gr.update(visible=False),
|
63 |
gr.update(visible=False),
|
64 |
)
|
65 |
|
66 |
return (
|
67 |
+
"β
Logged in!",
|
68 |
gr.update(visible=True, choices=list(user_playlists.keys())),
|
69 |
gr.update(visible=True, choices=list(device_map.keys())),
|
70 |
gr.update(visible=True),
|
|
|
89 |
|
90 |
try:
|
91 |
sp.start_playback(device_id=device_id, uris=uris[:100])
|
|
|
92 |
for uri in uris[100:]:
|
93 |
sp.add_to_queue(uri, device_id=device_id)
|
94 |
+
time.sleep(0.1)
|
95 |
return f"βΆοΈ Now playing **{playlist_name}** on **{device_name}**."
|
96 |
except Exception as e:
|
97 |
return f"β Playback failed: {str(e)}"
|
|
|
109 |
image = track["album"]["images"][0]["url"]
|
110 |
html = f"""
|
111 |
<img src='{image}' width='300'><br>
|
112 |
+
<b>{name}</b> by {artist}<br/>
|
113 |
<i>{album}</i>
|
114 |
"""
|
115 |
return html
|
|
|
134 |
fn=try_login,
|
135 |
inputs=[url_state, filter_txt],
|
136 |
outputs=[status, playlist_dd, device_dd, shuffle_btn],
|
137 |
+
js="() => { return [window.location.href, '']; }"
|
138 |
)
|
139 |
|
140 |
shuffle_btn.click(shuffle_and_play, [playlist_dd, device_dd], [result])
|