Update:Podcast episode download show ffmpeg progress and print full debug log dump on error

This commit is contained in:
advplyr 2024-02-16 16:05:02 -06:00
parent 5b5613a762
commit 52323b7eb5
3 changed files with 22 additions and 13 deletions

View File

@ -336,7 +336,7 @@ class MeController {
}
/**
* GET: /api/stats/year/:year
* GET: /api/me/stats/year/:year
*
* @param {import('express').Request} req
* @param {import('express').Response} res

View File

@ -101,8 +101,8 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
})
if (!response) return resolve(false)
const ffmpeg = Ffmpeg(response.data)
ffmpeg.addOption('-loglevel debug') // Debug logs printed on error
ffmpeg.outputOptions(
'-c', 'copy',
'-metadata', 'podcast=1'
@ -110,6 +110,7 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
const podcastMetadata = podcastEpisodeDownload.libraryItem.media.metadata
const podcastEpisode = podcastEpisodeDownload.podcastEpisode
const finalSizeInBytes = Number(podcastEpisode.enclosure?.length || 0)
const taggings = {
'album': podcastMetadata.title,
@ -147,13 +148,30 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
ffmpeg.addOutput(podcastEpisodeDownload.targetPath)
const stderrLines = []
ffmpeg.on('stderr', (stderrLine) => {
if (typeof stderrLine === 'string') {
stderrLines.push(stderrLine)
}
})
ffmpeg.on('start', (cmd) => {
Logger.debug(`[FfmpegHelpers] downloadPodcastEpisode: Cmd: ${cmd}`)
})
ffmpeg.on('error', (err, stdout, stderr) => {
Logger.error(`[FfmpegHelpers] downloadPodcastEpisode: Error ${err} ${stdout} ${stderr}`)
ffmpeg.on('error', (err) => {
Logger.error(`[FfmpegHelpers] downloadPodcastEpisode: Error ${err}`)
if (stderrLines.length) {
Logger.error(`Full stderr dump for episode url "${podcastEpisodeDownload.url}": ${stderrLines.join('\n')}`)
}
resolve(false)
})
ffmpeg.on('progress', (progress) => {
let progressPercent = 0
if (finalSizeInBytes && progress.targetSize && !isNaN(progress.targetSize)) {
const finalSizeInKb = Math.floor(finalSizeInBytes / 1000)
progressPercent = Math.min(1, progress.targetSize / finalSizeInKb) * 100
}
Logger.debug(`[FfmpegHelpers] downloadPodcastEpisode: Progress estimate ${progressPercent.toFixed(0)}% (${progress?.targetSize || 'N/A'} KB) for "${podcastEpisodeDownload.url}"`)
})
ffmpeg.on('end', () => {
Logger.debug(`[FfmpegHelpers] downloadPodcastEpisode: Complete`)
resolve(podcastEpisodeDownload.targetPath)

View File

@ -1,9 +0,0 @@
const { parentPort } = require("worker_threads")
const prober = require('./prober')
parentPort.on("message", async ({ mediaPath }) => {
const results = await prober.probe(mediaPath)
parentPort.postMessage({
data: results,
})
})