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_fr.js

68 lines
1.9 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')
let post = 0
let page = 0
const MAX_VOLUME = 3
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 volume = (post) => post <= 69 ? 1 : post <= 168 ? 2 : MAX_VOLUME
const metadata = (volume) => ({
title: `L'auberge Vagabonde - Volume ${volume}`,
author: ['Maroti', 'ElliVia', 'Pirateaba'],
cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png',
output: `output/L'auberge Vagabonde - Volume ${volume}.epub`,
version: 3,
lang: 'fr',
tocTitle: 'Table des matières',
appendChapterTitles: false,
content: [],
verbose: true,
description: "L'histoire d'une fille, d'une auberge et d'un monde plein de niveaux",
})
2021-06-11 22:17:08 +00:00
for (let i = 1; i <= MAX_VOLUME; i++) {
books.push(metadata(i))
2021-06-11 20:08:53 +00:00
}
(async () => {
while (true) {
2021-06-11 21:07:51 +00:00
const response = await fetch(`https://www.jeunesecrivains.com/t53075p${page++ * 15}-the-wandering-inn-fan-traduction-fantastique-aventure`)
2021-06-11 20:08:53 +00:00
const responseHtml = await response.text()
const html = cheerio.load(responseHtml)
const postBody = html('div.postbody')
if (postBody.html() === null) break
postBody.each((i, el) => {
if (++post === 1) return
const title = html('div[align=center]', el)
if (title.html() === null) return
let text = html('div > div', el)
2021-06-12 07:38:16 +00:00
text.attr('style', '')
2021-06-11 20:08:53 +00:00
2021-06-11 22:13:15 +00:00
const titleFirst = title.first()
titleFirst.find('br').replaceWith(' ')
const titleText = titleFirst.text().replace(/\*/g, '')
2021-06-11 20:08:53 +00:00
console.log(`${post} - ${titleText}`)
books[volume(post) - 1].content.push({
title: titleText,
data: text.html(),
})
})
}
books.map(book => new epub(book))
})()