aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/youtube-dl.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-20 10:38:33 +0200
committerChocobozzz <me@florianbigard.com>2020-04-20 10:41:43 +0200
commit86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172 (patch)
treee939620851db2690b568cb4660f749cda125146f /server/helpers/youtube-dl.ts
parentb1770a0af464ad6350d156245b1abcc1395e142e (diff)
downloadPeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.tar.gz
PeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.tar.zst
PeerTube-86ad0cde9e7e7cbe86dfd7642c9d9b807e17c172.zip
Add licence and language support to y-dl imports
Diffstat (limited to 'server/helpers/youtube-dl.ts')
-rw-r--r--server/helpers/youtube-dl.ts15
1 files changed, 13 insertions, 2 deletions
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 @@
1import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants' 1import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '../initializers/constants'
2import { logger } from './logger' 2import { logger } from './logger'
3import { generateVideoImportTmpPath } from './utils' 3import { generateVideoImportTmpPath } from './utils'
4import { join } from 'path' 4import { 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
255function buildVideoInfo (obj: any) { 256function 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
331function getLanguage (language: string) {
332 return VIDEO_LANGUAGES[language] ? language : undefined
333}
334
324function wrapWithProxyOptions (options: string[]) { 335function 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')