@@ -66,7 +66,7 @@ function main() {
6666
6767 let y2b = url . match ( / ^ h t t p s ? : \/ \/ (?: y o u t u .b e \/ | (?: w w w | m ) .y o u t u b e .c o m \/ (?: w a t c h | s h o r t s ) (?: \/ | \? v = ) ) ( [ \w - ] { 11 } ) $ / ) ;
6868 let bilibili = url . match ( / ^ h t t p s ? : \/ \/ (?: w w w \. | m \. ) ? b i l i b i l i \. c o m \/ v i d e o \/ ( [ \w \d ] { 11 , 14 } ) \/ ? (?: \? p = ( \d + ) ) ? $ / ) ;
69- let xcom = url . match ( / ^ h t t p s ? : \/ \/ (?: w w w ) ? x \. c o m \/ [ ^ \/ ] + \/ s t a t u s \/ ( \d + ) $ / ) ;
69+ let xcom = url . match ( / ^ h t t p s ? : \/ \/ (?: w w w ) ? x \. c o m \/ [ ^ \/ ] + \/ s t a t u s \/ ( \d + ) (?: \/ v i d e o \/ ( \d + ) ) ? $ / ) ;
7070 let website ;
7171 switch ( true ) {
7272 case y2b != null :
@@ -94,7 +94,7 @@ function main() {
9494 // console.log(JSON.stringify(msg, null, 1));
9595 res . send ( msg ) ;
9696 } ) ;
97- thread . postMessage ( { op : 'parse' , website, url, videoID : ( y2b || bilibili || xcom ) [ 1 ] , p : bilibili ?. [ 2 ] } ) ;
97+ thread . postMessage ( { op : 'parse' , website, url, videoID : ( y2b || bilibili || xcom ) [ 1 ] , p : ( bilibili || xcom ) ?. [ 2 ] } ) ;
9898 } ) ;
9999
100100 let queue = [ ] ;
@@ -367,25 +367,39 @@ function task() {
367367 } // case subtitle end
368368
369369 case 'parse' : {
370+ let { website, url, videoID, p } = msg ;
370371 let audios = [ ] , videos = [ ] ;
371372 let bestAudio = { } , bestVideo = { } ;
372373
373374 let rs = { title : '' , thumbnail : '' , formats : [ ] } ;
374375 try {
375- let cmd = `yt-dlp --print-json --skip-download ${ config . cookie !== undefined ? `--cookies ${ config . cookie } ` : '' } '${ msg . url } ' 2> /dev/null`
376+ let cmd = `yt-dlp --print-json --skip-download ${ config . cookie !== undefined ? `--cookies ${ config . cookie } ` : '' } '${ getWebsiteUrl ( website , videoID , p ) } ' 2> /dev/null`
376377 console . log ( '解析视频, 命令:' , cmd ) ;
377- rs = child_process . execSync ( cmd , { maxBuffer : 10 * 1024 * 1024 } ) . toString ( ) ; // 10MB 缓冲区
378- try {
379- rs = JSON . parse ( rs ) ;
380- } catch ( error ) {
381- let cmd = `yt-dlp --print-json --skip-download ${ config . cookie !== undefined ? `--cookies ${ config . cookie } ` : '' } '${ msg . url } ?p=1' 2> /dev/null` ;
382- console . log ( '尝试分P, 命令:' , cmd ) ;
383- rs = child_process . execSync ( cmd ) . toString ( ) ;
384- rs = JSON . parse ( rs ) ;
385- msg . p = '1' ;
386- msg . url = `${ msg . url } ?p=1` ;
378+ rs = child_process . execSync ( cmd , { maxBuffer : 10 * 1024 * 1024 } ) . toString ( ) ; // 10MB 缓冲区
379+ switch ( website ) {
380+ case 'xcom' : {
381+ let tmp = rs . split ( '\n' ) . filter ( it => it != '' ) ;
382+ rs = JSON . parse ( tmp [ p ? ( Number ( p ) - 1 ) : 0 ] ) ;
383+ if ( ! p && tmp . length > 1 ) {
384+ msg . p = '1' ;
385+ msg . url = getWebsiteUrl ( website , videoID , msg . p ) ;
386+ }
387+ break ;
388+ }
389+ default : {
390+ try {
391+ rs = JSON . parse ( rs ) ;
392+ } catch ( error ) {
393+ let cmd = `yt-dlp --print-json --skip-download ${ config . cookie !== undefined ? `--cookies ${ config . cookie } ` : '' } '${ msg . url } ?p=1' 2> /dev/null` ;
394+ console . log ( '尝试分P, 命令:' , cmd ) ;
395+ rs = child_process . execSync ( cmd ) . toString ( ) ;
396+ rs = JSON . parse ( rs ) ;
397+ msg . p = '1' ;
398+ msg . url = `${ msg . url } ?p=1` ;
399+ }
400+ console . log ( '解析完成:' , rs . title , msg . url ) ;
401+ }
387402 }
388- console . log ( '解析完成:' , rs . title , msg . url ) ;
389403 } catch ( error ) {
390404 console . log ( error . toString ( ) ) ;
391405 worker_threads . parentPort . postMessage ( {
@@ -438,10 +452,13 @@ function task() {
438452 let cmd = //`cd '${__dirname}' && (cd tmp > /dev/null || (mkdir tmp && cd tmp)) &&` +
439453 `yt-dlp ${ config . cookie !== undefined ? `--cookies ${ config . cookie } ` : '' } ${ getWebsiteUrl ( website , videoID , p ) } -f ${ format . replace ( 'x' , '+' ) } ` +
440454 `-o '${ fullpath } /${ videoID } .%(ext)s' ${ recode !== undefined ? `--recode ${ recode } ` : '' } -k --write-info-json` ;
455+ // if (website == 'xcom') cmd += ` --playlist-items ${p ?? 1}`; // 可能导致dest捕获异常
456+ if ( website == 'xcom' ) cmd += ` --no-playlist` ;
441457 console . log ( '下载视频, 命令:' , cmd ) ;
442458 try {
443459 let dest = 'Unknown dest' ;
444460 let ps = child_process . execSync ( cmd ) . toString ( ) . split ( '\n' ) ;
461+ // let regex = new RegExp(`^\\[download\\].*${fullpath}/(${videoID}\\.[\\w]+).*$`);
445462 let regex = new RegExp ( `^.*${ fullpath } /(${ videoID } \\.[\\w]+).*$` ) ;
446463 ps . forEach ( it => {
447464 console . log ( it ) ;
0 commit comments