Skip to content

Commit

Permalink
add build audio button
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Oct 22, 2024
1 parent 44b3f54 commit 2a92645
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
.idea
.tmp
.DS_Store
.tmp
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { uploadVideoController } from './routers/admin/detail/file.js';

import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { media } from './routers/admin/detail/mediaMontage.js';

function registerViewFunctions() {
Handlebars.registerHelper('eq', (a, b) => a === b);
Expand Down Expand Up @@ -53,6 +54,7 @@ const init = async () => {
editPodcastDetails(server);
rss(server);
uploadVideoController(server);
media(server);

await server.start();
console.log('Server running on %s', server.info.uri);
Expand Down
12 changes: 7 additions & 5 deletions src/minio/ffmpegApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export async function applyFFmpegToFileInMinio(inputKey, outputKey, ffmpegComman

// Wrap the child process in a promise
await new Promise((resolve, reject) => {
const child = spawn(ffmpegPath, [
'-i', `${folder}/${inputKey}`,
'-filter_complex', ffmpegCommand,
output,
]);
const commandArray = ['-i', `${folder}/${inputKey}`];
if (ffmpegCommand) {
commandArray.push('-filter_complex', ffmpegCommand);
}
commandArray.push(output);
console.log('commandArray', commandArray);
const child = spawn(ffmpegPath, commandArray);

child.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
Expand Down
4 changes: 3 additions & 1 deletion src/routers/admin/detail/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function uploadVideo(request, h) {
const file = data.video;
console.log(file);

const uploadDir = `uploads/`;
const uploadDir = `.tmp/uploads/`;
fs.mkdirSync(uploadDir, { recursive: true });

if (!fs.existsSync(uploadDir)) {
Expand All @@ -56,6 +56,8 @@ async function uploadVideo(request, h) {
return h.view(
'media_component',
{
showSlug: showSlug,
episodeSlug: episodeSlug,
showAudio: false,
showVideo: true,
videoUrl: `${startUrl}/${s3FileKey}`,
Expand Down
3 changes: 3 additions & 0 deletions src/routers/admin/detail/getDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ async function getPodcastDetails(request, h) {
}
}

media.showSlug = showSlug;
media.episodeSlug = episodeSlug;

return h.view(
'admin/admin_podcast_detail',
{
Expand Down
23 changes: 23 additions & 0 deletions src/routers/admin/detail/mediaMontage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getPostBySlug } from "../../../core/episodeRepo.js";
import { applyFFmpegToFileInMinio } from "../../../minio/ffmpegApply.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);
console.log('Building audio for episode', showSlug, episodeSlug);

}

export function media(server) {
server.route({
method: 'POST',
path: '/admin/show/{showSlug}/episode/{episodeSlug}/buildAudio',
handler: buildAudio,
options: {
auth: 'adminSession',
}
});
}
13 changes: 9 additions & 4 deletions src/templates/widgets/media_component.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{{#if showAudio}}
<div class="w-full sm:p-0 sm:m-0 mx-auto-2 lg:px-0">
{{#if showAudio}}
<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>
{{/if}}
</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}}

{{#if showVideo}}
<div class="w-full">
{{#if showVideo}}
<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>
{{/if}}
</div>
{{/if}}

{{#if showUploadVideoButton}}
<div class="w-full">
Expand Down

0 comments on commit 2a92645

Please sign in to comment.