A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
Can't suppress info message
aminnausindfe5d818dca3
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.phpindex c9ae6a1d..3ba20cd9 100644--- a/app/Http/Controllers/DirectoryController.php+++ b/app/Http/Controllers/DirectoryController.php@@ -14,6 +14,9 @@ use App\Models\Video;use ErrorException;use Illuminate\Http\Request;use App\Traits\HttpResponses;+use Illuminate\Support\Facades\Bus;+use FFMpeg\FFProbe as FFMpegFFProbe;+use Illuminate\Support\Facades\Storage;class DirectoryController extends Controller{@@ -154,50 +157,23 @@ class DirectoryController extends Controllerpublic function verifyFiles(Request $request){try {- VerifyFiles::dispatch();- dump('success');+ $jobs = [];+ $chunks = [];++ Video::orderBy('id')->chunk(20, function($videos) use (&$chunks) {+ $chunks[] = $videos;+ });++ foreach($chunks as $chunk){+ $jobs[] = new VerifyFiles($chunk);+ break;+ }++ Bus::batch($jobs)->dispatch();+ dump('This job has not web output. Check console for updates.');} catch (\Throwable $th) {dump('Error cannot verify file metadata');dump($th);}}- // public function generateDirectory(Request $request) {- // $dir = $request->dir;- // $mediaRoot = '/media/';- // $publicRoot = '/storage';- // $default = 'tv';- // $path = isset($dir) ? $mediaRoot . $dir : $mediaRoot . $default ;-- // if(!Storage::exists('public/' . $path)){- // $error = 'Invalid Directory: "' . $path . '"';-- // return json_encode(array("success"=>false, "result"=>"", "error"=>$error), JSON_UNESCAPED_SLASHES);- // }--- // $allDirectories = Storage::directories('public' . $path);-- // $folders = array();- // $currentFolder = array("name"=>"", "files"=>array());--- // foreach ($allDirectories as $directory) {- // if (basename($directory) != '.thumbs') {- // $currentFolder['name'] = basename($directory);- // $files = File::allFiles(storage_path('app') . '/' . $directory);-- // foreach($files as $file){- // if ($file->getExtension() == 'mp4' || $file->getExtension() == 'mkv' ) {- // $fileData = array('name'=> $publicRoot . $path . '/' . basename($directory) . '/' . basename($file), 'title'=>basename($file), 'date' => filectime($file), 'formattedDate' => date("Y-m-d g:i A", filectime($file)));- // $rawFile = array('name'=> $publicRoot . $path . '/' . basename($directory) . '/' . basename($file), 'title'=>basename($file), 'date' => filectime($file), 'formattedDate' => date("Y-m-d g:i A", filectime($file)));- // array_push($currentFolder['files'], $fileData);- // }- // }- // }- // array_push($folders, $currentFolder);- // $currentFolder['files'] = array();- // }-- // return json_encode(array("success"=>true, "result"=>$folders, "error"=>""), JSON_UNESCAPED_SLASHES);- // }}\ No newline at end of filediff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.phpindex d9c0ad84..706812de 100644--- a/app/Jobs/VerifyFiles.php+++ b/app/Jobs/VerifyFiles.php@@ -4,21 +4,23 @@ namespace App\Jobs;use App\Models\Record;use App\Models\Video;+use Illuminate\Bus\Batchable;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use FFMpeg\FFProbe as FFMpegFFProbe;+use Illuminate\Support\Facades\Storage;class VerifyFiles implements ShouldQueue{- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;+ use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;/*** Create a new job instance.*/- public function __construct()+ public function __construct(public $videos){//}@@ -28,61 +30,83 @@ class VerifyFiles implements ShouldQueue*/public function handle(): void{- //- Video::orderBy('id')->chunk(100, function ($videos) {- $transactions = array();- foreach ($videos as $video) {- try {- $stored = array();- $changes = array();-- $stored = $video->toArray();-- preg_match('![sS][0-9]+!', $stored['name'], $seasonRaw);- preg_match('![eE][0-9]+!', $stored['name'], $episodeRaw);- preg_match('![0-9]+!', $seasonRaw[0] ?? '', $season);- preg_match('![0-9]+!', $episodeRaw[0] ?? '', $episode);--- if(is_null($video->duration)){- $ffprobe = FFMpegFFProbe::create();- $duration = ceil($ffprobe- ->format($video->path) // extracts file informations- ->get('duration'));- $changes['duration'] = $duration;- }--- if(is_null($video->season) && count($season) == 1) $changes['season'] = (int)$season;- if(is_null($video->episode) && count($episode) == 1) $changes['episode'] = (int)$episode;- if(is_null($video->season) && count($season) == 1) $changes['season'] = (int)$season;-- if(is_null($video->title)){- $newTitle = count($season) == 1 ? 'S' . $season[0] : '';- $newTitle .= count($episode) == 1 ? 'E' . $episode[0] : '';-- if($newTitle != '') $changes['title'] = $newTitle;- }-- is_null($video->view_count) ? $changes['view_count'] = Record::where('video_id', $video->id)->count() : $stored['view_count'] = $video->view_count;--- // $video->update($changes);- if(count($changes) > 0){- array_push($transactions, [...$stored, ...$changes]);- dump([...$stored, ...$changes]);- dump($changes);- }-- } catch (\Throwable $th) {- //throw $th;- dump('Error ' . $th->getMessage());- return;+ if ($this->batch()->cancelled()) {+ // Determine if the batch has been cancelled...+ return;+ }++ if(count($this->videos) == 0){+ dump('Video Data Lost');+ return;+ }+++ try {+ $ffprobe = FFMpegFFProbe::create();+ // $duration = ceil($ffprobe+ // ->format('C:\NAS-6\projects\mediaServer\storage\app\public\media\yakuza\Ishin\Like a Dragon_ Ishin! 2023-12-16 2-47-02 PM.mp4') // extracts file informations+ // ->get('duration'));+ // $changes['duration'] = $duration;+ $change = $ffprobe->format('C:\NAS-6\projects\mediaServer\storage\app\public\media\anime\frieren\S1E01.mp4')->get('duration');+ dump($change);+ } catch (\Throwable $th) {+ dump($th->getMessage());+ }+ return;++ $transactions = array();+ foreach ($this->videos as $video) {+ try {+ $stored = array();+ $changes = array();++ $stored = $video->toArray();++ preg_match('![sS][0-9]+!', $stored['name'], $seasonRaw);+ preg_match('![eE][0-9]+!', $stored['name'], $episodeRaw);+ preg_match('![0-9]+!', $seasonRaw[0] ?? '', $season);+ preg_match('![0-9]+!', $episodeRaw[0] ?? '', $episode);+++ if(is_null($video->duration)){+ // dump(Storage::path('') . 'public\\' . substr($video->path, 8));+ $ffprobe = FFMpegFFProbe::create();+ $duration = ceil($ffprobe+ ->format(Storage::path('') . 'public\\' . substr($video->path, 8)) // extracts file informations+ ->get('duration'));+ $changes['duration'] = $duration;+ break;+ }++ if(is_null($video->season) && count($season) == 1) $changes['season'] = (int)$season;+ if(is_null($video->episode) && count($episode) == 1) $changes['episode'] = (int)$episode;+ if(is_null($video->season) && count($season) == 1) $changes['season'] = (int)$season;++ if(is_null($video->title)){+ $newTitle = count($season) == 1 ? 'S' . $season[0] : '';+ $newTitle .= count($episode) == 1 ? 'E' . $episode[0] : '';++ if($newTitle != '') $changes['title'] = $newTitle;+ }++ is_null($video->view_count) ? $changes['view_count'] = Record::where('video_id', $video->id)->count() : $stored['view_count'] = $video->view_count;++ if(count($changes) > 0){+ array_push($transactions, [...$stored, ...$changes]);+ //dump([...$stored, ...$changes]);+ //dump($changes);}++ } catch (\Throwable $th) {+ //throw $th;+ dump('Error cannot verify file metadata ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates');+ return;}+ }+ if(count($transactions) == 0) return;- Video::upsert($transactions, 'id', ['title','duration','season','episode','view_count']);- });+ Video::upsert($transactions, 'id', ['title','duration','season','episode','view_count']);+ dump('Updated ' . count($transactions) . ' videos from id ' . ($transactions[0]->id ?? 'null') . ' to ' . ($transactions[count($transactions) - 1]->id ?? 'null'));}}diff --git a/config/laravel-ffmpeg.php b/config/laravel-ffmpeg.phpindex 25b8913a..3af9f4f9 100644--- a/config/laravel-ffmpeg.php+++ b/config/laravel-ffmpeg.php@@ -13,7 +13,7 @@ return ['timeout' => 3600,- 'log_channel' => env('LOG_CHANNEL', 'stack'), // set to false to completely disable logging+ 'log_channel' => env('LOG_CHANNEL', 'null'), // set to false to completely disable logging'temporary_files_root' => env('FFMPEG_TEMPORARY_FILES_ROOT', sys_get_temp_dir()),diff --git a/database/migrations/2024_07_29_183244_create_job_batches_table.php b/database/migrations/2024_07_29_183244_create_job_batches_table.phpnew file mode 100644index 00000000..50e38c20--- /dev/null+++ b/database/migrations/2024_07_29_183244_create_job_batches_table.php@@ -0,0 +1,35 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::create('job_batches', function (Blueprint $table) {+ $table->string('id')->primary();+ $table->string('name');+ $table->integer('total_jobs');+ $table->integer('pending_jobs');+ $table->integer('failed_jobs');+ $table->longText('failed_job_ids');+ $table->mediumText('options')->nullable();+ $table->integer('cancelled_at')->nullable();+ $table->integer('created_at');+ $table->integer('finished_at')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('job_batches');+ }+};diff --git a/database/migrations/2024_07_29_185123_create_jobs_table.php b/database/migrations/2024_07_29_185123_create_jobs_table.phpnew file mode 100644index 00000000..6098d9b1--- /dev/null+++ b/database/migrations/2024_07_29_185123_create_jobs_table.php@@ -0,0 +1,32 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::create('jobs', function (Blueprint $table) {+ $table->bigIncrements('id');+ $table->string('queue')->index();+ $table->longText('payload');+ $table->unsignedTinyInteger('attempts');+ $table->unsignedInteger('reserved_at')->nullable();+ $table->unsignedInteger('available_at');+ $table->unsignedInteger('created_at');+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('jobs');+ }+};