From: Chocobozzz Date: Tue, 21 Jan 2020 14:59:57 +0000 (+0100) Subject: Use a proxy for youtube-dl to avoid travis errors X-Git-Tag: v2.1.0-rc.1~16 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=be7ca0c6b9c51c639bac7d2da94599893e7b1c01;p=oweals%2Fpeertube.git Use a proxy for youtube-dl to avoid travis errors --- diff --git a/config/default.yaml b/config/default.yaml index ce2b20c75..3260c62fc 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -234,6 +234,10 @@ import: videos: http: # Classic HTTP or all sites supported by youtube-dl https://rg3.github.io/youtube-dl/supportedsites.html enabled: false + # You can use an HTTP/HTTPS/SOCKS proxy with youtube-dl + proxy: + enabled: false + url: "" torrent: # Magnet URI or torrent file (use classic TCP/UDP/WebSeed to download the file) enabled: false diff --git a/config/production.yaml.example b/config/production.yaml.example index 52892acfb..30cd2ffe0 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -248,6 +248,10 @@ import: videos: http: # Classic HTTP or all sites supported by youtube-dl https://rg3.github.io/youtube-dl/supportedsites.html enabled: false + # You can use an HTTP/HTTPS/SOCKS proxy with youtube-dl + proxy: + enabled: false + url: "" torrent: # Magnet URI or torrent file (use classic TCP/UDP/WebSeed to download the file) enabled: false diff --git a/config/test.yaml b/config/test.yaml index 3ab391504..5d98b41c4 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -86,6 +86,9 @@ import: videos: http: enabled: true + proxy: + enabled: false + url: "" torrent: enabled: true diff --git a/scripts/ci.sh b/scripts/ci.sh index 270a2b5bc..7b5c3f2bb 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -9,6 +9,8 @@ fi killall -q peertube || true +perl -0777 -i -pe 's#(proxy:\n\s+enabled: false\n\s+)url: ""#$1url: "'"$PROXY_URL"'"#' config/test.yaml + if [ "$1" = "misc" ]; then npm run build -- --light-fr mocha --timeout 5000 --exit --require ts-node/register --require tsconfig-paths/register --bail server/tests/client.ts \ @@ -40,3 +42,5 @@ elif [ "$1" = "lint" ]; then npm run lint ) fi + +git checkout -- config/test.yaml diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index 87a0d0584..d17c9d554 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts @@ -6,6 +6,7 @@ import { peertubeTruncate, root } from './core-utils' import { ensureDir, remove, writeFile } from 'fs-extra' import * as request from 'request' import { createWriteStream } from 'fs' +import { CONFIG } from '@server/initializers/config' export type YoutubeDLInfo = { name?: string @@ -45,11 +46,16 @@ function downloadYoutubeDLVideo (url: string, timeout: number) { logger.info('Importing youtubeDL video %s', url) - const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] + let options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] + + if (CONFIG.IMPORT.VIDEOS.HTTP.PROXY.ENABLED) { + logger.debug('Using proxy for YoutubeDL') + + options = [ '--proxy', CONFIG.IMPORT.VIDEOS.HTTP.PROXY.URL ].concat(options) + } if (process.env.FFMPEG_PATH) { - options.push('--ffmpeg-location') - options.push(process.env.FFMPEG_PATH) + options = options.concat([ '--ffmpeg-location', process.env.FFMPEG_PATH ]) } return new Promise(async (res, rej) => { diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 95b069533..7fd77f3e8 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -191,7 +191,11 @@ const CONFIG = { IMPORT: { VIDEOS: { HTTP: { - get ENABLED () { return config.get('import.videos.http.enabled') } + get ENABLED () { return config.get('import.videos.http.enabled') }, + PROXY: { + get ENABLED () { return config.get('import.videos.http.proxy.enabled') }, + get URL () { return config.get('import.videos.http.proxy.url') } + } }, TORRENT: { get ENABLED () { return config.get('import.videos.torrent.enabled') }