Update app.py
Browse files
app.py
CHANGED
|
@@ -105,14 +105,48 @@ if st.session_state.current_playlist:
|
|
| 105 |
st.markdown(f"[Open on Spotify]({track['spotify_url']})")
|
| 106 |
st.markdown("---")
|
| 107 |
|
| 108 |
-
# ---
|
| 109 |
-
|
| 110 |
-
st.
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# --- Footer ---
|
| 118 |
st.markdown("---")
|
|
|
|
| 105 |
st.markdown(f"[Open on Spotify]({track['spotify_url']})")
|
| 106 |
st.markdown("---")
|
| 107 |
|
| 108 |
+
# --- Format Selector ---
|
| 109 |
+
st.markdown("### ⬇️ Download Your Playlist")
|
| 110 |
+
file_format = st.selectbox("Choose format", ["JSON", "CSV", "TXT"])
|
| 111 |
+
|
| 112 |
+
# --- JSON Format ---
|
| 113 |
+
if file_format == "JSON":
|
| 114 |
+
playlist_json = json.dumps(st.session_state.current_playlist, indent=2)
|
| 115 |
+
st.download_button(
|
| 116 |
+
label="💾 Download JSON",
|
| 117 |
+
data=playlist_json,
|
| 118 |
+
file_name="vibedj_playlist.json",
|
| 119 |
+
mime="application/json"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# --- CSV Format ---
|
| 123 |
+
elif file_format == "CSV":
|
| 124 |
+
import pandas as pd
|
| 125 |
+
df = pd.DataFrame(st.session_state.current_playlist)
|
| 126 |
+
csv_data = df.to_csv(index=False)
|
| 127 |
+
st.download_button(
|
| 128 |
+
label="📄 Download CSV",
|
| 129 |
+
data=csv_data,
|
| 130 |
+
file_name="vibedj_playlist.csv",
|
| 131 |
+
mime="text/csv"
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# --- TXT Format ---
|
| 135 |
+
elif file_format == "TXT":
|
| 136 |
+
txt_data = "\n".join(
|
| 137 |
+
f"{track['title']} - {track['spotify_url']}" for track in st.session_state.current_playlist
|
| 138 |
+
)
|
| 139 |
+
st.download_button(
|
| 140 |
+
label="📃 Download TXT",
|
| 141 |
+
data=txt_data,
|
| 142 |
+
file_name="vibedj_playlist.txt",
|
| 143 |
+
mime="text/plain"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
# --- Optional: Spotify Export (Open All)
|
| 147 |
+
with st.expander("🎧 Open all songs in Spotify"):
|
| 148 |
+
for track in st.session_state.current_playlist:
|
| 149 |
+
st.markdown(f"- [{track['title']}]({track['spotify_url']})")
|
| 150 |
|
| 151 |
# --- Footer ---
|
| 152 |
st.markdown("---")
|