Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ def complete_login(full_url):
|
|
31 |
code = full_url.split("?code=")[1].split("&")[0]
|
32 |
except IndexError:
|
33 |
return (
|
34 |
-
gr.update(value="β OAuth code not found.
|
35 |
gr.update(visible=False),
|
36 |
gr.update(visible=False),
|
37 |
)
|
@@ -48,13 +48,13 @@ def complete_login(full_url):
|
|
48 |
|
49 |
if not devices_dict:
|
50 |
return (
|
51 |
-
gr.update(value="β οΈ No active Spotify devices found. Open Spotify
|
52 |
gr.update(visible=False),
|
53 |
gr.update(visible=False),
|
54 |
)
|
55 |
|
56 |
return (
|
57 |
-
gr.update(value="β
Logged in!
|
58 |
gr.update(visible=True, choices=list(user_playlists.keys())),
|
59 |
gr.update(visible=True, choices=list(devices_dict.keys())),
|
60 |
)
|
@@ -79,9 +79,8 @@ def shuffle_and_play(playlist_name, device_name):
|
|
79 |
with gr.Blocks() as demo:
|
80 |
gr.Markdown("## π΅ RNG Spotify Playlist Shuffler")
|
81 |
|
82 |
-
login_url = get_auth_url()
|
83 |
login_btn = gr.HTML(
|
84 |
-
f'<a href="{
|
85 |
)
|
86 |
|
87 |
status = gr.Markdown()
|
@@ -91,10 +90,8 @@ with gr.Blocks() as demo:
|
|
91 |
shuffle_btn = gr.Button("π Shuffle & Play", visible=False)
|
92 |
result = gr.Markdown()
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
complete_login_btn = gr.Button(visible=False)
|
98 |
|
99 |
complete_login_btn.click(
|
100 |
complete_login,
|
@@ -110,18 +107,21 @@ with gr.Blocks() as demo:
|
|
110 |
outputs=[result]
|
111 |
)
|
112 |
|
113 |
-
#
|
114 |
demo.load(None, None, None, js="""
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
123 |
}
|
124 |
}
|
|
|
125 |
""")
|
126 |
|
127 |
if __name__ == "__main__":
|
|
|
31 |
code = full_url.split("?code=")[1].split("&")[0]
|
32 |
except IndexError:
|
33 |
return (
|
34 |
+
gr.update(value="β OAuth code not found. Please try again."),
|
35 |
gr.update(visible=False),
|
36 |
gr.update(visible=False),
|
37 |
)
|
|
|
48 |
|
49 |
if not devices_dict:
|
50 |
return (
|
51 |
+
gr.update(value="β οΈ No active Spotify devices found. Open Spotify."),
|
52 |
gr.update(visible=False),
|
53 |
gr.update(visible=False),
|
54 |
)
|
55 |
|
56 |
return (
|
57 |
+
gr.update(value="β
Logged in! Choose playlist & device."),
|
58 |
gr.update(visible=True, choices=list(user_playlists.keys())),
|
59 |
gr.update(visible=True, choices=list(devices_dict.keys())),
|
60 |
)
|
|
|
79 |
with gr.Blocks() as demo:
|
80 |
gr.Markdown("## π΅ RNG Spotify Playlist Shuffler")
|
81 |
|
|
|
82 |
login_btn = gr.HTML(
|
83 |
+
f'<a href="{get_auth_url()}"><button style="width:100%;height:40px;font-size:16px;">π Login to Spotify</button></a>'
|
84 |
)
|
85 |
|
86 |
status = gr.Markdown()
|
|
|
90 |
shuffle_btn = gr.Button("π Shuffle & Play", visible=False)
|
91 |
result = gr.Markdown()
|
92 |
|
93 |
+
redirect_url_box = gr.Textbox(visible=False, elem_id="redirect_url_box")
|
94 |
+
complete_login_btn = gr.Button(visible=False, elem_id="complete_login_btn")
|
|
|
|
|
95 |
|
96 |
complete_login_btn.click(
|
97 |
complete_login,
|
|
|
107 |
outputs=[result]
|
108 |
)
|
109 |
|
110 |
+
# Correct automation JavaScript snippet:
|
111 |
demo.load(None, None, None, js="""
|
112 |
+
() => {
|
113 |
+
const params = new URLSearchParams(window.location.search);
|
114 |
+
const code = params.get('code');
|
115 |
+
if (code) {
|
116 |
+
const box = document.querySelector("#redirect_url_box textarea");
|
117 |
+
const btn = document.querySelector("#complete_login_btn button");
|
118 |
+
if (box && btn) {
|
119 |
+
box.value = window.location.href;
|
120 |
+
box.dispatchEvent(new Event('input', { bubbles: true }));
|
121 |
+
btn.click();
|
122 |
}
|
123 |
}
|
124 |
+
}
|
125 |
""")
|
126 |
|
127 |
if __name__ == "__main__":
|