Skip to content

Instantly share code, notes, and snippets.

@fxp
Created April 22, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxp/65e72787462bab60c66624e5dd4532e7 to your computer and use it in GitHub Desktop.
Save fxp/65e72787462bab60c66624e5dd4532e7 to your computer and use it in GitHub Desktop.
Download all albumns from hentaiser homepage
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