Added support for fetching content directly from host. Improved pattern interpolation. Refactored content modules.

This commit is contained in:
2024-09-11 05:16:57 +02:00
parent 20cb522689
commit b9a7e4b83a
26 changed files with 572 additions and 440 deletions

View File

@@ -1,32 +1,30 @@
'use strict';
'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const base = 'https://www.erome.com/';
function erome(post) {
return fetch(`${base}a/${post.host.id}`).then(res => {
if(res.ok) {
return res.text();
}
async function erome(host) {
const res = await fetch(`${base}a/${host.id}`);
throw new Error(`Unable to retrieve info for Erome album '${post.host.id}' :(`);
}).then(res => {
const $ = cheerio.load(res);
const videoUrls = $('video').toArray().map(videoEl => {
const sourceHd = $(videoEl).find('source[label="HD"]');
const sourceSd = $(videoEl).find('source[label="SD"]');
if (res.ok) {
throw new Error(`Unable to retrieve info for Erome album '${host.id}' :(`);
}
console.log(sourceHd.attr('src'));
const html = await res.text();
return sourceHd ? base + sourceHd.attr('src') : base + sourceSd.attr('src');
});
const $ = cheerio.load(html);
const videoUrls = $('video').toArray().map((videoEl) => {
const sourceHd = $(videoEl).find('source[label="HD"]');
const sourceSd = $(videoEl).find('source[label="SD"]');
console.log(videoUrls);
console.log(sourceHd.attr('src'));
return sourceHd ? base + sourceHd.attr('src') : base + sourceSd.attr('src');
});
};
console.log(videoUrls);
}
module.exports = erome;