'use strict'; const unprint = require('unprint'); function scrapeAll(scenes) { return scenes.map(({ query }) => { const release = {}; release.url = query.url('.image-container a'); release.entryId = new URL(release.url).pathname.match(/\/video-preview\/(\w+)/)[1]; release.title = query.content('.caption-title'); release.poster = query.img('.image-container img'); return release; }); } function scrapeScene({ query }, { url }) { const release = {}; release.entryId = new URL(url).pathname.match(/\/video-preview\/(\w+)/)[1]; release.title = query.content('#dm_content .dmNewParagraph[data-diy-text]'); release.poster = query.poster('#dm_content video'); release.trailer = query.video('#dm_content video source'); return release; } async function fetchScene(url) { const res = await unprint.get(url, { headers: { Accept: '*/*', // seems to respond with JSON otherwise }, }); if (res.ok) { return scrapeScene(res.context, { url }); } return res.status; } async function fetchLatest(channel) { const url = `${channel.url}/free-video`; // no pagination at this time const res = await unprint.get(url, { selectAll: '.gallery .photoGalleryThumbs', headers: { Accept: '*/*', // seems to respond with JSON otherwise }, }); if (res.ok) { return scrapeAll(res.context, channel); } return res.status; } module.exports = { fetchLatest, fetchScene, };