Completed Erome module. Added content URL list fetching.

This commit is contained in:
2024-09-11 05:16:57 +02:00
parent aecf79fa25
commit 443f0fc028
5 changed files with 87 additions and 36 deletions

View File

@@ -1,30 +1,76 @@
'use strict';
const config = require('config');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const base = 'https://www.erome.com/';
async function erome(host) {
const res = await fetch(`${base}a/${host.id}`);
async function erome(host, post) {
const url = `${base}a/${host.id}`;
const res = await fetch(url);
if (res.ok) {
if (!res.ok) {
throw new Error(`Unable to retrieve info for Erome album '${host.id}' :(`);
}
const html = await res.text();
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(sourceHd.attr('src'));
const title = $('meta[property="og:title"]').attr('content') || $('meta[property="twitter:title"]').attr('content');
return sourceHd ? base + sourceHd.attr('src') : base + sourceSd.attr('src');
const items = $('.media-group').toArray().map((mediaItem) => {
const mediaElement = $(mediaItem);
const videoElement = mediaElement.find('.video video');
const id = mediaElement.attr('id');
const itemTitle = mediaElement.find('h2.media-title').text();
if (videoElement.length) {
const sourceHd = videoElement.find('source[label="HD"]');
const sourceSd = videoElement.find('source[label="SD"]');
return {
id,
title: itemTitle,
url: sourceHd.length ? sourceHd.attr('src') : sourceSd.attr('src'),
type: (sourceHd.length ? sourceHd.attr('type') : sourceSd.attr('type')) || 'video/mp4',
};
}
const img = mediaElement.find('.img-front').attr('data-src');
return {
id,
title: itemTitle,
url: img,
};
});
console.log(videoUrls);
const extract = config.library.extractSingleAlbumItem && (items.length === 1);
if (extract) {
console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${url}' (${post ? post.url : 'no post'})`);
}
return {
album: extract ? null : {
id: host.id,
url,
title,
description: null,
datetime: null,
},
items: items.map(item => ({
extracted: extract,
id: item.id,
url: item.url,
title: item.title || title || null,
description: null,
type: item.type || 'image/jpeg',
datetime: null,
})),
};
}
module.exports = erome;