Last active
October 6, 2023 20:47
-
-
Save ppalone/cb72ed5bab9546e97f9fc623b88d5067 to your computer and use it in GitHub Desktop.
Node script to download Tokyo revengers manga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependenices | |
const cheerio = require("cheerio"); | |
const axios = require("axios").default; | |
const fs = require("fs/promises"); | |
const fscore = require("fs"); | |
const path = require("path"); | |
// constants | |
const BASE_URL = "https://tokyorevengersmanga.com/"; | |
const FOLDER_NAME = "manga"; | |
(async () => { | |
try { | |
const res = await axios.get(BASE_URL) | |
const $ = cheerio.load(res.data) | |
const posts = $("li.su-post") | |
const t = [] | |
posts.each((_, post) => { | |
t.push({ | |
id: parseInt(post.attribs.id.split("-")[2], 10), | |
link: post.firstChild.attribs.href, | |
}) | |
}) | |
const s = t.sort((a, b) => a.id - b.id) | |
for (let i = 0; i < s.length; i++) { | |
const d = path.join(__dirname, FOLDER_NAME, `chapter-${i + 1}`) | |
await fs.mkdir(d, { recursive: true }) | |
const res = await axios.get(s[i].link) | |
const $ = cheerio.load(res.data) | |
const images = $(".entry-content .separator > img") | |
const t = [] | |
images.each((_, img) => { | |
t.push(img.attribs.src) | |
}) | |
for (let j = 0; j < t.length; j++) { | |
const res = await axios({ | |
method: "GET", | |
url: t[j], | |
responseType: "stream" | |
}) | |
res.data.pipe(fscore.createWriteStream(path.join(d, `${j + 1}.jpg`))) | |
} | |
} | |
} catch (err) { | |
console.error(err) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment