Skip to content

Commit

Permalink
Add build process
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Oct 24, 2024
1 parent 2a92645 commit 053f720
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 46 deletions.
26 changes: 23 additions & 3 deletions src/core/episodeRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ export function updateVideoPathBySlug(showSlug, episodeSlug, videoPath) {
}
);
}
export function updatePublicAudio(showSlug, episodeSlug, publicAudioFile) {
return Database.collection('posts').updateOne(
{
showSlug: showSlug,
slug: episodeSlug
},
{
$set: { publicAudioFile: publicAudioFile }
}
);
}

export function updateAudioPathBySlug(showSlug, episodeSlug, audioPath) {
return Database.collection('posts').updateOne(
{
showSlug: showSlug,
slug: episodeSlug
},
{
$set: { audioPath: audioPath }
}
);
}

export function updateTimeCodeBySlug(showSlug, episodeSlug, index, time, description, isPublicValue) {
const timeInSeconds = time.split(':').reduce((acc, time) => (60 * acc) + +time, 0);
Expand Down Expand Up @@ -107,9 +130,6 @@ export function updateMontageStatusBySlug(showSlug, episodeSlug, status) {
return Database.collection('posts').updateOne({ slug: episodeSlug, showSlug: showSlug }, { $set: { montage_status: status } });
}

export function updatePublicAudio(showSlug, episodeSlug, publicAudioFile) {
return Database.collection('posts').updateOne({ showSlug: showSlug, slug: episodeSlug }, { $set: { publicAudioFile: publicAudioFile } });
}

export function publishPodcast(showSlug, episodeSlug) {
return Database.collection('posts').updateOne({ showSlug: showSlug, slug: episodeSlug }, { $set: { visibility: 'public' } });
Expand Down
2 changes: 1 addition & 1 deletion src/montage/publicAudioGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function createPublicAudioJob(podcast) {

complexFilterString += `concat=n=${publicIndex - 1}:v=0:a=1`;

await applyFFmpegToFileInMinio(podcast.originFilePath, podcast.publicAudioFile, complexFilterString)
await applyFFmpegToFileInMinio(podcast.audioPath, podcast.publicAudioFile, complexFilterString)
}

export async function createPublicAudio(podcast) {
Expand Down
20 changes: 10 additions & 10 deletions src/routers/admin/detail/getDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,9 @@ async function getPodcastDetails(request, h) {
showAudio: false,
showVideo: false,
showUploadVideoButton: true,
audioUrl: buildObjectURL(podcast.originFilePath),
audioUrl: buildObjectURL(podcast.audioPath),
uploadUrl: `/admin/show/${showSlug}/episode/${episodeSlug}/upload`,
}
if (podcast.videoPath && podcast.originFilePath) {
media = {
showAudio: true,
showVideo: true,
showUploadVideoButton: false,
videoUrl: buildObjectURL(podcast.videoPath),
audioUrl: buildObjectURL(podcast.originFilePath),
}
}
if (podcast.videoPath) {
media = {
showAudio: false,
Expand All @@ -40,6 +31,15 @@ async function getPodcastDetails(request, h) {
audioUrl: buildObjectURL(podcast.originFilePath),
}
}
if (podcast.videoPath && podcast.audioPath) {
media = {
showAudio: true,
showVideo: true,
showUploadVideoButton: false,
videoUrl: buildObjectURL(podcast.videoPath),
audioUrl: buildObjectURL(podcast.audioPath),
}
}

media.showSlug = showSlug;
media.episodeSlug = episodeSlug;
Expand Down
19 changes: 18 additions & 1 deletion src/routers/admin/detail/mediaMontage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { getPostBySlug } from "../../../core/episodeRepo.js";
import { getPostBySlug, updateAudioPathBySlug } from "../../../core/episodeRepo.js";
import { applyFFmpegToFileInMinio } from "../../../minio/ffmpegApply.js";
import { buildObjectURL } from "../../../minio/utils.js";

async function buildAudio(request, h) {
const showSlug = request.params.showSlug;
const episodeSlug = request.params.episodeSlug;
const episode = await getPostBySlug(showSlug, episodeSlug);
const audioPath = `${showSlug}/episodes/${episodeSlug}/full-audio.wav`;
await applyFFmpegToFileInMinio(episode.videoPath, audioPath);
await updateAudioPathBySlug(showSlug, episodeSlug, audioPath);
console.log('Building audio for episode', showSlug, episodeSlug);

return h.view(
'media_component',
{
showSlug: showSlug,
episodeSlug: episodeSlug,
showAudio: true,
showVideo: true,
audioUrl: buildObjectURL(audioPath),
videoUrl: buildObjectURL(episode.videoPath),
showUploadVideoButton: false,
},
{
layout: false
}
)
}

export function media(server) {
Expand Down
65 changes: 34 additions & 31 deletions src/templates/widgets/media_component.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
{{#if showAudio}}
<div class="w-full sm:p-0 sm:m-0 mx-auto-2 lg:px-0">
<div id="audio-player-container">
<audio id="audio-player" controls class="w-full">
<source src="{{audioUrl}}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div id="media-container" class="py-8">
{{#if showAudio}}
<div class="w-full sm:p-0 sm:m-0 mx-auto-2 lg:px-0 py-4">
<div id="audio-player-container">
<audio id="audio-player" controls class="w-full">
<source src="{{audioUrl}}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
</div>
</div>
{{else}}
<button hx-post="/admin/show/{{showSlug}}/episode/{{episodeSlug}}/buildAudio" hx-swap="outerHTML"
class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out">
Build Audio
</button>
{{/if}}
{{else}}
<button hx-post="/admin/show/{{showSlug}}/episode/{{episodeSlug}}/buildAudio" hx-swap="outerHTML"
hx-target="#media-container" class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out">
Build Audio
</button>
{{/if}}

{{#if showVideo}}
<div class="w-full">
<div id="video-player-container">
<video id="video-player" controls class="w-full">
<source src="{{videoUrl}}" type="video/mp4">
Your browser does not support the video element.
</video>
{{#if showVideo}}
<div class="w-full py-4">
<div id="video-player-container">
<video id="video-player" controls class="w-full">
<source src="{{videoUrl}}" type="video/mp4">
Your browser does not support the video element.
</video>
</div>
</div>
</div>
{{/if}}
{{/if}}

{{#if showUploadVideoButton}}
<div class="w-full">
<form action="{{uploadUrl}}" method="POST" enctype="multipart/form-data" hx-post="{{uploadUrl}}" hx-swap="outerHTML">
<input type="file" name="video" accept=".mov" required />
<button type="submit" class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out">Upload
Video</button>
</form>
{{#if showUploadVideoButton}}
<div class="w-full py-4">
<form action="{{uploadUrl}}" method="POST" enctype="multipart/form-data" hx-post="{{uploadUrl}}" hx-swap="outerHTML"
hx-target="#media-container">
<input type="file" name="video" accept=".mov" required />
<button type="submit" class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out">Upload
Video</button>
</form>
</div>
{{/if}}
</div>
{{/if}}

0 comments on commit 053f720

Please sign in to comment.