Skip to content

Commit 40fa83c

Browse files
author
SM_SAYEED
committed
"Add safety check to clips CSV route"
1 parent fab7379 commit 40fa83c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,20 @@ def public_clips():
421421
try:
422422
with open('drive_music.csv', encoding='utf-8') as f:
423423
reader = csv.DictReader(f)
424+
425+
# ✅ Safety check: ensure CSV has required headers
426+
required_headers = {'title', 'description', 'preview_url', 'download_url'}
427+
if not reader.fieldnames or not required_headers.issubset(set(reader.fieldnames)):
428+
raise ValueError("Missing or invalid CSV header. Required headers: title, description, preview_url, download_url")
429+
424430
for row in reader:
425431
title = row.get('title', '').strip()
426432
description = row.get('description', '').strip()
427433
preview = row.get('preview_url', '').strip()
428434
download = row.get('download_url', '').strip()
429435
if preview and download:
430436
clips.append((preview, download, title, description))
437+
431438
except Exception as e:
432439
print("Error reading drive_music.csv:", e)
433440
clips = []

0 commit comments

Comments
 (0)