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
Raw Normal View History

2021-06-11 22:13:15 +00:00
const fs = require('fs')
2021-06-11 20:08:53 +00:00
const cheerio = require('cheerio')
const fetch = require('node-fetch')
const epub = require('epub-gen')
const books = []
2021-06-11 22:13:15 +00:00
if (!fs.existsSync('output')) {
fs.mkdirSync('output')
}
2021-06-11 20:08:53 +00:00
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) {
2021-06-12 07:38:16 +00:00
volume = html(el).text().replace(/Volume /, '').trim()
2021-06-11 21:12:44 +00:00
books.push(metadata(volume))
} else {
2021-06-11 20:08:53 +00:00
html('a', el).each((i, el) => {
2021-06-11 21:12:44 +00:00
books[volume - 1].links.push(html(el).attr('href'))
2021-06-11 20:08:53 +00:00
})
}
})
books.map(async book => {
for (const link of book.links) {
book.content.push(await fetchPage(link))
}
new epub(book)
})
})()