@@ -8,7 +8,7 @@ const fetchYoutubeHeaders = {
8
8
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36'
9
9
}
10
10
const subtitlesYTDLPArgs = `--write-subs --write-auto-subs --sub-format vtt --convert-subs srt -k`
11
- const videoYTDLPArgs = `--concurrent-fragments 5 -f best[ext=mp4 ] --sponsorblock-remove sponsor`
11
+ const videoYTDLPArgs = `--concurrent-fragments 5 --merge-output-format webm/mp4 -f bestvideo[height<=480]+bestaudio/ best[height<=480 ] --sponsorblock-remove sponsor`
12
12
13
13
function getOptionalCookiesPath ( ) {
14
14
if ( fs . existsSync ( '/app/cookies.txt' ) ) return '/app/cookies.txt'
@@ -25,22 +25,31 @@ export async function downloadVideo(id, repo, callback = () => {}) {
25
25
try {
26
26
const cookiesPath = getOptionalCookiesPath ( )
27
27
let cookiesOption = cookiesPath ? `--cookies ${ cookiesPath } ` : ''
28
- const commandArgs = `-o ./data/videos/${ id } .mp4 ${ cookiesOption } ${ videoYTDLPArgs } ${ subtitlesYTDLPArgs } -- ${ id } ` . split ( / + / )
28
+ const commandArgs = `-o ./data/videos/${ id } .%(ext)s ${ cookiesOption } ${ videoYTDLPArgs } ${ subtitlesYTDLPArgs } -- ${ id } ` . split ( / + / )
29
29
console . log ( 'running yt-dlp' , commandArgs . join ( ' ' ) )
30
+ let location , format
30
31
for await ( const line of spawn ( 'yt-dlp' , commandArgs ) ) {
31
32
console . log ( line )
32
33
callback ( line )
34
+ if ( line . startsWith ( '[Merger] Merging formats into' ) ) {
35
+ location = line . substring ( line . lastIndexOf ( ' ' ) + 1 ) . replace ( / " / g, '' )
36
+ format = location . substring ( location . lastIndexOf ( '.' ) + 1 )
37
+ }
33
38
}
39
+ console . log ( 'downloaded file to' , location )
34
40
35
41
if ( ! repo . getVideo ( id ) ) {
36
42
const video = await getVideo ( id )
43
+ video . location = location
44
+ video . format = format
37
45
repo . upsertVideos ( [ video ] )
38
46
callback ( `downloaded external video ${ id } ` )
39
47
}
48
+
49
+ repo . updateVideo ( id , { downloaded : true , location, format} )
40
50
41
51
normalizeSubtitleFiles ( id )
42
52
43
- repo . setVideoDownloaded ( id )
44
53
console . log ( 'Download completed' )
45
54
resolve ( id )
46
55
} catch ( error ) {
0 commit comments