Skip to content

Commit bd02420

Browse files
author
SM_SAYEED
committed
"Fix Drive preview and download display in clips.html"
1 parent 93a0464 commit bd02420

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

app.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,15 @@ def public_clips():
440440

441441
elif action == 'drive_link':
442442
link = request.form.get('link', '').strip()
443-
media_type = request.form.get('media_type', 'audio')
444443
try:
445444
file_id = extract_drive_id(link)
446-
# Manually add extension to help with player detection
447-
#ext = '.mp4' if media_type == 'video' else '.mp3'
448-
db_filename = f"https://drive.google.com/file/d/{file_id}/preview"
449-
445+
# Save as preview|download (separated by ||)
446+
preview_url = f"https://drive.google.com/file/d/{file_id}/preview"
447+
download_url = f"https://drive.google.com/uc?export=download&id={file_id}"
448+
db_filename = f"{preview_url}||{download_url}"
450449
except Exception as e:
451450
message = f"Invalid Google Drive link. ({e})"
452451

453-
# Insert into DB
454452
if db_filename:
455453
try:
456454
with sqlite3.connect(DB_NAME) as conn:

templates/clips.html

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ <h3>Upload a Music/Video File</h3>
7575
</div>
7676

7777
<div class="upload-form" style="margin-bottom:2em;">
78-
7978
<h3>Add a Clip from Google Drive</h3>
8079
<form action="{{ url_for('public_clips') }}" method="post">
8180
<input type="hidden" name="action" value="drive_link">
@@ -91,7 +90,6 @@ <h3>Add a Clip from Google Drive</h3>
9190
</p>
9291
<p><button type="submit">Add Drive Content</button></p>
9392
</form>
94-
9593
</div>
9694

9795
{% if message %}
@@ -102,38 +100,39 @@ <h3>Add a Clip from Google Drive</h3>
102100
{% if clips and clips|length > 0 %}
103101
{% for id, filename, title, description in clips %}
104102
{% set is_drive = 'drive.google.com' in filename %}
105-
{% set is_video = filename.endswith('.mp4') or filename.endswith('.webm') or filename.endswith('.mov') %}
106-
{% set is_audio = filename.endswith('.mp3') or filename.endswith('.wav') or filename.endswith('.m4a') or filename.endswith('.ogg') %}
103+
{% set is_split = '||' in filename %}
104+
{% if is_split %}
105+
{% set preview_url = filename.split('||')[0] %}
106+
{% set download_url = filename.split('||')[1] %}
107+
{% else %}
108+
{% set preview_url = url_for('uploaded_file', filename=filename) %}
109+
{% set download_url = url_for('uploaded_file', filename=filename) %}
110+
{% endif %}
111+
107112
<div class="section">
108113
<b>{{ title }}</b><br>
109114
<small>{{ description }}</small><br>
110-
115+
111116
{% if is_drive %}
112-
<iframe src="{{ filename }}" width="380" height="240" allow="autoplay" allowfullscreen style="margin-top:0.7em;"></iframe>
113-
<source src="{{ filename }}">
114-
Your browser does not support the video tag.
115-
</video>
116-
{% elif is_drive %}
117-
<audio controls style="margin-top:0.7em; width: 260px;">
118-
<source src="{{ filename }}">
119-
Your browser does not support the audio element.
120-
</audio>
121-
{% elif is_video %}
122-
<video controls width="380" style="margin-top:0.7em;">
123-
<source src="{{ url_for('uploaded_file', filename=filename) }}">
124-
Your browser does not support the video tag.
125-
</video>
126-
{% elif is_audio %}
127-
<audio controls style="margin-top:0.7em; width: 260px;">
128-
<source src="{{ url_for('uploaded_file', filename=filename) }}">
129-
Your browser does not support the audio element.
130-
</audio>
117+
<iframe src="{{ preview_url }}" width="380" height="240" allow="autoplay" allowfullscreen style="margin-top:0.7em;"></iframe>
131118
{% else %}
132-
<span title="Unrecognized file type">{{ filename }}</span>
119+
{% set is_video = filename.endswith('.mp4') or filename.endswith('.webm') or filename.endswith('.mov') %}
120+
{% set is_audio = filename.endswith('.mp3') or filename.endswith('.wav') or filename.endswith('.m4a') or filename.endswith('.ogg') %}
121+
{% if is_video %}
122+
<video controls width="380" style="margin-top:0.7em;">
123+
<source src="{{ preview_url }}">
124+
Your browser does not support the video tag.
125+
</video>
126+
{% elif is_audio %}
127+
<audio controls style="margin-top:0.7em; width: 260px;">
128+
<source src="{{ preview_url }}">
129+
Your browser does not support the audio element.
130+
</audio>
131+
{% endif %}
133132
{% endif %}
134133

135134
<br>
136-
<a href="{{ url_for('uploaded_file', filename=filename) if not is_drive else filename }}" download>Download</a>
135+
<a href="{{ download_url }}" target="_blank">Download</a>
137136
{% if admin %}
138137
<form action="{{ url_for('delete_clip', clip_id=id) }}" method="post" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this clip?');">
139138
<button type="submit" class="delete-btn">Delete</button>

0 commit comments

Comments
 (0)