'use strict'; const config = require('config'); const fetch = require('node-fetch'); async function eroshareAlbum(host) { const res = await fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${host.id}`); if (!res.ok) { throw new Error(`Unable to recover Eroshare album or item '${host.id}' :(`); } const html = await res.text(); const data = JSON.parse(html.match(/var album = .*/)[0].slice(12, -1)); const extract = config.library.extractSingleAlbumItem && 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 => ({ 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;