2019-03-24 04:28:18 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
const qu = require('../utils/q');
|
|
|
|
const slugify = require('../utils/slugify');
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2020-07-17 01:39:13 +00:00
|
|
|
function scrapeAll(scenes) {
|
2020-07-16 13:55:03 +00:00
|
|
|
return scenes.map(({ query }) => {
|
|
|
|
const release = {};
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2020-07-17 01:39:13 +00:00
|
|
|
release.url = query.url('.title a');
|
|
|
|
release.entryId = new URL(release.url).pathname.match(/\/scene\/(\d+)/)[1];
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
release.title = query.cnt('.title a');
|
|
|
|
release.description = query.cnt('.description');
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
release.date = query.date('.date', 'MMM DD, YYYY');
|
|
|
|
release.actors = query.cnts('.models a.model');
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2020-07-17 01:39:13 +00:00
|
|
|
release.poster = query.img('img.poster');
|
|
|
|
release.teaser = { src: query.video('.teaser video') };
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
release.stars = query.number('.rating');
|
|
|
|
release.likes = query.number('.likes');
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
console.log(release);
|
|
|
|
return release;
|
|
|
|
});
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 01:39:13 +00:00
|
|
|
function scrapeScene({ query }, url) {
|
2020-07-16 13:55:03 +00:00
|
|
|
const release = {};
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2020-07-17 01:39:13 +00:00
|
|
|
release.entryId = new URL(url).pathname.match(/\/scene\/(\d+)/)[1];
|
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
release.title = query.cnt('h3.title');
|
|
|
|
release.description = query.cnt('p.description');
|
|
|
|
|
|
|
|
[release.poster, ...release.photos] = query.imgs('.preview-thumb');
|
2020-07-17 01:39:13 +00:00
|
|
|
release.trailer = { src: query.video('.trailer video') };
|
2020-07-16 13:55:03 +00:00
|
|
|
|
|
|
|
console.log(release);
|
|
|
|
return release;
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
function scrapeProfile({ query, el }, actorName, entity, include) {
|
|
|
|
const profile = {};
|
|
|
|
|
|
|
|
profile.description = query.cnt('.bio-text');
|
|
|
|
profile.birthPlace = query.cnt('.birth-place span');
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
profile.avatar = query.img('.actor-photo img');
|
|
|
|
|
|
|
|
if (include.releases) {
|
|
|
|
return scrapeAll(qu.initAll(el, '.scene'));
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(profile);
|
|
|
|
return profile;
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
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) {
|
2020-07-17 01:39:13 +00:00
|
|
|
return scrapeScene(res.item, url, channel);
|
2020-07-16 13:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res.status;
|
|
|
|
}
|
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
async function fetchProfile({ name: actorName }, entity, include) {
|
2020-07-16 13:55:03 +00:00
|
|
|
const url = `${entity.url}/actors/${slugify(actorName, '_')}`;
|
|
|
|
const res = await qu.get(url);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
return scrapeProfile(res.item, actorName, entity, include);
|
|
|
|
}
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2020-07-16 13:55:03 +00:00
|
|
|
return res.status;
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-07-16 13:55:03 +00:00
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
fetchProfile,
|
2019-03-24 04:28:18 +00:00
|
|
|
};
|