A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: implement metadata media type instead of reading mime type
aminnausindf2053a27c4b
diff --git a/app/Enums/MediaType.php b/app/Enums/MediaType.phpindex bca3742f..c31c0d38 100644--- a/app/Enums/MediaType.php+++ b/app/Enums/MediaType.php@@ -31,10 +31,18 @@ enum MediaType: int {return array_column(self::cases(), 'value');}- public static function getLabel(TaskStatus $type): string {+ public static function getLabel(MediaType $type): string {return match ($type) {self::VIDEO => 'video',self::AUDIO => 'audio',};}++ public static function fromLabel(string $label): ?self {+ return match (strtolower($label)) {+ 'video' => self::VIDEO,+ 'audio' => self::AUDIO,+ default => null,+ };+ }}diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.phpindex e063c4b9..387b92a8 100755--- a/app/Jobs/VerifyFiles.php+++ b/app/Jobs/VerifyFiles.php@@ -2,6 +2,7 @@namespace App\Jobs;+use App\Enums\MediaType;use App\Enums\TaskStatus;use App\Models\Metadata;use App\Models\Record;@@ -191,10 +192,15 @@ class VerifyFiles implements ShouldQueue {}$mime_type = isset($changes['mime_type']) ? $changes['mime_type'] : $metadata->mime_type;+ $is_audio = str_starts_with($mime_type, 'audio');+ $media_type = $is_audio ? MediaType::AUDIO : MediaType::VIDEO;+ if ($stored['media_type'] !== $media_type) {+ $changes['media_type'] = $media_type;+ }// if file is of type audio one of the following is true: description and episode is null, codec is null, bitrate is null => generate description from audio tags- $audioMetadata = ((is_null($metadata->description) && is_null($metadata->episode)) || is_null($metadata->bitrate) || is_null($metadata->codec)) && str_starts_with($mime_type, 'audio') ? $this->getAudioDescription($filePath, $this->fileMetaData ?? null) : [];- if ((is_null($metadata->poster_url) || filemtime($filePath)) && $mime_type && str_starts_with($mime_type, 'audio')) {+ $audioMetadata = ((is_null($metadata->description) && is_null($metadata->episode)) || is_null($metadata->bitrate) || is_null($metadata->codec)) && $is_audio ? $this->getAudioDescription($filePath, $this->fileMetaData ?? null) : [];+ if ((is_null($metadata->poster_url) || filemtime($filePath)) && $mime_type && $is_audio) {$relativePath = $video->folder->path . '/' . $metadata->id;$coverArtPath = "posters/audio/$relativePath-$uuid.png";@@ -215,7 +221,7 @@ class VerifyFiles implements ShouldQueue {$changes['duration'] = $duration;}- if (! str_starts_with($mime_type, 'audio') && (is_null($metadata->resolution_height) || is_null($metadata->codec))) {+ if (! $is_audio && (is_null($metadata->resolution_height) || is_null($metadata->codec))) {$this->confirmMetadata($filePath);foreach ($this->fileMetaData['streams'] as $stream) {if (! isset($stream['codec_type']) || $stream['codec_type'] !== 'video' || ! isset($stream['width'])) {@@ -246,7 +252,7 @@ class VerifyFiles implements ShouldQueue {$changes['season'] = count($season) == 1 ? (int) $season[0] : $audioMetadata['season'] ?? null;}- if (is_null($metadata->title) && ! str_starts_with($mime_type, 'audio')) {+ if (is_null($metadata->title) && ! $is_audio) {$newTitle = count($season) == 1 ? 'S' . $season[0] : '';$newTitle .= count($episode) == 1 ? 'E' . $episode[0] : '';@@ -257,7 +263,7 @@ class VerifyFiles implements ShouldQueue {}}- if ((is_null($metadata->title) || $fileUpdated) && str_starts_with($mime_type, 'audio') && isset($audioMetadata['title'])) {+ if ((is_null($metadata->title) || $fileUpdated) && $is_audio && isset($audioMetadata['title'])) {$changes['title'] = $audioMetadata['title'];}@@ -339,6 +345,7 @@ class VerifyFiles implements ShouldQueue {'poster_url','date_scanned','date_uploaded',+ 'media_type']);diff --git a/app/Models/Metadata.php b/app/Models/Metadata.phpindex 35d5ec8a..3da784bc 100644--- a/app/Models/Metadata.php+++ b/app/Models/Metadata.php@@ -2,6 +2,7 @@namespace App\Models;+use App\Enums\MediaType;use Carbon\Carbon;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;@@ -34,10 +35,12 @@ class Metadata extends Model {'date_released','date_scanned','date_uploaded',+ 'media_type'];protected $casts = ['date_uploaded' => 'datetime',+ 'media_type' => MediaType::class,];public function video(): BelongsTo {diff --git a/app/Models/Series.php b/app/Models/Series.phpindex fc7ea4f4..725a1167 100644--- a/app/Models/Series.php+++ b/app/Models/Series.php@@ -2,6 +2,7 @@namespace App\Models;+use App\Enums\MediaType;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\BelongsTo;@@ -26,6 +27,10 @@ class Series extends Model {'thumbnail_url',];+ protected $casts = [+ 'primary_media_type' => MediaType::class,+ ];+public function folder(): BelongsTo {return $this->belongsTo(Folder::class);}diff --git a/config/scramble.php b/config/scramble.phpnew file mode 100644index 00000000..fdd49209--- /dev/null+++ b/config/scramble.php@@ -0,0 +1,87 @@+<?php++use Dedoc\Scramble\Http\Middleware\RestrictedDocsAccess;++return [+ /*+ * Your API path. By default, all routes starting with this path will be added to the docs.+ * If you need to change this behavior, you can add your custom routes resolver using `Scramble::routes()`.+ */+ 'api_path' => 'api',++ /*+ * Your API domain. By default, app domain is used. This is also a part of the default API routes+ * matcher, so when implementing your own, make sure you use this config if needed.+ */+ 'api_domain' => null,++ /*+ * The path where your OpenAPI specification will be exported.+ */+ 'export_path' => 'api.json',++ 'info' => [+ /*+ * API version.+ */+ 'version' => env('API_VERSION', '0.0.1'),++ /*+ * Description rendered on the home page of the API documentation (`/docs/api`).+ */+ 'description' => '',+ ],++ /*+ * Customize Stoplight Elements UI+ */+ 'ui' => [+ /*+ * Define the title of the documentation's website. App name is used when this config is `null`.+ */+ 'title' => null,++ /*+ * Define the theme of the documentation. Available options are `light` and `dark`.+ */+ 'theme' => 'dark',++ /*+ * Hide the `Try It` feature. Enabled by default.+ */+ 'hide_try_it' => false,++ /*+ * URL to an image that displays as a small square logo next to the title, above the table of contents.+ */+ 'logo' => '',++ /*+ * Use to fetch the credential policy for the Try It feature. Options are: omit, include (default), and same-origin+ */+ 'try_it_credentials_policy' => 'include',+ ],++ /*+ * The list of servers of the API. By default, when `null`, server URL will be created from+ * `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you+ * will need to specify the local server URL manually (if needed).+ *+ * Example of non-default config (final URLs are generated using Laravel `url` helper):+ *+ * ```php+ * 'servers' => [+ * 'Live' => 'api',+ * 'Prod' => 'https://scramble.dedoc.co/api',+ * ],+ * ```+ */+ 'servers' => null,++ 'middleware' => [+ 'web',+ RestrictedDocsAccess::class,+ ],++ 'extensions' => [],+];diff --git a/database/migrations/2025_05_27_173949_add_media_type_to_metadata.php b/database/migrations/2025_05_27_173949_add_media_type_to_metadata.phpnew file mode 100644index 00000000..2e38422f--- /dev/null+++ b/database/migrations/2025_05_27_173949_add_media_type_to_metadata.php@@ -0,0 +1,26 @@+<?php++use App\Enums\MediaType;+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::table('metadata', function (Blueprint $table) {+ $table->tinyInteger('media_type')->default(MediaType::VIDEO);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void {+ Schema::table('metadata', function (Blueprint $table) {+ $table->dropColumn('media_type');+ });+ }+};diff --git a/resources/js/components/cards/VideoCard.vue b/resources/js/components/cards/VideoCard.vueindex cd140bd2..7050520e 100755--- a/resources/js/components/cards/VideoCard.vue+++ b/resources/js/components/cards/VideoCard.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import type { ContextMenuItem } from '@/types/types';+import { MediaType, type ContextMenuItem } from '@/types/types';import type { VideoResource } from '@/types/resources';import { formatFileSize, toFormattedDate } from '@/service/util';@@ -26,7 +26,7 @@ const { stateFolder, stateDirectory } = storeToRefs(useContentStore());const { setContextMenu } = useAppStore();const isAudio = computed(() => {- return props.data?.metadata?.mime_type?.startsWith('audio') ?? false;+ return props.data.metadata?.media_type === MediaType.AUDIO;});const contextMenuItems = computed(() => {@@ -76,14 +76,14 @@ watch(<template #trigger><span class="flex group"><h3 class="line-clamp-1 break-all">- {{ `${data.episode ? `${data.episode}. ` : ''}${data.title}` }}+ {{ metaData.fields.title }}</h3><ProiconsComment class="my-auto ms-4 group-hover:opacity-20 opacity-100 transition-opacity duration-300 shrink-0 h-5 w-5" title="Description" /></span></template></HoverCard><h3 v-else class="flex-1 truncate min-w-[30%]" :title="data.title">- {{ `${data.episode ? `${data.episode}. ` : ''}${data.title}` }}+ {{ metaData.fields.title }}</h3><HoverCardclass="items-end flex-1 -ms-2 hidden sm:block"diff --git a/resources/js/components/forms/EditVideo.vue b/resources/js/components/forms/EditVideo.vueindex d4adf1a5..794bf4b3 100755--- a/resources/js/components/forms/EditVideo.vue+++ b/resources/js/components/forms/EditVideo.vue@@ -1,6 +1,6 @@<script setup lang="ts">import type { TagResource, VideoResource, VideoTagResource } from '@/types/resources';-import { type FormField, type SelectItem } from '@/types/types';+import { MediaType, type FormField, type SelectItem } from '@/types/types';import type { MetadataUpdateRequest } from '@/types/requests';import { computed, reactive, ref, watch } from 'vue';@@ -25,7 +25,7 @@ const { data: tagsQuery } = useGetAllTags();const createTag = UseCreateTag();const isAudio = computed(() => {- return props.video?.metadata?.mime_type?.startsWith('audio') ?? false;+ return props.video.metadata?.media_type === MediaType.AUDIO;});const allTags = ref<TagResource[]>([]);@@ -58,19 +58,39 @@ const fields = reactive<FormField[]>([},{name: 'episode',- text: isAudio.value ? 'Track' : 'Episode',+ text: 'Episode',type: 'number',value: props.video?.episode ?? 1,default: 0,min: 0,+ disabled: props.video.metadata?.media_type !== 0,},{name: 'season',- text: isAudio.value ? 'Disc' : 'Season',+ text: 'Season',type: 'number',value: props.video?.season ?? 1,default: 0,min: 0,+ disabled: props.video.metadata?.media_type !== 0,+ },+ {+ name: 'episode',+ text: 'Track',+ type: 'number',+ value: props.video?.episode ?? 1,+ default: 0,+ min: 0,+ disabled: props.video.metadata?.media_type !== 1,+ },+ {+ name: 'season',+ text: 'Disc',+ type: 'number',+ value: props.video?.season ?? 1,+ default: 0,+ min: 0,+ disabled: props.video.metadata?.media_type !== 1,},{name: 'poster_url',@@ -171,7 +191,7 @@ watch(tagsQuery, () => {<template><form class="flex flex-col sm:flex-row sm:justify-between flex-wrap gap-4" @submit.prevent="handleSubmit">- <div v-for="(field, index) in fields" :key="index" class="w-full" :class="field.class">+ <div v-for="(field, index) in fields.filter((field) => !field.disabled)" :key="index" class="w-full" :class="field.class"><FormInputLabel :field="field" /><FormTextArea v-if="field.type === 'textArea'" v-model="form.fields[field.name]" :field="field" />diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vueindex 9c40fcef..d4a17d22 100755--- a/resources/js/components/video/VideoPlayer.vue+++ b/resources/js/components/video/VideoPlayer.vue@@ -1,6 +1,6 @@<script setup lang="ts">import type { FolderResource, UserResource, VideoResource } from '@/types/resources';-import type { ContextMenuItem, PopoverItem } from '@/types/types';+import { type ContextMenuItem, type PopoverItem, MediaType } from '@/types/types';import type { Series } from '@/types/model';import { getScreenSize, handleStorageURL, isInputLikeElement, isMobileDevice, toFormattedDate, toFormattedDuration } from '@/service/util';@@ -286,7 +286,7 @@ const videoPopoverItems = computed(() => {// Computed Player Stateconst isAudio = computed(() => {- return stateVideo.value.metadata?.mime_type?.startsWith('audio') ?? false;+ return stateVideo.value.metadata?.media_type === MediaType.AUDIO;});const isPortrait = computed(() => {diff --git a/resources/js/composables/useMetaData.ts b/resources/js/composables/useMetaData.tsindex 99d81eeb..8410486c 100644--- a/resources/js/composables/useMetaData.ts+++ b/resources/js/composables/useMetaData.ts@@ -1,6 +1,7 @@import type { VideoResource } from '@/types/resources';import { formatFileSize, toFormattedDuration } from '@/service/util';+import { MediaType } from '@/types/types';import { useRoute } from 'vue-router';import { reactive } from 'vue';@@ -10,7 +11,7 @@ export default function useMetaData(data: VideoResource, skipBaseURL: boolean =const metadata = reactive({fields: {- title: data?.title ?? data?.name,+ title: `${data.episode && data.metadata?.media_type === MediaType.AUDIO ? `${data.episode}. ` : ''}${data?.title ?? data?.name}`,duration: toFormattedDuration(data?.duration) ?? 'N/A',views: data?.view_count ? `${data?.view_count} view${data?.view_count !== 1 ? 's' : ''}` : '0 views',description: data?.description ?? '',@@ -20,7 +21,8 @@ export default function useMetaData(data: VideoResource, skipBaseURL: boolean =updateData(props: VideoResource) {this.fields = {...this.fields,- title: props?.title ?? props?.name,++ title: `${props.episode && props.metadata?.media_type === MediaType.AUDIO ? `${props.episode}. ` : ''}${props?.title ?? props?.name}`,duration: toFormattedDuration(props?.duration) ?? 'N/A',views: props?.view_count ? `${props?.view_count} view${props?.view_count !== 1 ? 's' : ''}` : '0 views',description: props?.description ?? '',diff --git a/resources/js/types/model.ts b/resources/js/types/model.tsindex 59a26962..977cf5a5 100644--- a/resources/js/types/model.ts+++ b/resources/js/types/model.ts@@ -1,3 +1,5 @@+import type { MediaTypeValue } from '@/types/types';+/* eslint-disable @typescript-eslint/no-explicit-any */export interface Category {id: number;@@ -45,6 +47,7 @@ export interface Metadata {poster_url?: string;playbacks?: Playback[];video_tags?: VideoTag[];+ media_type: MediaTypeValue;}export interface Playback {id: number;diff --git a/resources/js/types/types.ts b/resources/js/types/types.tsindex a425569d..87864f19 100644--- a/resources/js/types/types.ts+++ b/resources/js/types/types.ts@@ -146,6 +146,13 @@ export interface TaskStatsResponse {export type TaskStatus = 'pending' | 'processing' | 'completed' | 'cancelled' | 'failed' | 'incomplete';+export const MediaType = {+ VIDEO: 0,+ AUDIO: 1,+} as const;++export type MediaTypeValue = (typeof MediaType)[keyof typeof MediaType];+export interface ContextMenuItem {text?: string;shortcut?: string;@@ -250,6 +257,7 @@ export interface FormField {min?: number;max?: number;class?: string;+ disabled?: boolean;}export interface SelectItem {diff --git a/routes/api.php b/routes/api.phpindex 7dd5577e..c5a40057 100755--- a/routes/api.php+++ b/routes/api.php@@ -1,25 +1,25 @@<?php-use App\Http\Controllers\Api\V1\AnalyticsController;-use App\Http\Controllers\Api\V1\AuthController;-use App\Http\Controllers\Api\V1\CategoryController;-use App\Http\Controllers\Api\V1\ExternalMetadataController;-use App\Http\Controllers\Api\V1\FolderController;+use App\Support\AppManifest;+use Illuminate\Http\Request;+use Illuminate\Support\Facades\Route;+use App\Http\Controllers\DirectoryController;use App\Http\Controllers\Api\V1\JobController;-use App\Http\Controllers\Api\V1\MetadataController;-use App\Http\Controllers\Api\V1\PlaybackController;-use App\Http\Controllers\Api\V1\ProfileController;-use App\Http\Controllers\Api\V1\RecordController;-use App\Http\Controllers\Api\V1\SeriesController;-use App\Http\Controllers\Api\V1\SubTaskController;use App\Http\Controllers\Api\V1\TagController;+use App\Http\Controllers\Api\V1\AuthController;use App\Http\Controllers\Api\V1\TaskController;use App\Http\Controllers\Api\V1\UserController;use App\Http\Controllers\Api\V1\VideoController;-use App\Http\Controllers\DirectoryController;-use App\Support\AppManifest;-use Illuminate\Http\Request;-use Illuminate\Support\Facades\Route;+use App\Http\Controllers\Api\V1\FolderController;+use App\Http\Controllers\Api\V1\RecordController;+use App\Http\Controllers\Api\V1\SeriesController;+use App\Http\Controllers\Api\V1\ProfileController;+use App\Http\Controllers\Api\V1\SubTaskController;+use App\Http\Controllers\Api\V1\CategoryController;+use App\Http\Controllers\Api\V1\MetadataController;+use App\Http\Controllers\Api\V1\PlaybackController;+use App\Http\Controllers\Api\V1\AnalyticsController;+use App\Http\Controllers\Api\V1\ExternalMetadataController;use Robertogallea\PulseApi\Http\Controllers\DashboardController;Route::get('/user', function (Request $request) {@@ -49,6 +49,8 @@ Route::group(['middleware' => ['auth:sanctum']], function () {Route::post('/sub-tasks/{task}', [SubTaskController::class, 'show']);Route::post('/categories/privacy/{category}', [CategoryController::class, 'updatePrivacy']);+ Route::get('/metadata/{id}/import/lyrics', [ExternalMetadataController::class, 'importLyrics']);+Route::prefix('tasks')->group(function () {Route::get('/stats', [TaskController::class, 'stats']);Route::post('/sync', [JobController::class, 'syncFiles']);@@ -72,8 +74,6 @@ Route::get('/manifest', function () {return response()->json(AppManifest::info());});-Route::get('/metadata/{id}/import/lyrics', [ExternalMetadataController::class, 'importLyrics']);-Route::post('/login', [AuthController::class, 'login']);Route::post('/register', [AuthController::class, 'register']);Route::patch('/videos/watch/{video}', [VideoController::class, 'watch']);