diff options
Diffstat (limited to 'server/helpers/youtube-dl.ts')
-rw-r--r-- | server/helpers/youtube-dl.ts | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index b74351b42..b3079370f 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { truncate } from 'lodash' | 1 | import { truncate } from 'lodash' |
2 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers' | 2 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants' |
3 | import { logger } from './logger' | 3 | import { logger } from './logger' |
4 | import { generateVideoImportTmpPath } from './utils' | 4 | import { generateVideoImportTmpPath } from './utils' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
@@ -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 | originallyPublishedAt?: Date | ||
19 | } | 20 | } |
20 | 21 | ||
21 | const processOptions = { | 22 | const processOptions = { |
@@ -47,6 +48,11 @@ function downloadYoutubeDLVideo (url: string, timeout: number) { | |||
47 | 48 | ||
48 | const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] | 49 | const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] |
49 | 50 | ||
51 | if (process.env.FFMPEG_PATH) { | ||
52 | options.push('--ffmpeg-location') | ||
53 | options.push(process.env.FFMPEG_PATH) | ||
54 | } | ||
55 | |||
50 | return new Promise<string>(async (res, rej) => { | 56 | return new Promise<string>(async (res, rej) => { |
51 | const youtubeDL = await safeGetYoutubeDL() | 57 | const youtubeDL = await safeGetYoutubeDL() |
52 | youtubeDL.exec(url, options, processOptions, err => { | 58 | youtubeDL.exec(url, options, processOptions, err => { |
@@ -142,13 +148,33 @@ async function safeGetYoutubeDL () { | |||
142 | return youtubeDL | 148 | return youtubeDL |
143 | } | 149 | } |
144 | 150 | ||
151 | function buildOriginallyPublishedAt (obj: any) { | ||
152 | let originallyPublishedAt: Date = null | ||
153 | |||
154 | const uploadDateMatcher = /^(\d{4})(\d{2})(\d{2})$/.exec(obj.upload_date) | ||
155 | if (uploadDateMatcher) { | ||
156 | originallyPublishedAt = new Date() | ||
157 | originallyPublishedAt.setHours(0, 0, 0, 0) | ||
158 | |||
159 | const year = parseInt(uploadDateMatcher[1], 10) | ||
160 | // Month starts from 0 | ||
161 | const month = parseInt(uploadDateMatcher[2], 10) - 1 | ||
162 | const day = parseInt(uploadDateMatcher[3], 10) | ||
163 | |||
164 | originallyPublishedAt.setFullYear(year, month, day) | ||
165 | } | ||
166 | |||
167 | return originallyPublishedAt | ||
168 | } | ||
169 | |||
145 | // --------------------------------------------------------------------------- | 170 | // --------------------------------------------------------------------------- |
146 | 171 | ||
147 | export { | 172 | export { |
148 | updateYoutubeDLBinary, | 173 | updateYoutubeDLBinary, |
149 | downloadYoutubeDLVideo, | 174 | downloadYoutubeDLVideo, |
150 | getYoutubeDLInfo, | 175 | getYoutubeDLInfo, |
151 | safeGetYoutubeDL | 176 | safeGetYoutubeDL, |
177 | buildOriginallyPublishedAt | ||
152 | } | 178 | } |
153 | 179 | ||
154 | // --------------------------------------------------------------------------- | 180 | // --------------------------------------------------------------------------- |
@@ -180,7 +206,8 @@ function buildVideoInfo (obj: any) { | |||
180 | licence: getLicence(obj.license), | 206 | licence: getLicence(obj.license), |
181 | nsfw: isNSFW(obj), | 207 | nsfw: isNSFW(obj), |
182 | tags: getTags(obj.tags), | 208 | tags: getTags(obj.tags), |
183 | thumbnailUrl: obj.thumbnail || undefined | 209 | thumbnailUrl: obj.thumbnail || undefined, |
210 | originallyPublishedAt: buildOriginallyPublishedAt(obj) | ||
184 | } | 211 | } |
185 | } | 212 | } |
186 | 213 | ||