From 25795e2cceab31345fc33f5848120203bb97698e Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Thu, 12 Mar 2020 00:59:32 +0100 Subject: [PATCH] Added latest and scene scrapers to BAM Visions. --- seeds/02_sites.js | 2 +- src/scrapers/bamvisions.js | 67 ++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/seeds/02_sites.js b/seeds/02_sites.js index b5707180..c09fdf22 100644 --- a/seeds/02_sites.js +++ b/seeds/02_sites.js @@ -498,7 +498,7 @@ const sites = [ { slug: 'bamvisions', name: 'BAM Visions', - url: 'https://www.bamvisions.com', + url: 'https://tour.bamvisions.com', network: 'bamvisions', }, // BANG diff --git a/src/scrapers/bamvisions.js b/src/scrapers/bamvisions.js index 0580787f..365e4501 100644 --- a/src/scrapers/bamvisions.js +++ b/src/scrapers/bamvisions.js @@ -1,26 +1,81 @@ 'use strict'; -const { geta } = require('../utils/qu'); +const { get, geta, formatDate } = require('../utils/qu'); +const slugify = require('../utils/slugify'); -function scrapeLatest(scenes, _site) { - return scenes.map(( qu ) => { +function scrapeLatest(scenes, site) { + return scenes.map(({ qu }) => { const release = {}; release.title = qu.q('h3 a', true); release.url = qu.url('h3 a'); - console.log(release); + release.date = qu.date('.item-meta li', 'MMMM D, YYYY', /\w+ \d{1,2}, \d{4}/); + release.duration = qu.dur('.item-meta li:nth-child(2)'); + release.description = qu.q('.description', true); + + release.actors = qu.all('a[href*="/models"]', true); + [release.poster, ...release.photos] = qu.all('.item-thumbs img') + .map(source => [ + source.getAttribute('src0_3x'), + source.getAttribute('src0_2x'), + source.getAttribute('src0_1x'), + ] + .filter(Boolean) + .map(fallback => (/^http/.test(fallback) ? fallback : `${site.url}${fallback}`))); + + release.entryId = `${formatDate(release.date, 'YYYY-MM-DD')}-${slugify(release.title)}`; + return release; }); } +function scrapeScene({ html, qu }, url, site) { + const release = { url }; + + release.title = qu.q('.item-episode h4 a', true); + release.date = qu.date('.item-meta li', 'MMMM D, YYYY', /\w+ \d{1,2}, \d{4}/); + release.duration = qu.dur('.item-meta li:nth-child(2)'); + release.description = qu.q('.description', true); + + release.actors = qu.all('.item-episode a[href*="/models"]', true); + + const posterPath = html.match(/poster="(.*.jpg)"/)?.[1]; + const trailerPath = html.match(/video src="(.*.mp4)"/)?.[1]; + + if (posterPath) { + const poster = /^http/.test(posterPath) ? posterPath : `${site.url}${posterPath}`; + release.poster = [ + poster.replace('-1x', '-3x'), + poster.replace('-1x', '-2x'), + poster, + ]; + } + + if (trailerPath) { + const trailer = /^http/.test(trailerPath) ? trailerPath : `${site.url}${trailerPath}`; + release.trailer = { src: trailer }; + } + + release.entryId = `${formatDate(release.date, 'YYYY-MM-DD')}-${slugify(release.title)}`; + + return release; +} + async function fetchLatest(site, page = 1) { - const url = `https://tour.bamvisions.com/categories/movies/${page}/latest/`; - const res = geta(url, '.item-episode'); + const url = `${site.url}/categories/movies/${page}/latest/`; + const res = await geta(url, '.item-episode'); return res.ok ? scrapeLatest(res.items, site) : res.status; } +async function fetchScene(url, site) { + const res = await get(url); + + return res.ok ? scrapeScene(res.item, url, site) : res.status; +} + module.exports = { fetchLatest, + fetchScene, };