- 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:
+17
-1
@@ -43,6 +43,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.';
|
||||
@@ -51,6 +52,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
// Handle thumbnail replacement
|
||||
$thumbnail = $video['thumbnail'];
|
||||
$uploaded_thumbnail = false;
|
||||
if (!empty($_FILES['thumbnail']['tmp_name'])) {
|
||||
$ext = strtolower(pathinfo($_FILES['thumbnail']['name'], PATHINFO_EXTENSION));
|
||||
$allowed = ['jpg','jpeg','png','webp','gif'];
|
||||
@@ -62,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$fname = $slug . '_thumb_' . time() . '.' . $ext;
|
||||
if (move_uploaded_file($_FILES['thumbnail']['tmp_name'], $thumb_dir . $fname)) {
|
||||
$thumbnail = 'thumbs/' . $fname;
|
||||
$uploaded_thumbnail = true;
|
||||
}
|
||||
} else {
|
||||
$error = 'Thumbnail must be JPG, PNG, WebP, or GIF.';
|
||||
@@ -178,6 +181,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (file_exists($moved)) unlink($moved);
|
||||
}
|
||||
} else {
|
||||
if ($auto_thumb && !$uploaded_thumbnail) {
|
||||
$auto_thumbnail = media_auto_thumbnail_for_video($id, $slug);
|
||||
if ($auto_thumbnail !== '') {
|
||||
if ($thumbnail && file_exists(MEDIA_DIR . $thumbnail)) unlink(MEDIA_DIR . $thumbnail);
|
||||
$thumbnail = $auto_thumbnail;
|
||||
$db->prepare("UPDATE videos SET thumbnail=?, updated_at=datetime('now') WHERE id=?")->execute([$thumbnail, $id]);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: edit.php?id=' . $id . '&saved=1');
|
||||
exit;
|
||||
}
|
||||
@@ -329,7 +341,11 @@ render_head('Edit Video — Admin', '
|
||||
<?php endif; ?>
|
||||
<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">Upload new image to replace current thumbnail.</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' && !$video['thumbnail']) ? 'checked' : '' ?>>
|
||||
<span style="font-size:.78rem;color:var(--text-2);">Auto-grab/refresh thumbnail from source on save</span>
|
||||
</label>
|
||||
<span class="hint">Upload a new image to override auto-grab. Auto-grab supports YouTube, Vimeo, Dailymotion and other oEmbed providers; local uploads use ffmpeg when available.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user