- 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:
@@ -464,20 +464,7 @@ function yt_scrape_channel_videos(string $input, int $limit): array {
|
||||
}
|
||||
|
||||
function yt_download_thumbnail(string $url, string $slug): string {
|
||||
if ($url === '') return '';
|
||||
$fetch = yt_http_get($url, 12);
|
||||
if ($fetch['body'] === '' || $fetch['error']) return '';
|
||||
if (function_exists('getimagesizefromstring') && !@getimagesizefromstring($fetch['body'])) return '';
|
||||
|
||||
$content_type = strtolower((string)$fetch['content_type']);
|
||||
$ext = 'jpg';
|
||||
if (str_contains($content_type, 'png')) $ext = 'png';
|
||||
elseif (str_contains($content_type, 'webp')) $ext = 'webp';
|
||||
|
||||
$thumb_dir = MEDIA_DIR . 'thumbs/';
|
||||
if (!is_dir($thumb_dir)) mkdir($thumb_dir, 0755, true);
|
||||
$fname = $slug . '_yt_' . time() . '.' . $ext;
|
||||
return file_put_contents($thumb_dir . $fname, $fetch['body']) !== false ? 'thumbs/' . $fname : '';
|
||||
return media_download_thumbnail($url, $slug, 'yt');
|
||||
}
|
||||
|
||||
function yt_import_videos(PDO $db, array $videos, array $selected_ids, bool $published): array {
|
||||
|
||||
Reference in New Issue
Block a user