Browse Source

Fix CLI import script

pull/3326/head
Chocobozzz 1 week ago
parent
commit
de29e90c37
No known key found for this signature in database GPG Key ID: 583A612D890159BE
1 changed files with 41 additions and 29 deletions
  1. +41
    -29
      server/tools/peertube-import-videos.ts

+ 41
- 29
server/tools/peertube-import-videos.ts View File

@@ -72,42 +72,42 @@ async function run (url: string, user: UserInfo) {

const youtubeDL = await safeGetYoutubeDL()

const options = [ '-j', '--flat-playlist', '--playlist-reverse', ...command.args ]
let info = await getYoutubeDLInfo(youtubeDL, program['targetUrl'], command.args)

youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => {
if (err) {
exitError(err.stderr + ' ' + err.message)
}
if (info?.title === 'Uploads') {
console.log('Fixing URL to %s.', info.url)

let infoArray: any[]
info = await getYoutubeDLInfo(youtubeDL, info.url, command.args)
}

// Normalize utf8 fields
infoArray = [].concat(info)
if (program['first']) {
infoArray = infoArray.slice(0, program['first'])
} else if (program['last']) {
infoArray = infoArray.slice(-program['last'])
}
infoArray = infoArray.map(i => normalizeObject(i))
let infoArray: any[]

log.info('Will download and upload %d videos.\n', infoArray.length)
// Normalize utf8 fields
infoArray = [].concat(info)
if (program['first']) {
infoArray = infoArray.slice(0, program['first'])
} else if (program['last']) {
infoArray = infoArray.slice(-program['last'])
}
infoArray = infoArray.map(i => normalizeObject(i))

for (const info of infoArray) {
try {
await processVideo({
cwd: program['tmpdir'],
url,
user,
youtubeInfo: info
})
} catch (err) {
console.error('Cannot process video.', { info, url })
}
log.info('Will download and upload %d videos.\n', infoArray.length)

for (const info of infoArray) {
try {
await processVideo({
cwd: program['tmpdir'],
url,
user,
youtubeInfo: info
})
} catch (err) {
console.error('Cannot process video.', { info, url })
}
}

log.info('Video/s for user %s imported: %s', user.username, program['targetUrl'])
process.exit(0)
})
log.info('Video/s for user %s imported: %s', user.username, program['targetUrl'])
process.exit(0)
}

function processVideo (parameters: {
@@ -397,3 +397,15 @@ function exitError (message: string, ...meta: any[]) {
console.error(message, ...meta)
process.exit(-1)
}

function getYoutubeDLInfo (youtubeDL: any, url: string, args: string[]) {
return new Promise<any>((res, rej) => {
const options = [ '-j', '--flat-playlist', '--playlist-reverse', ...args ]

youtubeDL.getInfo(url, options, processOptions, async (err, info) => {
if (err) return rej(err)

return res(info)
})
})
}

Loading…
Cancel
Save