'integer', 'studio_plus_category_id' => 'integer', 'global_setting_id' => 'integer', 'types' => "array", 'is_old' => 'boolean', 'in_youtube' => 'boolean', 'in_ott' => 'boolean', 'video_duration' => 'integer', 'is_short' => 'boolean', 'metadata' => 'json', ]; protected $searchables = [ 'title', 'asin', 'product_name' ]; protected $appends = [ //'old', 'video_types', 'stamp', //'youtube', //'ott' ]; protected $dates = ['created_at', 'updated_at']; public const UPLOAD_STATUS_PENDING = 'PENDING'; public const UPLOAD_STATUS_PROCESSING = 'PROCESSING'; public const UPLOAD_STATUS_COMPLETE = 'COMPLETE'; public const VISIBILITY_TYPE_DRAFT = 'draft'; public const VISIBILITY_TYPE_PRIVATE = 'private'; public const VISIBILITY_TYPE_PUBLIC = 'public'; public const VISIBILITY_TYPE_UNLISTED = 'unlisted'; public const VISIBILITY_TYPE_SCHEDULE = 'schedule'; public const TYPE_SPONSORED = 'SPONSORED PRODUCT'; public const TYPE_REACH_OUT = 'REACH OUT'; public const TYPE_JOB = 'VIDEO BASED ON A JOB'; public const VIDEO_DEFAULT_PATH = '/Storage/default.ts'; public const VIDEO_SPONSORED_PATH = '/Storage/sponsored.ts'; public const STATUS_INTERNAL_PUBLISHED = 'Internal Published'; public const STATUS_REJECTED = 'Edit Required'; public const STATUS_REUPLOAD = 'Reupload'; public const STATUS_EDITED = 'Review by Admin'; public const STATUS_APPROVED = 'Approved'; public const STATUS_AMAZON_UPLOADED = 'Uploaded'; public const STATUS_AMAZON_APPROVED = 'Issue'; public const STATUS_PUBLISHED = 'Published'; public const STATUS_PUBLISHED_TO_AMAZON = 'Published To Amazon'; public static function statusTypes() { return [ self::STATUS_INTERNAL_PUBLISHED => self::STATUS_INTERNAL_PUBLISHED, self::STATUS_REJECTED => self::STATUS_REJECTED, self::STATUS_REUPLOAD => self::STATUS_REUPLOAD, self::STATUS_EDITED => self::STATUS_EDITED, self::STATUS_APPROVED => self::STATUS_APPROVED, self::STATUS_AMAZON_UPLOADED => self::STATUS_AMAZON_UPLOADED, self::STATUS_AMAZON_APPROVED => self::STATUS_AMAZON_APPROVED, self::STATUS_PUBLISHED => self::STATUS_PUBLISHED, ]; } public static function visibilityTypes() { return [ self::VISIBILITY_TYPE_DRAFT => self::VISIBILITY_TYPE_DRAFT, self::VISIBILITY_TYPE_PRIVATE => self::VISIBILITY_TYPE_PRIVATE, self::VISIBILITY_TYPE_PUBLIC => self::VISIBILITY_TYPE_PUBLIC, self::VISIBILITY_TYPE_UNLISTED => self::VISIBILITY_TYPE_UNLISTED, self::VISIBILITY_TYPE_SCHEDULE => self::VISIBILITY_TYPE_SCHEDULE, ]; } public static function videoTypes() { return [ self::TYPE_SPONSORED => self::TYPE_SPONSORED, self::TYPE_REACH_OUT => self::TYPE_REACH_OUT, self::TYPE_JOB => self::TYPE_JOB, ]; } public static function boot() { parent::boot(); self::deleting(function($video) { $video->otts()->each(function($ott) { $ott->links()->each(function($link) { $link->delete(); }); $ott->delete(); }); }); } public function asinData(): BelongsTo { return $this->belongsTo(StudioPlusAsin::class, 'studio_plus_asin_id') ->withDefault([ 'range_amount' => '' ]); } public function category(): BelongsTo { return $this->belongsTo(StudioPlusCategory::class, 'studio_plus_category_id') ->withDefault([ 'name' => '' ]); } public function videoType(): BelongsTo { return $this->belongsTo(StudioPlusVideoType::class, 'studio_plus_video_type_id') ->withDefault([ 'name' => '' ]); } public function otts(): HasMany { return $this->hasMany(StudioPlusVideoOtt::class, 'studio_plus_video_id', 'id'); } public function channel(): BelongsTo { return $this->belongsTo(StudioPlusChannel::class, 'studio_plus_channel_id'); } public function job(): BelongsTo { return $this->belongsTo(JobRequest::class, 'job_request_id'); } public function tags(): BelongsToMany { return $this->belongsToMany(StudioPlusTagVideo::class, 'studio_plus_tag_videos', 'studio_plus_video_id', 'studio_plus_tag_id') ->withTimeStamps(); } public function thumbnails(): HasMany { return $this->hasMany(StudioPlusThumbnail::class)->latest(); } public function thumbnail(): HasOne { return $this->hasOne(StudioPlusThumbnail::class, 'studio_plus_video_id', 'id') ->where('is_active', 1) ->latest(); } public function globalSetting(): BelongsTo { return $this->belongsTo(GlobalSetting::class); } public function comments() { return $this->hasMany(StudioPlusComment::class); } public function getVideoDurationAttribute($value) { $hour = 3600; $value = (int) $value; try { return $value >= $hour ? Carbon::parse($value)->format('H:i:s') : Carbon::parse($value)->format('i:s'); } catch (\Exception $ex) { dd($value); //dd($ex); } } public function getOriginalVideoUrlAttribute($value) { if ($this->upload_status !== self::UPLOAD_STATUS_COMPLETE && str_contains($value, 'temp')) { $result = "CreatorStudio/temp/upload/{$this->id}/video.mp4"; if (Storage::exists($result)) { return asset("storage/app/$result"); } return asset($value); } else { $bucketName = Config::get('studioplus.bucket_name'); $value = Str::remove('wticreatorhub/', $value); return Config::get('studioplus.google_api_endpoint') . "/$bucketName/$value"; } } public function getVideoUrlAttribute($value) { if ($this->upload_status !== self::UPLOAD_STATUS_COMPLETE && str_contains($value, 'temp')) { $result = "CreatorStudio/temp/upload/{$this->id}/result.mp4"; if (Storage::exists($result)) { return asset("storage/app/$result"); } return asset($value); } else { $meta = StudioPlusVideoMeta::where('studioplus_video_id', $this->id)->where('name', 'is_old')->where('value', 'true')->first(); if ($meta) { return $value; } $bucketName = Config::get('studioplus.bucket_name'); $value = Str::remove('wticreatorhub/', $value); return Config::get('studioplus.google_api_endpoint') . "/$bucketName/$value"; } } public function meta() { return $this->hasMany(StudioPlusVideoMeta::class, 'studioplus_video_id', 'id'); } public function getOldAttribute() { $meta = $this->meta()->where('name', 'is_old')->where('value', 'true')->first(); if ($meta) { return true; } return false; } public function getVideoTypesAttribute() { $types = collect($this->types); if ($this->is_short) { $types->push('SHORTS'); } return $types->join(', '); } public function getTagsAttribute($value) { if ($value) { return json_decode($value); } return null; } public function getStampAttribute() { if ($this->created_at) { return $this->created_at->format('F j, Y g:i A'); } return $this->created_at; } public function tracks() { return $this->hasMany(StudioPlusVideoStatusTrack::class, 'studio_plus_video_id', 'id')->latest(); } public function urls() { return $this->hasMany(VideoUrl::class, 'video_id'); } public function ottUrl() { return $this->hasOne(VideoUrl::class, 'video_id')->where('label', 'OTT'); } public function getYoutubeAttribute() { $meta = StudioPlusVideoMeta::where('studioplus_video_id', $this->id)->where('name', 'youtube')->first(); if ($meta) { if ($meta->value === 'true') { return true; } } return false; } public function getOttAttribute() { $meta = StudioPlusVideoMeta::where('studioplus_video_id', $this->id)->where('name', 'ott')->first(); if ($meta) { if ($meta->value === 'true') { return true; } } return false; } }