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

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-06-11 20:08:53 +00:00
const cheerio = require('cheerio')
const fetch = require('node-fetch')
const epub = require('epub-gen')
const START_VOLUME = 3
const books = []
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 /, '')
if (volume >= START_VOLUME) {
books.push(metadata(i))
}
} else if (volume >= START_VOLUME) {
html('a', el).each((i, el) => {
books[volume - START_VOLUME].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)
})
})()