From 67378d4c7ad53bac54782982c837e1b880594037 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Tue, 15 May 2018 15:36:15 +0200 Subject: [PATCH] Added new eroshare method source files. --- src/methods/eroshareAlbum.js | 42 ++++++++++++++++++++++++++++++++++++ src/methods/eroshareItem.js | 34 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/methods/eroshareAlbum.js create mode 100644 src/methods/eroshareItem.js diff --git a/src/methods/eroshareAlbum.js b/src/methods/eroshareAlbum.js new file mode 100644 index 0000000..141b620 --- /dev/null +++ b/src/methods/eroshareAlbum.js @@ -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; diff --git a/src/methods/eroshareItem.js b/src/methods/eroshareItem.js new file mode 100644 index 0000000..aadccdb --- /dev/null +++ b/src/methods/eroshareItem.js @@ -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;