diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-20 10:38:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-04-20 10:41:43 +0200 |
commit | 86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172 (patch) | |
tree | e939620851db2690b568cb4660f749cda125146f /server | |
parent | b1770a0af464ad6350d156245b1abcc1395e142e (diff) | |
download | PeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.tar.gz PeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.tar.zst PeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.zip |
Add licence and language support to y-dl imports
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/import.ts | 6 | ||||
-rw-r--r-- | server/helpers/youtube-dl.ts | 15 |
2 files changed, 16 insertions, 5 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index fb2de5dc0..be96ef42c 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -159,7 +159,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
159 | thumbnailModel = await processThumbnail(req, video) | 159 | thumbnailModel = await processThumbnail(req, video) |
160 | 160 | ||
161 | // Process video thumbnail from url if processing from request.files failed | 161 | // Process video thumbnail from url if processing from request.files failed |
162 | if (!thumbnailModel) { | 162 | if (!thumbnailModel && youtubeDLInfo.thumbnailUrl) { |
163 | thumbnailModel = await processThumbnailFromUrl(youtubeDLInfo.thumbnailUrl, video) | 163 | thumbnailModel = await processThumbnailFromUrl(youtubeDLInfo.thumbnailUrl, video) |
164 | } | 164 | } |
165 | 165 | ||
@@ -169,7 +169,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
169 | previewModel = await processPreview(req, video) | 169 | previewModel = await processPreview(req, video) |
170 | 170 | ||
171 | // Process video preview from url if processing from request.files failed | 171 | // Process video preview from url if processing from request.files failed |
172 | if (!previewModel) { | 172 | if (!previewModel && youtubeDLInfo.thumbnailUrl) { |
173 | previewModel = await processPreviewFromUrl(youtubeDLInfo.thumbnailUrl, video) | 173 | previewModel = await processPreviewFromUrl(youtubeDLInfo.thumbnailUrl, video) |
174 | } | 174 | } |
175 | 175 | ||
@@ -236,7 +236,7 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You | |||
236 | remote: false, | 236 | remote: false, |
237 | category: body.category || importData.category, | 237 | category: body.category || importData.category, |
238 | licence: body.licence || importData.licence, | 238 | licence: body.licence || importData.licence, |
239 | language: body.language || undefined, | 239 | language: body.language || importData.language, |
240 | commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true" | 240 | commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true" |
241 | downloadEnabled: body.downloadEnabled !== false, | 241 | downloadEnabled: body.downloadEnabled !== false, |
242 | waitTranscoding: body.waitTranscoding || false, | 242 | waitTranscoding: body.waitTranscoding || false, |
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index 6d2e6f6d1..f0944b94f 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants' | 1 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '../initializers/constants' |
2 | import { logger } from './logger' | 2 | import { logger } from './logger' |
3 | import { generateVideoImportTmpPath } from './utils' | 3 | import { generateVideoImportTmpPath } from './utils' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
@@ -12,6 +12,7 @@ export type YoutubeDLInfo = { | |||
12 | name?: string | 12 | name?: string |
13 | description?: string | 13 | description?: string |
14 | category?: number | 14 | category?: number |
15 | language?: string | ||
15 | licence?: number | 16 | licence?: number |
16 | nsfw?: boolean | 17 | nsfw?: boolean |
17 | tags?: string[] | 18 | tags?: string[] |
@@ -252,12 +253,13 @@ function normalizeObject (obj: any) { | |||
252 | return newObj | 253 | return newObj |
253 | } | 254 | } |
254 | 255 | ||
255 | function buildVideoInfo (obj: any) { | 256 | function buildVideoInfo (obj: any): YoutubeDLInfo { |
256 | return { | 257 | return { |
257 | name: titleTruncation(obj.title), | 258 | name: titleTruncation(obj.title), |
258 | description: descriptionTruncation(obj.description), | 259 | description: descriptionTruncation(obj.description), |
259 | category: getCategory(obj.categories), | 260 | category: getCategory(obj.categories), |
260 | licence: getLicence(obj.license), | 261 | licence: getLicence(obj.license), |
262 | language: getLanguage(obj.language), | ||
261 | nsfw: isNSFW(obj), | 263 | nsfw: isNSFW(obj), |
262 | tags: getTags(obj.tags), | 264 | tags: getTags(obj.tags), |
263 | thumbnailUrl: obj.thumbnail || undefined, | 265 | thumbnailUrl: obj.thumbnail || undefined, |
@@ -302,6 +304,11 @@ function getLicence (licence: string) { | |||
302 | 304 | ||
303 | if (licence.includes('Creative Commons Attribution')) return 1 | 305 | if (licence.includes('Creative Commons Attribution')) return 1 |
304 | 306 | ||
307 | for (const key of Object.keys(VIDEO_LICENCES)) { | ||
308 | const peertubeLicence = VIDEO_LICENCES[key] | ||
309 | if (peertubeLicence.toLowerCase() === licence.toLowerCase()) return parseInt(key, 10) | ||
310 | } | ||
311 | |||
305 | return undefined | 312 | return undefined |
306 | } | 313 | } |
307 | 314 | ||
@@ -321,6 +328,10 @@ function getCategory (categories: string[]) { | |||
321 | return undefined | 328 | return undefined |
322 | } | 329 | } |
323 | 330 | ||
331 | function getLanguage (language: string) { | ||
332 | return VIDEO_LANGUAGES[language] ? language : undefined | ||
333 | } | ||
334 | |||
324 | function wrapWithProxyOptions (options: string[]) { | 335 | function wrapWithProxyOptions (options: string[]) { |
325 | if (CONFIG.IMPORT.VIDEOS.HTTP.PROXY.ENABLED) { | 336 | if (CONFIG.IMPORT.VIDEOS.HTTP.PROXY.ENABLED) { |
326 | logger.debug('Using proxy for YoutubeDL') | 337 | logger.debug('Using proxy for YoutubeDL') |