78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const qu = require('../utils/qu');
|
||
|
const slugify = require('../utils/slugify');
|
||
|
|
||
|
function scrapeAll({ query }) {
|
||
|
const urls = query.urls('td > a:not([href*=joinnow])').map(pathname => `http://killergram.com/${encodeURI(pathname)}`);
|
||
|
const posters = query.imgs('td > a img');
|
||
|
const titles = query.all('.episodeheadertext', true);
|
||
|
const actors = query.all('.episodetextinfo:nth-child(3)').map(el => query.all(el, 'a', true));
|
||
|
const channels = query.all('.episodetextinfo:nth-child(2) a', true).map(channel => slugify(channel, ''));
|
||
|
|
||
|
if ([urls.length, posters.length, titles.length, actors.length, channels.length].every((value, index, array) => value === array[0])) { // make sure every set has the same number of items
|
||
|
const releases = urls.map((url, index) => ({
|
||
|
url,
|
||
|
entryId: new URL(url).searchParams.get('id'),
|
||
|
title: titles[index],
|
||
|
actors: actors[index],
|
||
|
channel: channels[index],
|
||
|
poster: posters[index],
|
||
|
}));
|
||
|
|
||
|
return releases;
|
||
|
}
|
||
|
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
function scrapeScene({ query, html }, url) {
|
||
|
const release = {};
|
||
|
|
||
|
release.entryId = new URL(url).searchParams.get('id');
|
||
|
release.date = query.date('.episodetext', 'DD MMMM YYYY', /\d{2} \w+ \d{4}/);
|
||
|
|
||
|
release.description = query.q('.episodetext tr:nth-child(5) td:nth-child(2)', true);
|
||
|
release.actors = query.all('.modelstarring a', true);
|
||
|
|
||
|
const duration = html.match(/(\d+) minutes/)?.[1];
|
||
|
if (duration) release.duration = Number(duration) * 60;
|
||
|
|
||
|
[release.poster, ...release.photos] = query.imgs('img[src*="/models"]');
|
||
|
|
||
|
return release;
|
||
|
}
|
||
|
|
||
|
function scrapeProfile({ query }, actorName) {
|
||
|
const profile = {};
|
||
|
|
||
|
profile.releases = scrapeAll({ query }).filter(release => release.actors.includes(actorName));
|
||
|
|
||
|
return profile;
|
||
|
}
|
||
|
|
||
|
async function fetchLatest(channel, page = 1) {
|
||
|
const res = await qu.get(`${channel.url}&p=${page}`, '#episodes > table');
|
||
|
|
||
|
return res.ok ? scrapeAll(res.item, channel) : res.status;
|
||
|
}
|
||
|
|
||
|
async function fetchScene(url, channel) {
|
||
|
const res = await qu.get(url, '#episodes > table');
|
||
|
|
||
|
return res.ok ? scrapeScene(res.item, url, channel) : res.status;
|
||
|
}
|
||
|
|
||
|
async function fetchProfile(actorName) {
|
||
|
const url = `http://killergram.com/episodes.asp?page=episodes&model=${encodeURI(actorName)}&ct=model`;
|
||
|
const res = await qu.get(url, '#episodes > table');
|
||
|
|
||
|
return res.ok ? scrapeProfile(res.item, actorName) : res.status;
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
fetchLatest,
|
||
|
fetchScene,
|
||
|
fetchProfile,
|
||
|
};
|