This repository has been archived on 2024-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
Auberge_Vagabonde/livres_en.js

72 lines
1.8 KiB
JavaScript

const fs = require('fs')
const cheerio = require('cheerio')
const fetch = require('node-fetch')
const epub = require('epub-gen')
const books = []
if (!fs.existsSync('output')) {
fs.mkdirSync('output')
}
const metadata = (volume) => ({
title: `The Wandering Inn - Volume ${volume}`,
author: ['Pirateaba'],
cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png',
output: `output/The Wandering Inn - Volume ${volume}.epub`,
version: 3,
lang: 'en',
appendChapterTitles: true,
content: [],
links: [],
verbose: true,
description: 'A tale of a girl, an inn, and a world full of levels',
})
const fetchPage = async (url) => {
const response = await fetch(url)
const responseHtml = await response.text()
const html = cheerio.load(responseHtml)
const title = html('h1.entry-title').text()
const content = html('div.entry-content')
content.find('a').remove()
content.find('div.tiled-gallery').remove()
const data = content.html()
console.log(title)
return {
title,
data,
}
}
(async () => {
const response = await fetch('https://wanderinginn.com/table-of-contents/')
const responseHtml = await response.text()
const html = cheerio.load(responseHtml)
const content = html('div.entry-content > p')
let volume = 0;
content.each((i, el) => {
if (i % 2 === 0) {
volume = html(el).text().replace(/Volume /, '').trim()
books.push(metadata(volume))
} else {
html('a', el).each((i, el) => {
books[volume - 1].links.push(html(el).attr('href'))
})
}
})
books.map(async book => {
for (const link of book.links) {
book.content.push(await fetchPage(link))
}
new epub(book)
})
})()