Created
April 22, 2021 16:02
-
-
Save fxp/65e72787462bab60c66624e5dd4532e7 to your computer and use it in GitHub Desktop.
Download all albumns from hentaiser homepage
This file contains 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
const fetch = require('node-fetch-with-proxy'); | |
const fs = require('fs'); | |
const path = require('path'); | |
async function getAlbumnList(type) { | |
let result = await fetch("https://api.hentaiser.com/1.2/books/" + type, { | |
"headers": { | |
"accept": "*/*", | |
"content-type": "application/json", | |
"origin": "https://app.hentaiser.com", | |
}, | |
"referrer": "https://app.hentaiser.com/", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
}); | |
return result.json(); | |
} | |
async function getTag(tag) { | |
let result = await fetch("https://api.hentaiser.com/1.2/books/search/tags", { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-US,en;q=0.9", | |
"content-type": "application/json", | |
"sec-ch-ua": "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-site" | |
}, | |
"referrer": "https://app.hentaiser.com/", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": "{\"tags\":[\"tags like '%|chinese|%'\"],\"page\":1}", | |
"method": "POST", | |
"mode": "cors" | |
}); | |
return result.json(); | |
} | |
async function getAlbumnPics(albumnId) { | |
console.log('fetch data', albumnId); | |
let result = await fetch("https://api.hentaiser.com/1.2/book/images/" + albumnId, { | |
"headers": { | |
"accept": "*/*", | |
"content-type": "application/json", | |
"origin": "https://app.hentaiser.com", | |
}, | |
"referrer": "https://app.hentaiser.com/", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
}); | |
return result.json(); | |
} | |
async function downloadAllPics(albumnId) { | |
let result = await getAlbumnPics(albumnId); | |
if (!fs.existsSync(albumnId)) { | |
fs.mkdirSync(albumnId); | |
} | |
for (let pic of result) { | |
let resUrl = 'https://media.hentaiser.com' + pic.url; | |
let filename = './' + albumnId + '/' + path.basename(resUrl); | |
console.log('download', resUrl); | |
if (!fs.existsSync(filename)) { | |
let response = await fetch(resUrl); | |
if (!response.ok) { | |
console.error('failed', response.statusCode); | |
continue; | |
} | |
fs.writeFileSync(filename, await response.buffer()); | |
} else { | |
console.log('existing', filename); | |
} | |
} | |
} | |
const ALBUMN_TYPES = ['latest_home', 'hot_home', 'top_rated_home']; | |
async function downloadAllAlbumn() { | |
for (let type of ALBUMN_TYPES) { | |
let albumnList = await getAlbumnList(type); | |
for (let albumn of albumnList) { | |
try { | |
await downloadAllPics(albumn.gid); | |
} catch (e) { | |
} | |
} | |
} | |
} | |
downloadAllAlbumn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment