You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
#!/usr/bin/node
|
|
|
|
import axios from 'axios'
|
|
import { constants } from 'buffer'
|
|
import * as cheerio from 'cheerio'
|
|
import fs from 'fs'
|
|
import { connect } from 'http2'
|
|
|
|
const BASEDDIR = 'hentai'
|
|
const DELAY = 16
|
|
|
|
|
|
|
|
async function main() {
|
|
if (!fs.existsSync(BASEDDIR)) {
|
|
fs.mkdirSync(BASEDDIR)
|
|
}
|
|
const start = 420
|
|
const end = 1312
|
|
for (let i = start; i <= end; i += 1) {
|
|
await dlHentai(i)
|
|
}
|
|
}
|
|
main()
|
|
|
|
|
|
|
|
|
|
async function dlHentai(id: number) {
|
|
if (!fs.existsSync(`${BASEDDIR}/${id}`)) {
|
|
fs.mkdirSync(`${BASEDDIR}/${id}`)
|
|
}
|
|
const res = await axios.get(`https://nhentai.net/g/${id}/1`)
|
|
const $ = cheerio.load(res.data)
|
|
const numpg = parseInt($(".num-pages").html())
|
|
const baseUrlParts = $("#image-container img").attr('src').split("/")
|
|
baseUrlParts.pop()
|
|
const baseUrl = baseUrlParts.join("/")
|
|
const prowomises = []
|
|
for (let i = 1; i <= numpg; i += 1) {
|
|
prowomises.push(dlSinglePage(id, baseUrl, i))
|
|
await sleep(DELAY)
|
|
}
|
|
await Promise.all(prowomises)
|
|
}
|
|
|
|
|
|
|
|
async function dlSinglePage(id: number, baseUrl: string, pgid: number) {
|
|
const res = await axios.get(`${baseUrl}/${pgid}.jpg`, {
|
|
responseType: "arraybuffer",
|
|
})
|
|
fs.writeFileSync(`${BASEDDIR}/${id}/${pgid}.jpg`, res.data)
|
|
}
|
|
|
|
|
|
async function sleep(ms: number) {
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
}
|
|
|
|
|
|
|