Loading app/Database/Migrations/2021-12-09-130000_add_clips.php +8 −4 Original line number Diff line number Diff line Loading @@ -72,15 +72,19 @@ class AddClips extends Migration 'type' => 'INT', 'unsigned' => true, ], 'created_at' => [ 'job_started_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'updated_at' => [ 'job_ended_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'deleted_at' => [ 'created_at' => [ 'type' => 'DATETIME', ], 'updated_at' => [ 'type' => 'DATETIME', 'null' => true, ], ]); Loading app/Entities/Clip/BaseClip.php +32 −12 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ namespace App\Entities\Clip; use App\Entities\Episode; use App\Entities\Media\Audio; use App\Entities\Media\BaseMedia; use App\Entities\Media\Video; use App\Entities\Podcast; use App\Models\EpisodeModel; Loading @@ -21,6 +20,7 @@ use App\Models\PodcastModel; use App\Models\UserModel; use CodeIgniter\Entity\Entity; use CodeIgniter\Files\File; use CodeIgniter\I18n\Time; use Modules\Auth\Entities\User; /** Loading @@ -34,21 +34,32 @@ use Modules\Auth\Entities\User; * @property double $end_time * @property double $duration * @property string $type * @property int $media_id * @property Video|Audio $media * @property int|null $media_id * @property Video|Audio|null $media * @property array|null $metadata * @property string $status * @property string $logs * @property User $user * @property int $created_by * @property int $updated_by * @property Time|null $job_started_at * @property Time|null $job_ended_at */ class BaseClip extends Entity { /** * @var BaseMedia * @var Video|Audio|null */ protected $media = null; protected $media; protected ?int $job_duration = null; protected ?float $end_time = null; /** * @var string[] */ protected $dates = ['created_at', 'updated_at', 'job_started_at', 'job_ended_at']; /** * @var array<string, string> Loading @@ -75,12 +86,25 @@ class BaseClip extends Entity public function __construct(array $data = null) { parent::__construct($data); } if ($this->start_time && $this->duration) { public function getJobDuration(): ?int { if ($this->job_duration === null && $this->job_started_at && $this->job_ended_at) { $this->job_duration = ($this->job_started_at->difference($this->job_ended_at)) ->getSeconds(); } return $this->job_duration; } public function getEndTime(): float { if ($this->end_time === null) { $this->end_time = $this->start_time + $this->duration; } elseif ($this->start_time && $this->end_time) { $this->duration = $this->end_time - $this->duration; } return $this->end_time; } public function getPodcast(): ?Podcast Loading Loading @@ -128,16 +152,12 @@ class BaseClip extends Entity return $this; } /** * @noRector ReturnTypeDeclarationRector */ public function getMedia(): Audio | Video | null { if ($this->media_id !== null && $this->media === null) { $this->media = (new MediaModel($this->type))->getMediaById($this->media_id); } // @phpstan-ignore-next-line return $this->media; } } app/Helpers/components_helper.php +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ if (! function_exists('hint_tooltip')) { $tooltip = '<span data-tooltip="bottom" tabindex="0" title="' . $hintText . '" class="inline-block align-middle text-skin-muted focus:ring-accent'; '" class="inline-block align-middle opacity-75 focus:ring-accent'; if ($class !== '') { $tooltip .= ' ' . $class; Loading app/Helpers/misc_helper.php +9 −5 Original line number Diff line number Diff line Loading @@ -136,16 +136,20 @@ if (! function_exists('slugify')) { if (! function_exists('format_duration')) { /** * Formats duration in seconds to an hh:mm:ss string. Doesn't show leading zeros if any. * Formats duration in seconds to an hh:mm:ss string. * * ⚠️ This uses php's gmdate function so any duration > 86000 seconds (24 hours) will not be formatted properly. * * @param int $seconds seconds to format */ function format_duration(int $seconds): string function format_duration(int $seconds, bool $showLeadingZeros = false): string { if ($showLeadingZeros) { return gmdate('H:i:s', $seconds); } if ($seconds < 60) { return '0:' . $seconds; return '0:' . sprintf('%02d', $seconds); } if ($seconds < 3600) { // < 1 hour: returns MM:SS Loading @@ -153,9 +157,9 @@ if (! function_exists('format_duration')) { } if ($seconds < 36000) { // < 10 hours: returns H:MM:SS return ltrim(gmdate('h:i:s', $seconds), '0'); return ltrim(gmdate('H:i:s', $seconds), '0'); } return gmdate('h:i:s', $seconds); return gmdate('H:i:s', $seconds); } } Loading app/Libraries/MediaClipper/Config/MediaClipper.php +1 −1 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ class MediaClipper extends BaseConfig 'rescaleHeight' => 1200, 'x' => 0, 'y' => 600, 'mask' => APPPATH . 'Libraries/MediaClipper/soundwaves-mask-squared.png', 'mask' => APPPATH . 'Libraries/MediaClipper/soundwaves-mask-square.png', ], 'subtitles' => [ 'fontsize' => 20, Loading Loading
app/Database/Migrations/2021-12-09-130000_add_clips.php +8 −4 Original line number Diff line number Diff line Loading @@ -72,15 +72,19 @@ class AddClips extends Migration 'type' => 'INT', 'unsigned' => true, ], 'created_at' => [ 'job_started_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'updated_at' => [ 'job_ended_at' => [ 'type' => 'DATETIME', 'null' => true, ], 'deleted_at' => [ 'created_at' => [ 'type' => 'DATETIME', ], 'updated_at' => [ 'type' => 'DATETIME', 'null' => true, ], ]); Loading
app/Entities/Clip/BaseClip.php +32 −12 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ namespace App\Entities\Clip; use App\Entities\Episode; use App\Entities\Media\Audio; use App\Entities\Media\BaseMedia; use App\Entities\Media\Video; use App\Entities\Podcast; use App\Models\EpisodeModel; Loading @@ -21,6 +20,7 @@ use App\Models\PodcastModel; use App\Models\UserModel; use CodeIgniter\Entity\Entity; use CodeIgniter\Files\File; use CodeIgniter\I18n\Time; use Modules\Auth\Entities\User; /** Loading @@ -34,21 +34,32 @@ use Modules\Auth\Entities\User; * @property double $end_time * @property double $duration * @property string $type * @property int $media_id * @property Video|Audio $media * @property int|null $media_id * @property Video|Audio|null $media * @property array|null $metadata * @property string $status * @property string $logs * @property User $user * @property int $created_by * @property int $updated_by * @property Time|null $job_started_at * @property Time|null $job_ended_at */ class BaseClip extends Entity { /** * @var BaseMedia * @var Video|Audio|null */ protected $media = null; protected $media; protected ?int $job_duration = null; protected ?float $end_time = null; /** * @var string[] */ protected $dates = ['created_at', 'updated_at', 'job_started_at', 'job_ended_at']; /** * @var array<string, string> Loading @@ -75,12 +86,25 @@ class BaseClip extends Entity public function __construct(array $data = null) { parent::__construct($data); } if ($this->start_time && $this->duration) { public function getJobDuration(): ?int { if ($this->job_duration === null && $this->job_started_at && $this->job_ended_at) { $this->job_duration = ($this->job_started_at->difference($this->job_ended_at)) ->getSeconds(); } return $this->job_duration; } public function getEndTime(): float { if ($this->end_time === null) { $this->end_time = $this->start_time + $this->duration; } elseif ($this->start_time && $this->end_time) { $this->duration = $this->end_time - $this->duration; } return $this->end_time; } public function getPodcast(): ?Podcast Loading Loading @@ -128,16 +152,12 @@ class BaseClip extends Entity return $this; } /** * @noRector ReturnTypeDeclarationRector */ public function getMedia(): Audio | Video | null { if ($this->media_id !== null && $this->media === null) { $this->media = (new MediaModel($this->type))->getMediaById($this->media_id); } // @phpstan-ignore-next-line return $this->media; } }
app/Helpers/components_helper.php +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ if (! function_exists('hint_tooltip')) { $tooltip = '<span data-tooltip="bottom" tabindex="0" title="' . $hintText . '" class="inline-block align-middle text-skin-muted focus:ring-accent'; '" class="inline-block align-middle opacity-75 focus:ring-accent'; if ($class !== '') { $tooltip .= ' ' . $class; Loading
app/Helpers/misc_helper.php +9 −5 Original line number Diff line number Diff line Loading @@ -136,16 +136,20 @@ if (! function_exists('slugify')) { if (! function_exists('format_duration')) { /** * Formats duration in seconds to an hh:mm:ss string. Doesn't show leading zeros if any. * Formats duration in seconds to an hh:mm:ss string. * * ⚠️ This uses php's gmdate function so any duration > 86000 seconds (24 hours) will not be formatted properly. * * @param int $seconds seconds to format */ function format_duration(int $seconds): string function format_duration(int $seconds, bool $showLeadingZeros = false): string { if ($showLeadingZeros) { return gmdate('H:i:s', $seconds); } if ($seconds < 60) { return '0:' . $seconds; return '0:' . sprintf('%02d', $seconds); } if ($seconds < 3600) { // < 1 hour: returns MM:SS Loading @@ -153,9 +157,9 @@ if (! function_exists('format_duration')) { } if ($seconds < 36000) { // < 10 hours: returns H:MM:SS return ltrim(gmdate('h:i:s', $seconds), '0'); return ltrim(gmdate('H:i:s', $seconds), '0'); } return gmdate('h:i:s', $seconds); return gmdate('H:i:s', $seconds); } } Loading
app/Libraries/MediaClipper/Config/MediaClipper.php +1 −1 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ class MediaClipper extends BaseConfig 'rescaleHeight' => 1200, 'x' => 0, 'y' => 600, 'mask' => APPPATH . 'Libraries/MediaClipper/soundwaves-mask-squared.png', 'mask' => APPPATH . 'Libraries/MediaClipper/soundwaves-mask-square.png', ], 'subtitles' => [ 'fontsize' => 20, Loading