Skip to content

A self-hosted media server and file management system

feat: implement subtitle models

aminnausin2e62ac54c769
diff --git a/app/Http/Resources/SubtitleResource.php b/app/Http/Resources/SubtitleResource.php
new file mode 100644
index 00000000..57d57707
--- /dev/null
+++ b/app/Http/Resources/SubtitleResource.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Request;
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class SubtitleResource extends JsonResource {
+ /**
+ * Transform the resource into an array.
+ *
+ * @return array<string, mixed>
+ */
+ public function toArray(Request $request): array {
+ return [
+ 'id' => $this->id,
+ 'track_id' => $this->track_id,
+ 'metadata_uuid' => $this->metadata_uuid,
+ 'language' => $this->language,
+ 'codec' => $this->codec,
+ ];
+ }
+}
diff --git a/app/Http/Resources/VideoResource.php b/app/Http/Resources/VideoResource.php
index 825e71e8..5ea6b08e 100755
--- a/app/Http/Resources/VideoResource.php
+++ b/app/Http/Resources/VideoResource.php
@@ -16,6 +16,10 @@ class VideoResource extends JsonResource {
$this->loadMissing('metadata');
}
+ if (! $this->relationLoaded('metadata.subtitles')) {
+ $this->loadMissing('metadata.subtitles');
+ }
+
$metadata = $this->metadata;
return [
@@ -38,6 +42,7 @@ class VideoResource extends JsonResource {
'date_released' => $metadata?->date_released ?: null, // User Provided Release Date
'date_uploaded' => $metadata?->date_uploaded ?: null, // File Last Modified (Should be date_added)
'metadata' => $metadata,
+ 'subtitles' => SubtitleResource::collection($metadata->subtitles ?? [])
];
}
}
diff --git a/app/Models/Metadata.php b/app/Models/Metadata.php
index 7c615f5d..de59e443 100644
--- a/app/Models/Metadata.php
+++ b/app/Models/Metadata.php
@@ -66,6 +66,10 @@ class Metadata extends Model {
return $this->hasMany(Record::class);
}
+ public function subtitles(): HasMany {
+ return $this->hasMany(Subtitle::class, 'metadata_uuid', 'uuid');
+ }
+
public function getDateReleasedFormattedAttribute() {
return $this->attributes['date_released'] ? Carbon::parse($this->attributes['date_released'])->format('F d, Y') : null;
}
diff --git a/app/Models/Subtitle.php b/app/Models/Subtitle.php
new file mode 100644
index 00000000..d7127887
--- /dev/null
+++ b/app/Models/Subtitle.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class Subtitle extends Model {
+ protected $fillable = [
+ 'track_id',
+ 'language',
+ 'codec',
+ 'format',
+ 'path',
+ ];
+
+ public function metadata(): BelongsTo {
+ return $this->belongsTo(Metadata::class, 'uuid', 'metadata_uuid');
+ }
+}
diff --git a/config/app.php b/config/app.php
index d7992068..1b7f8d9e 100755
--- a/config/app.php
+++ b/config/app.php
@@ -71,7 +71,7 @@ return [
|
*/
- 'timezone' => env('APP_TIMEZONE', 'UTC'),
+ 'timezone' => env('APP_TIMEZONE', 'UTC'), // Always UTC on backend
/*
|--------------------------------------------------------------------------
diff --git a/resources/js/types/model.ts b/resources/js/types/model.ts
index 5497c685..8cfae063 100644
--- a/resources/js/types/model.ts
+++ b/resources/js/types/model.ts
@@ -49,6 +49,19 @@ export interface Metadata {
album?: string;
video_tags?: VideoTag[];
media_type: MediaTypeValue;
+ subtitles_scanned_at?: string;
+}
+
+export interface Subtitle {
+ id: number;
+ track_id: number;
+ metadata_uuid: string;
+ language?: string;
+ codec?: string;
+ format?: string;
+ path?: string;
+ created_at: string;
+ updated_at: string;
}
export interface Playback {
id: number;
diff --git a/resources/js/types/resources.ts b/resources/js/types/resources.ts
index 82b7f42b..fa7232a9 100644
--- a/resources/js/types/resources.ts
+++ b/resources/js/types/resources.ts
@@ -137,7 +137,17 @@ export interface VideoResource {
date_updated?: string;
date_uploaded?: string;
metadata?: Metadata;
+ subtitles: SubtitleResource[];
}
+
+export interface SubtitleResource {
+ id: number;
+ track_id: number;
+ metadata_uuid: string;
+ language?: string;
+ codec?: string;
+}
+
export interface VideoTagResource {
video_tag_id: number; // video tag (this) id
name: string;