traxxx/src/scrapers/karups.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
const qu = require('../utils/qu');
const slugify = require('../utils/slugify');
const channelSlugs = {
kpc: 'karupsprivatecollection',
kha: 'karupshometownamateurs',
kow: 'karupsolderwomen',
};
function scrapeAll(scenes) {
return scenes.map(({ query }) => {
const release = {};
release.url = query.url('a');
release.entryId = new URL(release.url).pathname.match(/(\d+)\.html/)?.[1];
release.title = query.cnt('.title');
release.date = query.date('.date', 'MMM Do, YYYY');
release.channel = channelSlugs[query.cnt('.site')];
release.poster = query.img('.thumb img');
return release;
});
}
function scrapeScene({ query }, url) {
const release = {};
release.entryId = new URL(url).pathname.match(/(\d+)\.html/)?.[1];
release.title = query.cnt('.title');
release.date = query.date('.date .content', 'MMM Do, YYYY');
2021-11-20 22:59:15 +00:00
release.actors = query.all('.models .content a').map((modelEl) => ({
name: query.cnt(modelEl),
url: query.url(modelEl, null),
}));
release.poster = query.poster();
release.photos = query.imgs('.video-thumbs img').slice(1);
release.trailer = query.video();
return release;
}
function scrapeProfile({ query }, entity) {
const profile = {};
profile.gender = 'female';
profile.avatar = query.img('.model-thumb img[src*=".jpg"]');
profile.scenes = scrapeAll(qu.initAll(query.all('.listing-videos .item')), entity);
return profile;
}
async function fetchLatest(channel, page) {
const res = await qu.getAll(`${channel.url}/videos/page${page}.html`, '.listing-videos .item');
if (res.ok) {
return scrapeAll(res.items, channel);
}
return res.status;
}
async function fetchProfile(baseActor, entity) {
const searchRes = await qu.getAll(`https://www.karups.com/models/search/${baseActor.slug}/`, '.listing-models .item');
if (!searchRes.ok) {
return searchRes.status;
}
2021-11-20 22:59:15 +00:00
const actorUrl = searchRes.items.find((item) => slugify(item.query.cnt('.title')) === baseActor.slug)?.query.url('a');
if (!actorUrl) {
return null;
}
const actorRes = await qu.get(actorUrl);
if (actorRes.ok) {
return scrapeProfile(actorRes.item, entity);
}
return actorRes.status;
}
module.exports = {
fetchLatest,
fetchProfile,
scrapeScene,
};