From 4a26709203ca0bf0eaef8f4545a732da7e243b9b Mon Sep 17 00:00:00 2001 From: Peifan Li Date: Sun, 7 Dec 2025 23:54:48 -0500 Subject: [PATCH] feat: Improve MissAVDownloader methods and error handling --- .../services/downloaders/MissAVDownloader.ts | 848 +++++++++++------- 1 file changed, 508 insertions(+), 340 deletions(-) diff --git a/backend/src/services/downloaders/MissAVDownloader.ts b/backend/src/services/downloaders/MissAVDownloader.ts index 54aabd3..606a524 100644 --- a/backend/src/services/downloaders/MissAVDownloader.ts +++ b/backend/src/services/downloaders/MissAVDownloader.ts @@ -10,375 +10,543 @@ import * as storageService from "../storageService"; import { Video } from "../storageService"; export class MissAVDownloader { - // Get video info without downloading - static async getVideoInfo(url: string): Promise<{ title: string; author: string; date: string; thumbnailUrl: string }> { - try { - console.log("Fetching MissAV page content with Puppeteer..."); + // Get video info without downloading + static async getVideoInfo( + url: string + ): Promise<{ + title: string; + author: string; + date: string; + thumbnailUrl: string; + }> { + try { + console.log("Fetching MissAV page content with Puppeteer..."); - const browser = await puppeteer.launch({ - headless: true, - executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined, - args: ['--no-sandbox', '--disable-setuid-sandbox'] - }); - const page = await browser.newPage(); - await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); - await page.goto(url, { waitUntil: 'networkidle2', timeout: 60000 }); + const browser = await puppeteer.launch({ + headless: true, + executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined, + args: ["--no-sandbox", "--disable-setuid-sandbox"], + }); + const page = await browser.newPage(); + await page.setUserAgent( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ); + await page.goto(url, { waitUntil: "networkidle2", timeout: 60000 }); - const html = await page.content(); - await browser.close(); + const html = await page.content(); + await browser.close(); - const $ = cheerio.load(html); - const pageTitle = $('meta[property="og:title"]').attr('content'); - const ogImage = $('meta[property="og:image"]').attr('content'); + const $ = cheerio.load(html); + const pageTitle = $('meta[property="og:title"]').attr("content"); + const ogImage = $('meta[property="og:image"]').attr("content"); - return { - title: pageTitle || "MissAV Video", - author: "MissAV", - date: new Date().toISOString().slice(0, 10).replace(/-/g, ""), - thumbnailUrl: ogImage || "", - }; - } catch (error) { - console.error("Error fetching MissAV video info:", error); - return { - title: "MissAV Video", - author: "MissAV", - date: new Date().toISOString().slice(0, 10).replace(/-/g, ""), - thumbnailUrl: "", - }; - } + return { + title: pageTitle || "MissAV Video", + author: "MissAV", + date: new Date().toISOString().slice(0, 10).replace(/-/g, ""), + thumbnailUrl: ogImage || "", + }; + } catch (error) { + console.error("Error fetching MissAV video info:", error); + return { + title: "MissAV Video", + author: "MissAV", + date: new Date().toISOString().slice(0, 10).replace(/-/g, ""), + thumbnailUrl: "", + }; } + } - // Helper function to download MissAV video - static async downloadVideo(url: string, downloadId?: string, onStart?: (cancel: () => void) => void): Promise