Update server.js
Browse files
server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const axios = require('axios');
|
| 3 |
const cheerio = require('cheerio');
|
| 4 |
-
const puppeteer = require('puppeteer-core');
|
| 5 |
|
| 6 |
const app = express();
|
| 7 |
const PORT = 7860;
|
|
@@ -36,16 +35,15 @@ async function searchGogoanime(animeTitle, episodeNumber) {
|
|
| 36 |
// Find first result
|
| 37 |
const firstResult = $('.items li a').first();
|
| 38 |
const animeSlug = firstResult.attr('href')?.split('/')[2];
|
| 39 |
-
const foundTitle = firstResult.text().trim();
|
| 40 |
if (!animeSlug) throw new Error("Anime not found");
|
| 41 |
|
| 42 |
-
console.log(`Anime Found: ${
|
| 43 |
|
| 44 |
// Episode page URL
|
| 45 |
const episodeUrl = `https://ww24.gogoanimes.fi/${animeSlug}-episode-${episodeNumber}`;
|
| 46 |
console.log(`Episode URL: ${episodeUrl}`);
|
| 47 |
|
| 48 |
-
return await getEpisodeInfo(episodeUrl,
|
| 49 |
} catch (error) {
|
| 50 |
throw new Error("Error searching Gogoanime: " + error.message);
|
| 51 |
}
|
|
@@ -57,85 +55,22 @@ async function getEpisodeInfo(episodeUrl, animeTitle, episodeNumber) {
|
|
| 57 |
const response = await axios.get(episodeUrl);
|
| 58 |
const $ = cheerio.load(response.data);
|
| 59 |
|
| 60 |
-
//
|
| 61 |
-
const
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
const downloadPageUrl = $('.dowloads a').attr('href');
|
| 66 |
-
if (!downloadPageUrl) throw new Error("Download page not found");
|
| 67 |
-
|
| 68 |
-
console.log(`S3embtaku Download Page Found: ${downloadPageUrl}`);
|
| 69 |
-
|
| 70 |
-
const downloadLinks = await getVideoLinks(downloadPageUrl);
|
| 71 |
|
| 72 |
return {
|
| 73 |
anime: animeTitle,
|
| 74 |
episode: episodeNumber,
|
| 75 |
-
thumbnail,
|
| 76 |
-
summary,
|
| 77 |
owner: "Reiker",
|
| 78 |
-
|
| 79 |
};
|
| 80 |
} catch (error) {
|
| 81 |
throw new Error("Error fetching episode info: " + error.message);
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
-
async function getVideoLinks(downloadPageUrl) {
|
| 86 |
-
console.log(`Opening Puppeteer: ${downloadPageUrl}`);
|
| 87 |
-
|
| 88 |
-
const browser = await puppeteer.launch({
|
| 89 |
-
executablePath: "/usr/bin/chromium",
|
| 90 |
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
| 91 |
-
});
|
| 92 |
-
|
| 93 |
-
const page = await browser.newPage();
|
| 94 |
-
|
| 95 |
-
try {
|
| 96 |
-
await page.goto(downloadPageUrl, { waitUntil: 'networkidle2' });
|
| 97 |
-
|
| 98 |
-
// Wait for the download buttons to load
|
| 99 |
-
await page.waitForSelector('a[href*="ggredi.info/download.php"]', { timeout: 10000 });
|
| 100 |
-
|
| 101 |
-
// Get all quality links
|
| 102 |
-
const videoLinks = await page.evaluate(() => {
|
| 103 |
-
const links = Array.from(document.querySelectorAll('a[href*="ggredi.info/download.php"]'));
|
| 104 |
-
return links.map(link => ({
|
| 105 |
-
quality: link.innerText.trim(),
|
| 106 |
-
url: link.href
|
| 107 |
-
}));
|
| 108 |
-
});
|
| 109 |
-
|
| 110 |
-
await browser.close();
|
| 111 |
-
|
| 112 |
-
return videoLinks;
|
| 113 |
-
} catch (error) {
|
| 114 |
-
console.error("Error extracting video links:", error.message);
|
| 115 |
-
await browser.close();
|
| 116 |
-
return [];
|
| 117 |
-
}
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
async function getFinalMp4Link(redirectLink) {
|
| 121 |
-
try {
|
| 122 |
-
console.log(`Following redirect: ${redirectLink}`);
|
| 123 |
-
|
| 124 |
-
// Step 1: Follow Redirect and Get Final Video URL
|
| 125 |
-
const response = await axios.get(redirectLink, { maxRedirects: 5 });
|
| 126 |
-
|
| 127 |
-
if (response.request.res.responseUrl) {
|
| 128 |
-
console.log(`Final MP4 Link: ${response.request.res.responseUrl}`);
|
| 129 |
-
return response.request.res.responseUrl;
|
| 130 |
-
} else {
|
| 131 |
-
console.log("No final MP4 link found.");
|
| 132 |
-
return null;
|
| 133 |
-
}
|
| 134 |
-
} catch (error) {
|
| 135 |
-
console.error("Error fetching final MP4 link:", error.message);
|
| 136 |
-
return null;
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
// Start API Server
|
| 141 |
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const axios = require('axios');
|
| 3 |
const cheerio = require('cheerio');
|
|
|
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
const PORT = 7860;
|
|
|
|
| 35 |
// Find first result
|
| 36 |
const firstResult = $('.items li a').first();
|
| 37 |
const animeSlug = firstResult.attr('href')?.split('/')[2];
|
|
|
|
| 38 |
if (!animeSlug) throw new Error("Anime not found");
|
| 39 |
|
| 40 |
+
console.log(`Anime Found: ${animeTitle} (${animeSlug})`);
|
| 41 |
|
| 42 |
// Episode page URL
|
| 43 |
const episodeUrl = `https://ww24.gogoanimes.fi/${animeSlug}-episode-${episodeNumber}`;
|
| 44 |
console.log(`Episode URL: ${episodeUrl}`);
|
| 45 |
|
| 46 |
+
return await getEpisodeInfo(episodeUrl, animeTitle, episodeNumber);
|
| 47 |
} catch (error) {
|
| 48 |
throw new Error("Error searching Gogoanime: " + error.message);
|
| 49 |
}
|
|
|
|
| 55 |
const response = await axios.get(episodeUrl);
|
| 56 |
const $ = cheerio.load(response.data);
|
| 57 |
|
| 58 |
+
// Find s3mtaku link
|
| 59 |
+
const s3mtakuLink = $('iframe').attr('src');
|
| 60 |
+
if (!s3mtakuLink) throw new Error("s3mtaku link not found");
|
| 61 |
|
| 62 |
+
console.log(`s3mtaku Link: ${s3mtakuLink}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
return {
|
| 65 |
anime: animeTitle,
|
| 66 |
episode: episodeNumber,
|
|
|
|
|
|
|
| 67 |
owner: "Reiker",
|
| 68 |
+
streamLink: s3mtakuLink
|
| 69 |
};
|
| 70 |
} catch (error) {
|
| 71 |
throw new Error("Error fetching episode info: " + error.message);
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
// Start API Server
|
| 76 |
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));
|