Spaces:
Sleeping

Sumayyea commited on
Commit
ee4e2f2
·
verified ·
1 Parent(s): ccbb8da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -8
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
- # --- Download Playlist ---
109
- playlist_json = json.dumps(st.session_state.current_playlist, indent=2)
110
- st.download_button(
111
- label="💾 Download Playlist as JSON",
112
- data=playlist_json,
113
- file_name="vibedj_playlist.json",
114
- mime="application/json"
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("---")