Added new eroshare method source files.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:55 +02:00
parent e1b3b1ce5f
commit e0ca4a0822
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,42 @@
'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
function eroshareAlbum(post) {
return fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${post.host.id}`).then(res => {
if(res.ok) {
return res.text();
}
return Promise.reject(`Unable to recover Eroshare album or item '${post.host.id}' :(`);
}).then(res => {
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
const extract = config.library.album.extractSingleItem && data.items.length === 1;
return {
album: extract ? null : {
id: data.slug,
title: data.title,
datetime: new Date(data.created_at)
},
items: data.items.map(item => {
return {
extracted: extract,
id: item.slug,
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
title: data.title,
description: item.description,
type: item.type === 'Image' ? 'image/jpeg' : 'video/mp4',
datetime: new Date(data.created_at),
width: data.width,
height: data.height,
original: item
};
})
};
});
};
module.exports = eroshareAlbum;

View File

@ -0,0 +1,34 @@
'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();
}
return Promise.reject(`Unable to recover Eroshare item '${post.host.id}' :(`);
}).then(res => {
const $ = cheerio.load(res);
const videoElement = $('source[data-default="true"]');
return {
album: null,
items: [{
id: post.host.id,
url: videoElement.attr('src'),
title: post.title,
type: videoElement.attr('type'),
datetime: post.datetime,
original: post
}]
};
});
};
module.exports = eroshareItem;