- Improved the upload/edit flow to auto-grab thumbnails.
What changed: Added shared thumbnail helpers in [includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php):YouTube direct thumbnails Dailymotion direct thumbnails oEmbed thumbnails for Vimeo, Wistia, TikTok, SoundCloud, Spotify, etc. optional first-frame thumbnail generation for local uploads when ffmpeg is installed Added an “Auto-grab thumbnail” checkbox to [admin/add.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/add.php) and [admin/edit.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/edit.php). Reused the new shared downloader in [admin/youtube_import.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/youtube_import.php). Documented the behavior in [README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md).
This commit is contained in:
+15
-3
@@ -13,6 +13,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$duration = (int)($_POST['duration'] ?? 0);
|
||||
$sort_order = (int)($_POST['sort_order'] ?? 0);
|
||||
$published = isset($_POST['published']) ? 1 : 0;
|
||||
$auto_thumb = isset($_POST['auto_thumbnail']);
|
||||
|
||||
if (!$title) {
|
||||
$error = 'Title is required.';
|
||||
@@ -112,8 +113,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($thumbnail && file_exists(MEDIA_DIR . $thumbnail)) unlink(MEDIA_DIR . $thumbnail);
|
||||
$db->prepare("DELETE FROM videos WHERE id=?")->execute([$video_id]);
|
||||
} else {
|
||||
header('Location: edit.php?id=' . $video_id . '&saved=1');
|
||||
exit;
|
||||
if ($thumbnail === '' && $auto_thumb) {
|
||||
$thumbnail = media_auto_thumbnail_for_video($video_id, $slug);
|
||||
if ($thumbnail !== '') {
|
||||
$db->prepare("UPDATE videos SET thumbnail=? WHERE id=?")->execute([$thumbnail, $video_id]);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: edit.php?id=' . $video_id . '&saved=1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +255,11 @@ render_head('Add Video — Admin', '
|
||||
<label class="form-label" for="thumbnail">Thumbnail Image</label>
|
||||
<input class="form-input" type="file" id="thumbnail" name="thumbnail"
|
||||
accept="image/jpeg,image/png,image/webp,image/gif" style="padding:.45rem .6rem;">
|
||||
<span class="hint">JPG, PNG, WebP or GIF. Shown as 16:9 preview.</span>
|
||||
<label style="display:flex;align-items:center;gap:.55rem;margin-top:.55rem;cursor:pointer;">
|
||||
<input type="checkbox" name="auto_thumbnail" value="1" <?= isset($_POST['auto_thumbnail']) || $_SERVER['REQUEST_METHOD'] !== 'POST' ? 'checked' : '' ?>>
|
||||
<span style="font-size:.78rem;color:var(--text-2);">Auto-grab thumbnail from source if no image is uploaded</span>
|
||||
</label>
|
||||
<span class="hint">JPG, PNG, WebP or GIF. Auto-grab supports YouTube, Vimeo, Dailymotion and other oEmbed providers; local uploads use ffmpeg when available.</span>
|
||||
</div>
|
||||
<div class="form-group" style="justify-content:flex-end;padding-bottom:.2rem;">
|
||||
<label style="display:flex;align-items:center;gap:.6rem;cursor:pointer;">
|
||||
|
||||
Reference in New Issue
Block a user