diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/utils.ts | 14 | ||||
-rw-r--r-- | server/helpers/youtube-dl.ts | 10 |
2 files changed, 17 insertions, 7 deletions
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' | |||
7 | import { remove } from 'fs-extra' | 7 | import { remove } from 'fs-extra' |
8 | import * as memoizee from 'memoizee' | 8 | import * as memoizee from 'memoizee' |
9 | import { CONFIG } from '../initializers/config' | 9 | import { CONFIG } from '../initializers/config' |
10 | import { isVideoFileExtnameValid } from './custom-validators/videos' | ||
10 | 11 | ||
11 | function deleteFileAsync (path: string) { | 12 | function deleteFileAsync (path: string) { |
12 | remove(path) | 13 | remove(path) |
@@ -42,11 +43,18 @@ const getServerActor = memoizee(async function () { | |||
42 | return actor | 43 | return actor |
43 | }, { promise: true }) | 44 | }, { promise: true }) |
44 | 45 | ||
45 | function generateVideoImportTmpPath (target: string | ParseTorrent) { | 46 | function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { |
46 | const id = typeof target === 'string' ? target : target.infoHash | 47 | const id = typeof target === 'string' |
48 | ? target | ||
49 | : target.infoHash | ||
50 | |||
51 | let extension = '.mp4' | ||
52 | if (extensionArg && isVideoFileExtnameValid(extensionArg)) { | ||
53 | extension = extensionArg | ||
54 | } | ||
47 | 55 | ||
48 | const hash = sha256(id) | 56 | const hash = sha256(id) |
49 | return join(CONFIG.STORAGE.TMP_DIR, hash + '-import.mp4') | 57 | return join(CONFIG.STORAGE.TMP_DIR, `${hash}-import${extension}`) |
50 | } | 58 | } |
51 | 59 | ||
52 | function getSecureTorrentName (originalName: string) { | 60 | 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 = { | |||
16 | nsfw?: boolean | 16 | nsfw?: boolean |
17 | tags?: string[] | 17 | tags?: string[] |
18 | thumbnailUrl?: string | 18 | thumbnailUrl?: string |
19 | fileExt?: string | ||
19 | originallyPublishedAt?: Date | 20 | originallyPublishedAt?: Date |
20 | } | 21 | } |
21 | 22 | ||
@@ -44,11 +45,11 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise<YoutubeDLInfo> | |||
44 | }) | 45 | }) |
45 | } | 46 | } |
46 | 47 | ||
47 | function downloadYoutubeDLVideo (url: string, timeout: number) { | 48 | function downloadYoutubeDLVideo (url: string, extension: string, timeout: number) { |
48 | const path = generateVideoImportTmpPath(url) | 49 | const path = generateVideoImportTmpPath(url, extension) |
49 | let timer | 50 | let timer |
50 | 51 | ||
51 | logger.info('Importing youtubeDL video %s', url) | 52 | logger.info('Importing youtubeDL video %s to %s', url, path) |
52 | 53 | ||
53 | let options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] | 54 | let options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] |
54 | options = wrapWithProxyOptions(options) | 55 | options = wrapWithProxyOptions(options) |
@@ -219,7 +220,8 @@ function buildVideoInfo (obj: any) { | |||
219 | nsfw: isNSFW(obj), | 220 | nsfw: isNSFW(obj), |
220 | tags: getTags(obj.tags), | 221 | tags: getTags(obj.tags), |
221 | thumbnailUrl: obj.thumbnail || undefined, | 222 | thumbnailUrl: obj.thumbnail || undefined, |
222 | originallyPublishedAt: buildOriginallyPublishedAt(obj) | 223 | originallyPublishedAt: buildOriginallyPublishedAt(obj), |
224 | fileExt: obj.ext | ||
223 | } | 225 | } |
224 | } | 226 | } |
225 | 227 | ||