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,34 +1,30 @@
'use strict';
'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const mime = require('mime-types');
function eroshareItem(post) {
return fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/i/${post.host.id}`).then(res => {
if(res.ok) {
return res.text();
}
async function eroshareItem(host, post) {
const res = await fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/i/${host.id}`);
if (!res.ok) {
throw new Error(`Unable to recover Eroshare item '${host.id}' :(`);
}
return Promise.reject(`Unable to recover Eroshare item '${post.host.id}' :(`);
}).then(res => {
const $ = cheerio.load(res);
const videoElement = $('source[data-default="true"]');
const html = await res.text();
return {
album: null,
items: [{
id: post.host.id,
url: videoElement.attr('src'),
title: post.title,
type: videoElement.attr('type'),
datetime: post.datetime,
original: post
}]
};
});
};
const $ = cheerio.load(html);
const videoElement = $('source[data-default="true"]');
return {
album: null,
items: [{
id: host.id,
url: videoElement.attr('src'),
title: post ? post.title : null,
type: videoElement.attr('type'),
datetime: post ? post.datetime : null,
original: post || null,
}],
};
}
module.exports = eroshareItem;