forked from DebaucheryLibrarian/traxxx
98 lines
2.2 KiB
JavaScript
98 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
const qu = require('../utils/q');
|
|
const slugify = require('../utils/slugify');
|
|
|
|
function scrapeAll(scenes) {
|
|
return scenes.map(({ query }) => {
|
|
const release = {};
|
|
|
|
release.url = query.url('.title a');
|
|
release.entryId = new URL(release.url).pathname.match(/\/scene\/(\d+)/)[1];
|
|
|
|
release.title = query.cnt('.title a');
|
|
release.description = query.cnt('.description');
|
|
|
|
release.date = query.date('.date', 'MMM DD, YYYY');
|
|
release.actors = query.cnts('.models a.model');
|
|
|
|
release.poster = query.img('img.poster');
|
|
release.teaser = { src: query.video('.teaser video') };
|
|
|
|
release.stars = query.number('.rating');
|
|
release.likes = query.number('.likes');
|
|
|
|
console.log(release);
|
|
return release;
|
|
});
|
|
}
|
|
|
|
function scrapeScene({ query }, url) {
|
|
const release = {};
|
|
|
|
release.entryId = new URL(url).pathname.match(/\/scene\/(\d+)/)[1];
|
|
|
|
release.title = query.cnt('h3.title');
|
|
release.description = query.cnt('p.description');
|
|
|
|
[release.poster, ...release.photos] = query.imgs('.preview-thumb');
|
|
release.trailer = { src: query.video('.trailer video') };
|
|
|
|
console.log(release);
|
|
return release;
|
|
}
|
|
|
|
function scrapeProfile({ query, el }, actorName, entity, include) {
|
|
const profile = {};
|
|
|
|
profile.description = query.cnt('.bio-text');
|
|
profile.birthPlace = query.cnt('.birth-place span');
|
|
|
|
profile.avatar = query.img('.actor-photo img');
|
|
|
|
if (include.releases) {
|
|
return scrapeAll(qu.initAll(el, '.scene'));
|
|
}
|
|
|
|
console.log(profile);
|
|
return profile;
|
|
}
|
|
|
|
async function fetchLatest(channel, page = 1) {
|
|
const url = `${channel.url}/${page}`;
|
|
const res = await qu.getAll(url, '.scene');
|
|
|
|
if (res.ok) {
|
|
return scrapeAll(res.items, channel);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
async function fetchScene(url, channel) {
|
|
const res = await qu.get(url);
|
|
|
|
if (res.ok) {
|
|
return scrapeScene(res.item, url, channel);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
async function fetchProfile({ name: actorName }, entity, include) {
|
|
const url = `${entity.url}/actors/${slugify(actorName, '_')}`;
|
|
const res = await qu.get(url);
|
|
|
|
if (res.ok) {
|
|
return scrapeProfile(res.item, actorName, entity, include);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchScene,
|
|
fetchProfile,
|
|
};
|