diff options
Diffstat (limited to 'server/helpers/youtube-dl')
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-cli.ts | 27 | ||||
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-info-builder.ts | 4 | ||||
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-wrapper.ts | 20 |
3 files changed, 47 insertions, 4 deletions
diff --git a/server/helpers/youtube-dl/youtube-dl-cli.ts b/server/helpers/youtube-dl/youtube-dl-cli.ts index 13c990a1e..5a87b99b4 100644 --- a/server/helpers/youtube-dl/youtube-dl-cli.ts +++ b/server/helpers/youtube-dl/youtube-dl-cli.ts | |||
@@ -87,6 +87,7 @@ export class YoutubeDLCLI { | |||
87 | return result.concat([ | 87 | return result.concat([ |
88 | 'bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio', | 88 | 'bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio', |
89 | 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats | 89 | 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats |
90 | 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', | ||
90 | 'best' // Ultimate fallback | 91 | 'best' // Ultimate fallback |
91 | ]).join('/') | 92 | ]).join('/') |
92 | } | 93 | } |
@@ -103,11 +104,14 @@ export class YoutubeDLCLI { | |||
103 | timeout?: number | 104 | timeout?: number |
104 | additionalYoutubeDLArgs?: string[] | 105 | additionalYoutubeDLArgs?: string[] |
105 | }) { | 106 | }) { |
107 | let args = options.additionalYoutubeDLArgs || [] | ||
108 | args = args.concat([ '--merge-output-format', 'mp4', '-f', options.format, '-o', options.output ]) | ||
109 | |||
106 | return this.run({ | 110 | return this.run({ |
107 | url: options.url, | 111 | url: options.url, |
108 | processOptions: options.processOptions, | 112 | processOptions: options.processOptions, |
109 | timeout: options.timeout, | 113 | timeout: options.timeout, |
110 | args: (options.additionalYoutubeDLArgs || []).concat([ '-f', options.format, '-o', options.output ]) | 114 | args |
111 | }) | 115 | }) |
112 | } | 116 | } |
113 | 117 | ||
@@ -129,6 +133,25 @@ export class YoutubeDLCLI { | |||
129 | : info | 133 | : info |
130 | } | 134 | } |
131 | 135 | ||
136 | getListInfo (options: { | ||
137 | url: string | ||
138 | latestVideosCount?: number | ||
139 | processOptions: execa.NodeOptions | ||
140 | }): Promise<{ upload_date: string, webpage_url: string }[]> { | ||
141 | const additionalYoutubeDLArgs = [ '--skip-download', '--playlist-reverse' ] | ||
142 | |||
143 | if (options.latestVideosCount !== undefined) { | ||
144 | additionalYoutubeDLArgs.push('--playlist-end', options.latestVideosCount.toString()) | ||
145 | } | ||
146 | |||
147 | return this.getInfo({ | ||
148 | url: options.url, | ||
149 | format: YoutubeDLCLI.getYoutubeDLVideoFormat([], false), | ||
150 | processOptions: options.processOptions, | ||
151 | additionalYoutubeDLArgs | ||
152 | }) | ||
153 | } | ||
154 | |||
132 | async getSubs (options: { | 155 | async getSubs (options: { |
133 | url: string | 156 | url: string |
134 | format: 'vtt' | 157 | format: 'vtt' |
@@ -175,7 +198,7 @@ export class YoutubeDLCLI { | |||
175 | 198 | ||
176 | const output = await subProcess | 199 | const output = await subProcess |
177 | 200 | ||
178 | logger.debug('Runned youtube-dl command.', { command: output.command, ...lTags() }) | 201 | logger.debug('Run youtube-dl command.', { command: output.command, ...lTags() }) |
179 | 202 | ||
180 | return output.stdout | 203 | return output.stdout |
181 | ? output.stdout.trim().split(/\r?\n/) | 204 | ? output.stdout.trim().split(/\r?\n/) |
diff --git a/server/helpers/youtube-dl/youtube-dl-info-builder.ts b/server/helpers/youtube-dl/youtube-dl-info-builder.ts index 71572f292..303e4051f 100644 --- a/server/helpers/youtube-dl/youtube-dl-info-builder.ts +++ b/server/helpers/youtube-dl/youtube-dl-info-builder.ts | |||
@@ -13,6 +13,7 @@ type YoutubeDLInfo = { | |||
13 | thumbnailUrl?: string | 13 | thumbnailUrl?: string |
14 | ext?: string | 14 | ext?: string |
15 | originallyPublishedAt?: Date | 15 | originallyPublishedAt?: Date |
16 | webpageUrl?: string | ||
16 | 17 | ||
17 | urls?: string[] | 18 | urls?: string[] |
18 | } | 19 | } |
@@ -81,7 +82,8 @@ class YoutubeDLInfoBuilder { | |||
81 | thumbnailUrl: obj.thumbnail || undefined, | 82 | thumbnailUrl: obj.thumbnail || undefined, |
82 | urls: this.buildAvailableUrl(obj), | 83 | urls: this.buildAvailableUrl(obj), |
83 | originallyPublishedAt: this.buildOriginallyPublishedAt(obj), | 84 | originallyPublishedAt: this.buildOriginallyPublishedAt(obj), |
84 | ext: obj.ext | 85 | ext: obj.ext, |
86 | webpageUrl: obj.webpage_url | ||
85 | } | 87 | } |
86 | } | 88 | } |
87 | 89 | ||
diff --git a/server/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/helpers/youtube-dl/youtube-dl-wrapper.ts index 176cf3b69..7cd5e3310 100644 --- a/server/helpers/youtube-dl/youtube-dl-wrapper.ts +++ b/server/helpers/youtube-dl/youtube-dl-wrapper.ts | |||
@@ -46,6 +46,24 @@ class YoutubeDLWrapper { | |||
46 | return infoBuilder.getInfo() | 46 | return infoBuilder.getInfo() |
47 | } | 47 | } |
48 | 48 | ||
49 | async getInfoForListImport (options: { | ||
50 | latestVideosCount?: number | ||
51 | }) { | ||
52 | const youtubeDL = await YoutubeDLCLI.safeGet() | ||
53 | |||
54 | const list = await youtubeDL.getListInfo({ | ||
55 | url: this.url, | ||
56 | latestVideosCount: options.latestVideosCount, | ||
57 | processOptions | ||
58 | }) | ||
59 | |||
60 | return list.map(info => { | ||
61 | const infoBuilder = new YoutubeDLInfoBuilder(info) | ||
62 | |||
63 | return infoBuilder.getInfo() | ||
64 | }) | ||
65 | } | ||
66 | |||
49 | async getSubtitles (): Promise<YoutubeDLSubs> { | 67 | async getSubtitles (): Promise<YoutubeDLSubs> { |
50 | const cwd = CONFIG.STORAGE.TMP_DIR | 68 | const cwd = CONFIG.STORAGE.TMP_DIR |
51 | 69 | ||
@@ -103,7 +121,7 @@ class YoutubeDLWrapper { | |||
103 | 121 | ||
104 | return remove(path) | 122 | return remove(path) |
105 | }) | 123 | }) |
106 | .catch(innerErr => logger.error('Cannot remove file in youtubeDL timeout.', { innerErr, ...lTags() })) | 124 | .catch(innerErr => logger.error('Cannot remove file in youtubeDL error.', { innerErr, ...lTags() })) |
107 | 125 | ||
108 | throw err | 126 | throw err |
109 | } | 127 | } |