Skip to content

Commit 7a52876

Browse files
committed
fix: initial state parse fail
1 parent 74fb2c4 commit 7a52876

7 files changed

+22
-15
lines changed

index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ function validateInt(value) {
2121
program
2222
.requiredOption(
2323
'-u, --url [urls...]',
24-
`the video set (or single) url of bilibili, can input multiple urls.`
24+
`the video set (or single) url of bilibili, can input multiple urls.`,
2525
)
2626
.option(
2727
'-t, --threads <number>',
2828
'how many download threads.',
2929
validateInt,
30-
10
30+
10,
3131
)
3232
.option(
3333
'-n, --naming <string>',
3434
`change the downloaded files' naming pattern. available: INDEX, TITLE, AUTHOR, DATE`,
35-
'TITLE-AUTHOR-DATE'
35+
'TITLE-AUTHOR-DATE',
3636
)
3737
.option(
3838
'--from <number>',
3939
'limit to page download from, 1-based.',
40-
validateInt
40+
validateInt,
4141
)
4242
.option('--to <number>', 'limit to page download to, 1-based.', validateInt)
4343
.option(
4444
'--index-offset <number>',
4545
'offset added to INDEX while saved.',
4646
validateInt,
47-
0
47+
0,
4848
)
4949
.option(
5050
'--skip-mp3',
5151
'skip the mp3 transform and keep downloaded file as video.',
52-
false
52+
false,
5353
)
5454
.option('--debug', 'enable debug log.', false);
5555

@@ -89,7 +89,7 @@ const argv = program.opts();
8989
!(
9090
(typeof argv.from === 'number' && index < argv.from) ||
9191
(typeof argv.to === 'number' && index > argv.to)
92-
)
92+
),
9393
);
9494
// console.log('Pages:', pages);
9595

src/_flv2mp3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import { uniqueId } from 'lodash-es';
1717
ffmpeg.FS(
1818
'writeFile',
1919
memBefore,
20-
await fetchFile(resolve(process.cwd(), filename))
20+
await fetchFile(resolve(process.cwd(), filename)),
2121
);
2222
// ffmpeg -y -i ${filename} -q:a 0 ${mp3}
2323
await ffmpeg.run('-y', '-i', memBefore, '-q:a', '0', memAfter);
2424
await fs.promises.writeFile(
2525
resolve(process.cwd(), mp3),
26-
ffmpeg.FS('readFile', memAfter)
26+
ffmpeg.FS('readFile', memAfter),
2727
);
2828
ffmpeg.FS('unlink', memBefore);
2929
ffmpeg.FS('unlink', memAfter);

src/debuglog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { join } from 'path';
44
export function debuglog(data) {
55
fs.appendFileSync(
66
join(process.cwd(), 'bilibili-video2mp3-error.log'),
7-
data.toString() + '\n'
7+
data.toString() + '\n',
88
);
99
}

src/download.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function download(url, index) {
7272
const cid = pages[pid - 1].cid;
7373
const title = (isSingle ? videoData.title : pages[pid - 1].part).replace(
7474
/\s/g,
75-
'-'
75+
'-',
7676
);
7777
const date = new Date(videoData.ctime * 1000);
7878
const dateString = `${date.getFullYear()}-${

src/download2mp3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function download2mp3({ url, index }) {
2424
const logFile = resolve(process.cwd(), 'bilibili-video2mp3-error.log');
2525
await fs.promises.appendFile(
2626
logFile,
27-
`index: ${offsetIndex}\n` + `url: ${url}\n` + err.stack + '\n\n'
27+
`index: ${offsetIndex}\n` + `url: ${url}\n` + err.stack + '\n\n',
2828
);
2929
}
3030
await sleep(2000);

src/flv2mp3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function flv2mp3(filename) {
1818
} else {
1919
resolve();
2020
}
21-
}
21+
},
2222
);
2323
});
2424
}

src/getDataByUrl.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import agent from './agent.js';
22

33
export async function getDataByUrl(url) {
44
const { data } = await agent.get(url);
5-
// console.log(data)
6-
const initialStateStr = data.match(/__INITIAL_STATE__=(.*?);/)[1];
5+
// console.log('--------data------------');
6+
// console.log(data);
7+
// console.log('--------------------');
8+
const initialStateStr = data.match(
9+
/__INITIAL_STATE__=(.*?);\(function\(\)/,
10+
)[1];
11+
// console.log('--------initialStateStr------------');
12+
// console.log(initialStateStr);
13+
// console.log('--------------------');
714
return JSON.parse(initialStateStr);
815
}

0 commit comments

Comments
 (0)