Skip to content

Commit 4bd525e

Browse files
author
SM_SAYEED
committed
"Falls back to drive_music.csv when running locally (e.g., for local dev)"
1 parent 54a4813 commit 4bd525e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

app.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,16 @@ def extract_drive_id(link):
415415

416416
@app.route('/clips')
417417
def public_clips():
418+
import os
419+
418420
admin = session.get('admin', False)
419421
clips = []
420422

421-
# 1. Read from drive_music.csv
423+
# -- 1. Try to load from CSV (Drive-backed music list)
424+
csv_path = '/data/drive_music.csv' if os.path.exists('/data/drive_music.csv') else 'drive_music.csv'
425+
422426
try:
423-
with open('/data/drive_music.csv', encoding='utf-8') as f:
427+
with open(csv_path, encoding='utf-8') as f:
424428
reader = csv.DictReader(f)
425429
required_headers = {'title', 'description', 'preview_url', 'download_url'}
426430
if reader.fieldnames and required_headers.issubset(set(reader.fieldnames)):
@@ -431,19 +435,21 @@ def public_clips():
431435
download = row.get('download_url', '').strip()
432436
if preview and download:
433437
clips.append((preview, download, title, description))
438+
else:
439+
print("⚠️ CSV is missing required headers:", reader.fieldnames)
434440
except Exception as e:
435-
print("Error reading drive_music.csv:", e)
441+
print("🚫 Error reading CSV:", e)
436442

437-
# 2. Also read from music_clips table
443+
# -- 2. Add any admin-uploaded clips stored in the database
438444
try:
439445
with sqlite3.connect(DB_NAME) as conn:
440446
c = conn.cursor()
441447
c.execute("SELECT filename, title, description FROM music_clips ORDER BY id DESC")
442448
for filename, title, description in c.fetchall():
443449
url = url_for('uploaded_file', filename=filename)
444-
clips.append((url, url, title, description)) # preview and download are the same
450+
clips.append((url, url, title or '', description or ''))
445451
except Exception as e:
446-
print("Error reading music_clips:", e)
452+
print("🚫 Error reading from music_clips DB:", e)
447453

448454
return render_template('clips.html', clips=clips, admin=admin)
449455

0 commit comments

Comments
 (0)