@extends('website.layouts.base') @section('title', __('video_player')) @section('base.content') @php if (isset($demoVideo) && isDemoMode()) { // Now assign them if needed $server = new \stdClass(); $server->file_source = 'json'; $server->file_url = $demoVideo['url']; } elseif (isDemoMode()) { $server = new \stdClass(); $server->file_source = 'json'; $server->file_url = $video->url; } if (isset($server)) { if ($server->file_source == 'local') { $path = preg_replace('#^public/#i', '', ltrim($server->file_url, '/')); $server->file_url = preg_replace('#/public(?=/|$)#', '', url($path)); // Build folder name: slugified label + ID $folderName = $server->id; $qualities = ['sd', 'hd', 'fullhd']; $fileUrls = []; foreach ($qualities as $quality) { $fileRelativePath = "uploads/videos/{$folderName}/{$quality}/video.mp4"; // Assuming mp4 $fileUrls[$quality] = preg_replace('#/public(?=/|$)#', '', url($fileRelativePath)); } // Now assign them if needed $server->sd_url = $fileUrls['sd']; $server->hd_url = $fileUrls['hd']; $server->full_hd_url = $fileUrls['fullhd']; // $folder_path = public_path('') // echo $server->id; } elseif ($server->file_source == 'gdrive') { $googleApiKey = get_config('google_api_key'); // or set your key directly preg_match('/\/d\/(.+?)\//', $server->file_url, $matches); if (!empty($matches[1])) { $fileId = $matches[1]; $server->file_url = "https://www.googleapis.com/drive/v3/files/{$fileId}?alt=media&key={$googleApiKey}&v=.mp4"; } else { // fallback if URL pattern is different $server->file_url = null; } } elseif ($server->file_source == 'youtube') { // Normalize youtu.be links to youtube.com/watch?v= so the player recognizes them if (preg_match('/(?:youtube\.com\/.*[?&]v=|youtu\.be\/)([^&\s?#]+)/', $server->file_url, $ytMatches)) { $server->file_url = 'https://www.youtube.com/watch?v=' . $ytMatches[1]; } } } if ($video_type == 'episode' && !isDemoMode()) { $video->video_url = $video->video_url ?? $video->file_url ?? ''; $episodeSourceType = $video->source_type ?? $video->file_source ?? ''; if ($episodeSourceType == 'youtube') { if (preg_match('/(?:youtube\.com\/.*[?&]v=|youtu\.be\/)([^&\s?#]+)/', $video->video_url, $ytMatches)) { $video->video_url = 'https://www.youtube.com/watch?v=' . $ytMatches[1]; } } elseif ($episodeSourceType == 'gdrive') { $googleApiKey = get_config('google_api_key'); if ($googleApiKey && preg_match('/\/d\/([^\/?#]+)/', $video->video_url, $matches)) { $fileId = $matches[1]; $video->video_url = "https://www.googleapis.com/drive/v3/files/{$fileId}?alt=media&key={$googleApiKey}&v=.mp4"; } } elseif ($episodeSourceType == 'video' || in_array($episodeSourceType, ['mp4', 'mkv', 'webm', 'm3u8', 'embed', 's3', 'wasabi', 'do'], true)) { if (!empty($video->video_url) && !preg_match('#^https?://#i', $video->video_url)) { $path = preg_replace('#^public/#i', '', ltrim($video->video_url, '/')); $video->video_url = preg_replace('#/public(?=/|$)#', '', url($path)); } } } elseif (isDemoMode()) { // Demo mode: use demo url and placeholders $video->video_url = $video->url ?? ''; $video->poster = '{"original_image":"https:\/\/placehold.co\/500x750"}'; $video->description = 'Demo video description'; $video->title = 'Demo Video Title'; } // For movie, video_url is set from repository (first video file's file_url) — do not overwrite $subtitleSourceAttr = ''; if (isset($video->subtitles) && $video->subtitles->isNotEmpty()) { $parts = []; foreach ($video->subtitles as $s) { $url = preg_match('#^https?://#i', $s->file_path) ? $s->file_path : url($s->file_path); $parts[] = "{source:'" . addslashes($url) . "', label:'" . addslashes($s->label) . "'}"; } $subtitleSourceAttr = '[' . implode(',', $parts) . ']'; } @endphp
@endsection