Skip to content

Commit

Permalink
Stylistic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccacremona committed Nov 4, 2024
1 parent af9bc06 commit b50e332
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions Scoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,20 +1008,22 @@ export class Scoop {
}
}

if (metadataParsed.length) {
// Merge parsed metadata into a single JSON string and clean it before saving it
const metadataAsJSON = JSON
.stringify(metadataParsed, null, 2)
.replaceAll(this.captureTmpFolderPath, '')

const url = 'file:///video-extracted-metadata.json'
const httpHeaders = new Headers({ 'content-type': 'application/json' })
const body = Buffer.from(metadataAsJSON)
const isEntryPoint = false

this.addGeneratedExchange(url, httpHeaders, body, isEntryPoint)
metadataSaved = true
if (!metadataParsed.length) {
throw new Error('yt-dlp reported success (returned 0) but produced no metadata.')
}

// Merge parsed metadata into a single JSON string and clean it before saving it
const metadataAsJSON = JSON
.stringify(metadataParsed, null, 2)
.replaceAll(this.captureTmpFolderPath, '')

const url = 'file:///video-extracted-metadata.json'
const httpHeaders = new Headers({ 'content-type': 'application/json' })
const body = Buffer.from(metadataAsJSON)
const isEntryPoint = false

this.addGeneratedExchange(url, httpHeaders, body, isEntryPoint)
metadataSaved = true
} catch (err) {
this.log.warn('Error while creating exchange for file:///video-extracted-medatadata.json.')
this.log.trace(err)
Expand All @@ -1030,31 +1032,31 @@ export class Scoop {
//
// Generate summary page
//
if (videoSaved || metadataSaved || subtitlesSaved) {
try {
const html = nunjucks.render('video-extracted-summary.njk', {
url: this.url,
now: new Date().toISOString(),
videoSaved,
metadataSaved,
subtitlesSaved,
availableVideosAndSubtitles,
metadataParsed
})

const url = 'file:///video-extracted-summary.html'
const httpHeaders = new Headers({ 'content-type': 'text/html' })
const body = Buffer.from(html)
const isEntryPoint = true
const description = `Extracted Video data from: ${this.url}`

this.addGeneratedExchange(url, httpHeaders, body, isEntryPoint, description)
} catch (err) {
this.log.warn('Error while creating exchange for file:///video-extracted-summary.html.')
this.log.trace(err)
}
} else {
this.log.debug('Skipping creation of file:///video-extracted-summary.html; yt-dlp silently failed to produce output.')
if ((videoSaved || metadataSaved || subtitlesSaved) === false) {
this.log.warn('yt-dlp reported success (returned 0), but produced no output.')
return
}
try {
const html = nunjucks.render('video-extracted-summary.njk', {
url: this.url,
now: new Date().toISOString(),
videoSaved,
metadataSaved,
subtitlesSaved,
availableVideosAndSubtitles,
metadataParsed
})

const url = 'file:///video-extracted-summary.html'
const httpHeaders = new Headers({ 'content-type': 'text/html' })
const body = Buffer.from(html)
const isEntryPoint = true
const description = `Extracted Video data from: ${this.url}`

this.addGeneratedExchange(url, httpHeaders, body, isEntryPoint, description)
} catch (err) {
this.log.warn('Error while creating exchange for file:///video-extracted-summary.html.')
this.log.trace(err)
}
}

Expand Down

0 comments on commit b50e332

Please sign in to comment.