add retrying for video list
This commit is contained in:
parent
27fb185b45
commit
ae25cb3c0d
5
bun.lock
5
bun.lock
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "preservetube-metadata-rewrite",
|
"name": "preservetube-metadata-rewrite",
|
||||||
|
|
@ -14,7 +15,7 @@
|
||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"googlevideo": "^4.0.4",
|
"googlevideo": "^4.0.4",
|
||||||
"jsdom": "^26.1.0",
|
"jsdom": "^26.1.0",
|
||||||
"youtubei.js": "^16.0.1",
|
"youtubei.js": "^17.0.1",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
|
|
@ -315,7 +316,7 @@
|
||||||
|
|
||||||
"xmlchars": ["xmlchars@2.2.0", "", {}, "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="],
|
"xmlchars": ["xmlchars@2.2.0", "", {}, "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="],
|
||||||
|
|
||||||
"youtubei.js": ["youtubei.js@16.0.1", "", { "dependencies": { "@bufbuild/protobuf": "^2.0.0", "meriyah": "^6.1.4" } }, "sha512-3802bCAGkBc2/G5WUTc0l/bO5mPYJbQAHL04d9hE9PnrDHoBUT8MN721Yqt4RCNncAXdHcfee9VdJy3Fhq1r5g=="],
|
"youtubei.js": ["youtubei.js@17.0.1", "", { "dependencies": { "@bufbuild/protobuf": "^2.0.0", "meriyah": "^6.1.4" } }, "sha512-1lO4b8UqMDzE0oh2qEGzbBOd4UYRdxn/4PdpRM7BGTHxM6ddsEsKZTu90jp8V9FHVgC2h1UirQyqoqLiKwl+Zg=="],
|
||||||
|
|
||||||
"dom-serializer/entities": ["entities@4.5.0", "", {}, "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="],
|
"dom-serializer/entities": ["entities@4.5.0", "", {}, "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="],
|
||||||
|
|
||||||
|
|
|
||||||
23
index.ts
23
index.ts
|
|
@ -91,11 +91,15 @@ app.get('/channel/:id', async (req, res) => {
|
||||||
|
|
||||||
app.get('/videos/:id', async (req, res) => {
|
app.get('/videos/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const videos = [];
|
let videos: any[] = [];
|
||||||
|
|
||||||
|
for (let attempt = 0; attempt < 3; attempt++) {
|
||||||
|
videos = [];
|
||||||
|
|
||||||
const yt = await Innertube.create();
|
const yt = await Innertube.create();
|
||||||
const channel = await yt.getChannel(req.params.id);
|
const channel = await yt.getChannel(req.params.id);
|
||||||
let json = await channel.getVideos();
|
|
||||||
|
|
||||||
|
let json = await channel.getVideos();
|
||||||
videos.push(...json.videos);
|
videos.push(...json.videos);
|
||||||
|
|
||||||
while (json.has_continuation && videos.length < 60) {
|
while (json.has_continuation && videos.length < 60) {
|
||||||
|
|
@ -103,13 +107,18 @@ app.get('/videos/:id', async (req, res) => {
|
||||||
videos.push(...json.videos);
|
videos.push(...json.videos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json(videos)
|
if (videos.length) break;
|
||||||
} catch (e:any) {
|
|
||||||
if (e.message.includes('Tab "videos" not found')) {
|
|
||||||
return res.json([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(false)
|
return res.json(videos);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
if (e.message.includes('Tab "videos" not found')) {
|
||||||
|
return res.json([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNextPage(json: any) {
|
async function getNextPage(json: any) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,6 @@
|
||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"googlevideo": "^4.0.4",
|
"googlevideo": "^4.0.4",
|
||||||
"jsdom": "^26.1.0",
|
"jsdom": "^26.1.0",
|
||||||
"youtubei.js": "^16.0.1"
|
"youtubei.js": "^17.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue