From d57d1d83c6a4d98a735b21f4e8e749a5c1e1a479 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Apr 2020 15:41:39 +0200 Subject: Support audio files import --- server/helpers/utils.ts | 14 +++++++++++--- server/helpers/youtube-dl.ts | 10 ++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 7a4c781cc..11c118292 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -7,6 +7,7 @@ import { Instance as ParseTorrent } from 'parse-torrent' import { remove } from 'fs-extra' import * as memoizee from 'memoizee' import { CONFIG } from '../initializers/config' +import { isVideoFileExtnameValid } from './custom-validators/videos' function deleteFileAsync (path: string) { remove(path) @@ -42,11 +43,18 @@ const getServerActor = memoizee(async function () { return actor }, { promise: true }) -function generateVideoImportTmpPath (target: string | ParseTorrent) { - const id = typeof target === 'string' ? target : target.infoHash +function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { + const id = typeof target === 'string' + ? target + : target.infoHash + + let extension = '.mp4' + if (extensionArg && isVideoFileExtnameValid(extensionArg)) { + extension = extensionArg + } const hash = sha256(id) - return join(CONFIG.STORAGE.TMP_DIR, hash + '-import.mp4') + return join(CONFIG.STORAGE.TMP_DIR, `${hash}-import${extension}`) } function getSecureTorrentName (originalName: string) { diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index 26dbe6543..07c85797a 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts @@ -16,6 +16,7 @@ export type YoutubeDLInfo = { nsfw?: boolean tags?: string[] thumbnailUrl?: string + fileExt?: string originallyPublishedAt?: Date } @@ -44,11 +45,11 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise }) } -function downloadYoutubeDLVideo (url: string, timeout: number) { - const path = generateVideoImportTmpPath(url) +function downloadYoutubeDLVideo (url: string, extension: string, timeout: number) { + const path = generateVideoImportTmpPath(url, extension) let timer - logger.info('Importing youtubeDL video %s', url) + logger.info('Importing youtubeDL video %s to %s', url, path) let options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] options = wrapWithProxyOptions(options) @@ -219,7 +220,8 @@ function buildVideoInfo (obj: any) { nsfw: isNSFW(obj), tags: getTags(obj.tags), thumbnailUrl: obj.thumbnail || undefined, - originallyPublishedAt: buildOriginallyPublishedAt(obj) + originallyPublishedAt: buildOriginallyPublishedAt(obj), + fileExt: obj.ext } } -- cgit v1.2.3