Commit de193171 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(soundbites): add soundbite list and creation forms with audio-clipper component

parent 602654b9
Loading
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -39,10 +39,9 @@ class AddClips extends Migration
                'type' => 'DECIMAL(7,3)',
                'unsigned' => true,
            ],
            'label' => [
            'title' => [
                'type' => 'VARCHAR',
                'constraint' => 128,
                'null' => true,
            ],
            'type' => [
                'type' => 'ENUM',
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ use Modules\Auth\Entities\User;
 * @property Podcast $podcast
 * @property int $episode_id
 * @property Episode $episode
 * @property string $label
 * @property string $title
 * @property double $start_time
 * @property double $end_time
 * @property double $duration
@@ -68,7 +68,7 @@ class BaseClip extends Entity
        'id' => 'integer',
        'podcast_id' => 'integer',
        'episode_id' => 'integer',
        'label' => 'string',
        'title' => 'string',
        'start_time' => 'double',
        'duration' => 'double',
        'type' => 'string',
+2 −2
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ if (! function_exists('get_rss_feed')) {
            $comments->addAttribute('uri', url_to('episode-comments', $podcast->handle, $episode->slug));
            $comments->addAttribute('contentType', 'application/podcast-activity+json');

            if ($episode->transcript->file_url !== '') {
            if ($episode->transcript !== null) {
                $transcriptElement = $item->addChild('transcript', null, $podcastNamespace);
                $transcriptElement->addAttribute('url', $episode->transcript->file_url);
                $transcriptElement->addAttribute(
@@ -275,7 +275,7 @@ if (! function_exists('get_rss_feed')) {

            foreach ($episode->soundbites as $soundbite) {
                // TODO: differentiate video from soundbites?
                $soundbiteElement = $item->addChild('soundbite', $soundbite->label, $podcastNamespace);
                $soundbiteElement = $item->addChild('soundbite', $soundbite->title, $podcastNamespace);
                $soundbiteElement->addAttribute('start_time', (string) $soundbite->start_time);
                $soundbiteElement->addAttribute('duration', (string) $soundbite->duration);
            }
+48 −28
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class ClipModel extends Model
        'id',
        'podcast_id',
        'episode_id',
        'label',
        'title',
        'start_time',
        'duration',
        'type',
@@ -89,33 +89,6 @@ class ClipModel extends Model
        parent::__construct($db, $validation);
    }

    /**
     * Gets all clips for an episode
     *
     * @return Soundbite[]
     */
    public function getEpisodeSoundbites(int $podcastId, int $episodeId): array
    {
        $cacheName = "podcast#{$podcastId}_episode#{$episodeId}_soundbites";
        if (! ($found = cache($cacheName))) {
            $found = $this->where([
                'episode_id' => $episodeId,
                'podcast_id' => $podcastId,
                'type' => 'audio',
            ])
                ->orderBy('start_time')
                ->findAll();

            foreach ($found as $key => $soundbite) {
                $found[$key] = new Soundbite($soundbite->toArray());
            }

            cache()
                ->save($cacheName, $found, DECADE);
        }
        return $found;
    }

    public function getVideoClipById(int $videoClipId): ?VideoClip
    {
        $cacheName = "video-clip#{$videoClipId}";
@@ -184,6 +157,53 @@ class ClipModel extends Model
        return $found;
    }

    public function getSoundbiteById(int $soundbiteId): ?Soundbite
    {
        $cacheName = "soundbite#{$soundbiteId}";
        if (! ($found = cache($cacheName))) {
            $clip = $this->find($soundbiteId);

            if ($clip === null) {
                return null;
            }

            // @phpstan-ignore-next-line
            $found = new Soundbite($clip->toArray());

            cache()
                ->save($cacheName, $found, DECADE);
        }

        return $found;
    }

    /**
     * Gets all clips for an episode
     *
     * @return Soundbite[]
     */
    public function getEpisodeSoundbites(int $podcastId, int $episodeId): array
    {
        $cacheName = "podcast#{$podcastId}_episode#{$episodeId}_soundbites";
        if (! ($found = cache($cacheName))) {
            $found = $this->where([
                'episode_id' => $episodeId,
                'podcast_id' => $podcastId,
                'type' => 'audio',
            ])
                ->orderBy('start_time')
                ->findAll();

            foreach ($found as $key => $soundbite) {
                $found[$key] = new Soundbite($soundbite->toArray());
            }

            cache()
                ->save($cacheName, $found, DECADE);
        }
        return $found;
    }

    public function deleteSoundbite(int $podcastId, int $episodeId, int $clipId): BaseResult | bool
    {
        cache()
+1 −2
Original line number Diff line number Diff line
@@ -10,11 +10,11 @@ import "./modules/markdown-preview";
import "./modules/markdown-write-preview";
import MultiSelect from "./modules/MultiSelect";
import "./modules/permalink-edit";
import "./modules/play-soundbite";
import PublishMessageWarning from "./modules/PublishMessageWarning";
import Select from "./modules/Select";
import SidebarToggler from "./modules/SidebarToggler";
import Slugify from "./modules/Slugify";
import Soundbites from "./modules/Soundbites";
import ThemePicker from "./modules/ThemePicker";
import Time from "./modules/Time";
import Tooltip from "./modules/Tooltip";
@@ -31,7 +31,6 @@ SidebarToggler();
ClientTimezone();
DateTimePicker();
Time();
Soundbites();
Clipboard();
ThemePicker();
PublishMessageWarning();
Loading