aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/youtube-dl
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-05 15:05:20 +0200
committerChocobozzz <me@florianbigard.com>2022-08-09 09:18:07 +0200
commit5e2afe4290103bf0d54ae7b3e62781f2a00487c9 (patch)
tree84e084135c60d208fc9afcee63180d3200f763e6 /server/helpers/youtube-dl
parent64fd6158fd276f258bcfc4bb0c8fc2f64a220a11 (diff)
downloadPeerTube-5e2afe4290103bf0d54ae7b3e62781f2a00487c9.tar.gz
PeerTube-5e2afe4290103bf0d54ae7b3e62781f2a00487c9.tar.zst
PeerTube-5e2afe4290103bf0d54ae7b3e62781f2a00487c9.zip
Limit import depending on transcoding resolutions
Diffstat (limited to 'server/helpers/youtube-dl')
-rw-r--r--server/helpers/youtube-dl/youtube-dl-cli.ts30
-rw-r--r--server/helpers/youtube-dl/youtube-dl-wrapper.ts10
2 files changed, 26 insertions, 14 deletions
diff --git a/server/helpers/youtube-dl/youtube-dl-cli.ts b/server/helpers/youtube-dl/youtube-dl-cli.ts
index 728f096b5..13c990a1e 100644
--- a/server/helpers/youtube-dl/youtube-dl-cli.ts
+++ b/server/helpers/youtube-dl/youtube-dl-cli.ts
@@ -57,7 +57,7 @@ export class YoutubeDLCLI {
57 } 57 }
58 } 58 }
59 59
60 static getYoutubeDLVideoFormat (enabledResolutions: VideoResolution[]) { 60 static getYoutubeDLVideoFormat (enabledResolutions: VideoResolution[], useBestFormat: boolean) {
61 /** 61 /**
62 * list of format selectors in order or preference 62 * list of format selectors in order or preference
63 * see https://github.com/ytdl-org/youtube-dl#format-selection 63 * see https://github.com/ytdl-org/youtube-dl#format-selection
@@ -69,18 +69,26 @@ export class YoutubeDLCLI {
69 * 69 *
70 * in any case we avoid AV1, see https://github.com/Chocobozzz/PeerTube/issues/3499 70 * in any case we avoid AV1, see https://github.com/Chocobozzz/PeerTube/issues/3499
71 **/ 71 **/
72 const resolution = enabledResolutions.length === 0 72
73 ? VideoResolution.H_720P 73 let result: string[] = []
74 : Math.max(...enabledResolutions) 74
75 75 if (!useBestFormat) {
76 return [ 76 const resolution = enabledResolutions.length === 0
77 `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1 77 ? VideoResolution.H_720P
78 `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2 78 : Math.max(...enabledResolutions)
79 `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]`, // case #3 79
80 `bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio`, 80 result = [
81 `bestvideo[vcodec^=avc1][height=${resolution}]+bestaudio[ext=m4a]`, // case #1
82 `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2
83 `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]` // case #
84 ]
85 }
86
87 return result.concat([
88 'bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio',
81 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats 89 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats
82 'best' // Ultimate fallback 90 'best' // Ultimate fallback
83 ].join('/') 91 ]).join('/')
84 } 92 }
85 93
86 private constructor () { 94 private constructor () {
diff --git a/server/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/helpers/youtube-dl/youtube-dl-wrapper.ts
index d585e9a95..176cf3b69 100644
--- a/server/helpers/youtube-dl/youtube-dl-wrapper.ts
+++ b/server/helpers/youtube-dl/youtube-dl-wrapper.ts
@@ -21,7 +21,11 @@ const processOptions = {
21 21
22class YoutubeDLWrapper { 22class YoutubeDLWrapper {
23 23
24 constructor (private readonly url: string = '', private readonly enabledResolutions: number[] = []) { 24 constructor (
25 private readonly url: string,
26 private readonly enabledResolutions: number[],
27 private readonly useBestFormat: boolean
28 ) {
25 29
26 } 30 }
27 31
@@ -30,7 +34,7 @@ class YoutubeDLWrapper {
30 34
31 const info = await youtubeDL.getInfo({ 35 const info = await youtubeDL.getInfo({
32 url: this.url, 36 url: this.url,
33 format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions), 37 format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions, this.useBestFormat),
34 additionalYoutubeDLArgs: youtubeDLArgs, 38 additionalYoutubeDLArgs: youtubeDLArgs,
35 processOptions 39 processOptions
36 }) 40 })
@@ -80,7 +84,7 @@ class YoutubeDLWrapper {
80 try { 84 try {
81 await youtubeDL.download({ 85 await youtubeDL.download({
82 url: this.url, 86 url: this.url,
83 format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions), 87 format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions, this.useBestFormat),
84 output: pathWithoutExtension, 88 output: pathWithoutExtension,
85 timeout, 89 timeout,
86 processOptions 90 processOptions