X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fyoutube-dl%2Fyoutube-dl-wrapper.ts;h=966b8df78e096a6d96df3e76cdc67a800a8ecdf3;hb=4638cd713dcdd007cd7f49b9a95fa62ac7823e7c;hp=176cf3b6995ef977e068aa070ba9ea15be8f61cb;hpb=5e2afe4290103bf0d54ae7b3e62781f2a00487c9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/helpers/youtube-dl/youtube-dl-wrapper.ts index 176cf3b69..966b8df78 100644 --- a/server/helpers/youtube-dl/youtube-dl-wrapper.ts +++ b/server/helpers/youtube-dl/youtube-dl-wrapper.ts @@ -1,5 +1,6 @@ import { move, pathExists, readdir, remove } from 'fs-extra' import { dirname, join } from 'path' +import { inspect } from 'util' import { CONFIG } from '@server/initializers/config' import { isVideoFileExtnameValid } from '../custom-validators/videos' import { logger, loggerTagsFactory } from '../logger' @@ -39,6 +40,8 @@ class YoutubeDLWrapper { processOptions }) + if (!info) throw new Error(`YoutubeDL could not get info from ${this.url}`) + if (info.is_live === true) throw new Error('Cannot download a live streaming.') const infoBuilder = new YoutubeDLInfoBuilder(info) @@ -46,6 +49,22 @@ class YoutubeDLWrapper { return infoBuilder.getInfo() } + async getInfoForListImport (options: { + latestVideosCount?: number + }) { + const youtubeDL = await YoutubeDLCLI.safeGet() + + const list = await youtubeDL.getListInfo({ + url: this.url, + latestVideosCount: options.latestVideosCount, + processOptions + }) + + if (!Array.isArray(list)) throw new Error(`YoutubeDL could not get list info from ${this.url}: ${inspect(list)}`) + + return list.map(info => info.webpage_url) + } + async getSubtitles (): Promise { const cwd = CONFIG.STORAGE.TMP_DIR @@ -103,7 +122,7 @@ class YoutubeDLWrapper { return remove(path) }) - .catch(innerErr => logger.error('Cannot remove file in youtubeDL timeout.', { innerErr, ...lTags() })) + .catch(innerErr => logger.error('Cannot remove file in youtubeDL error.', { innerErr, ...lTags() })) throw err }