ripunzel/methods/eroshare.js

45 lines
1.5 KiB
JavaScript

'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
function eroshare(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 video '${post.host.id}' :(`);
}).then(res => {
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
const extract = config.patterns.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
};
})
};
}).catch(error => {
console.log('\x1b[33m%s\x1b[0m', error);
});
};
module.exports = eroshare;