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

87 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-08-24 21:41:04 +00:00
import fs from 'fs'
import cheerio from 'cheerio'
import fetch from 'node-fetch'
2021-08-31 16:21:30 +00:00
import Epub from 'epub-gen-funstory'
2021-06-11 20:08:53 +00:00
2021-06-11 22:13:15 +00:00
if (!fs.existsSync('output')) {
fs.mkdirSync('output')
}
const metadata = (volume, title, author, tocTitle, description) => ({
title: `${title} - Volume ${volume}`,
author,
2021-06-11 20:08:53 +00:00
cover: 'https://i.pinimg.com/originals/0b/fd/cf/0bfdcfb42ba3ff0a22f4a7bc52928af4.png',
output: `output/${title} - Volume ${volume}.epub`,
2021-06-11 20:08:53 +00:00
version: 3,
lang: 'fr',
tocTitle,
2021-06-11 20:08:53 +00:00
appendChapterTitles: true,
content: [],
links: [],
verbose: true,
description,
2021-06-11 20:08:53 +00:00
})
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()
2021-08-31 06:02:21 +00:00
content.find('h3').remove()
2021-08-30 13:40:57 +00:00
content.find('hr').remove()
2021-06-11 20:08:53 +00:00
content.find('div.tiled-gallery').remove()
const data = content.html()
console.log(title)
return {
title,
data,
}
}
const run = async (url, authors) => {
const books = []
const response = await fetch(url)
2021-06-11 20:08:53 +00:00
const responseHtml = await response.text()
const html = cheerio.load(responseHtml)
const content = html('div.entry-content > p')
const title = html('#site-title > span > a').text()
const summary = html('h1.entry-title').text()
const description = html('#site-description').text()
2021-06-11 20:08:53 +00:00
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()
if (volume === '') return
books.push(metadata(volume, title, authors, summary, description))
2021-06-11 21:12:44 +00:00
} 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))
}
2021-08-24 21:41:04 +00:00
new Epub(book)
2021-06-11 20:08:53 +00:00
})
}
run(
'https://aubergevagabonde.wordpress.com/sommaire/',
['Maroti', 'ElliVia', 'Pirateaba']
)
run(
'https://wanderinginn.com/table-of-contents/',
['Pirateaba']
)