@@ -418,29 +418,36 @@ def public_clips():
418418 admin = session .get ('admin' , False )
419419 clips = []
420420
421+ # 1. Read from drive_music.csv
421422 try :
422423 with open ('/data/drive_music.csv' , encoding = 'utf-8' ) as f :
423424 reader = csv .DictReader (f )
424-
425- # ✅ Safety check: ensure CSV has required headers
426425 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-
430- for row in reader :
431- title = row .get ('title' , '' ).strip ()
432- description = row .get ('description' , '' ).strip ()
433- preview = row .get ('preview_url' , '' ).strip ()
434- download = row .get ('download_url' , '' ).strip ()
435- if preview and download :
436- clips .append ((preview , download , title , description ))
437-
426+ if reader .fieldnames and required_headers .issubset (set (reader .fieldnames )):
427+ for row in reader :
428+ title = row .get ('title' , '' ).strip ()
429+ description = row .get ('description' , '' ).strip ()
430+ preview = row .get ('preview_url' , '' ).strip ()
431+ download = row .get ('download_url' , '' ).strip ()
432+ if preview and download :
433+ clips .append ((preview , download , title , description ))
438434 except Exception as e :
439435 print ("Error reading drive_music.csv:" , e )
440- clips = []
436+
437+ # 2. Also read from music_clips table
438+ try :
439+ with sqlite3 .connect (DB_NAME ) as conn :
440+ c = conn .cursor ()
441+ c .execute ("SELECT filename, title, description FROM music_clips ORDER BY id DESC" )
442+ for filename , title , description in c .fetchall ():
443+ url = url_for ('uploaded_file' , filename = filename )
444+ clips .append ((url , url , title , description )) # preview and download are the same
445+ except Exception as e :
446+ print ("Error reading music_clips:" , e )
441447
442448 return render_template ('clips.html' , clips = clips , admin = admin )
443449
450+
444451@app .route ('/dataset/<table>' )
445452def public_view (table ):
446453 # Anyone can view any table
0 commit comments