2020-07-03 02:42:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2020-07-10 00:01:23 +00:00
|
|
|
const logger = require('../logger')(__filename);
|
2020-07-03 02:42:20 +00:00
|
|
|
const http = require('../utils/http');
|
2020-07-06 02:13:48 +00:00
|
|
|
const qu = require('../utils/qu');
|
2020-07-07 02:37:12 +00:00
|
|
|
const slugify = require('../utils/slugify');
|
2020-07-03 02:42:20 +00:00
|
|
|
const { prefixUrl } = require('../utils/qu');
|
|
|
|
|
2020-07-07 02:37:12 +00:00
|
|
|
function scrapeAll(scenes, entity) {
|
2020-07-03 02:42:20 +00:00
|
|
|
return scenes.map((scene) => {
|
|
|
|
const release = {};
|
|
|
|
|
|
|
|
release.entryId = scene.id;
|
2020-07-08 00:53:46 +00:00
|
|
|
release.url = `${new URL(entity.url).origin}/video/${scene.id}/${scene.slug}`;
|
2020-07-03 02:42:20 +00:00
|
|
|
|
|
|
|
if (/bic/i.test(scene.title)) {
|
|
|
|
release.shootId = scene.title.toUpperCase().replace('-', '_');
|
|
|
|
} else {
|
|
|
|
release.title = scene.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
release.description = scene.description;
|
|
|
|
release.date = moment.utc(scene.year, 'YYYY').toDate();
|
|
|
|
release.datePrecision = 'year';
|
|
|
|
|
|
|
|
release.actors = scene.actors.map(actor => ({
|
2020-07-08 00:53:46 +00:00
|
|
|
name: actor.name.trim(),
|
|
|
|
avatar: actor.image || null,
|
|
|
|
})).filter(actor => actor.name && slugify(actor.name) !== 'amateur-girl');
|
2020-07-03 02:42:20 +00:00
|
|
|
|
|
|
|
release.duration = scene.duration;
|
|
|
|
release.stars = scene.video_rating_score;
|
|
|
|
|
|
|
|
[release.poster, ...release.photos] = scene.screenshots.map(url => prefixUrl(url));
|
|
|
|
|
|
|
|
if (scene.is_gay) {
|
|
|
|
release.tags = ['gay'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return release;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:01:23 +00:00
|
|
|
async function scrapeScene({ query }, url) {
|
2020-07-06 02:13:48 +00:00
|
|
|
const release = {};
|
2020-07-10 00:01:23 +00:00
|
|
|
const { pathname, origin, host } = new URL(url);
|
2020-07-06 02:13:48 +00:00
|
|
|
|
2020-07-10 00:01:23 +00:00
|
|
|
const entryId = pathname.match(/\/video\/(\d+)/)[1];
|
2020-07-06 02:13:48 +00:00
|
|
|
release.entryId = entryId;
|
|
|
|
|
|
|
|
const title = query.meta('name=title');
|
|
|
|
|
|
|
|
if (/bic/i.test(title)) {
|
|
|
|
release.shootId = title.toUpperCase().replace('-', '_');
|
|
|
|
} else {
|
|
|
|
release.title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
release.date = query.date('.detail-meta li:nth-child(2)', 'YYYY');
|
|
|
|
release.datePrecision = 'year';
|
|
|
|
|
|
|
|
release.description = query.q('.detail-description', true);
|
|
|
|
release.duration = query.dur('.detail-meta li:first-child');
|
|
|
|
|
2020-07-08 00:53:46 +00:00
|
|
|
const actors = [query.q('.detail-hero-title h1', true)?.trim()].filter(name => name && slugify(name) !== 'amateur-girl');
|
|
|
|
|
|
|
|
if (actors.length > 0) {
|
|
|
|
release.actors = actors;
|
|
|
|
}
|
2020-07-06 02:13:48 +00:00
|
|
|
|
|
|
|
release.poster = query.q('.detail-hero').style['background-image'].match(/url\((.+)\)/)[1];
|
|
|
|
release.photos = query.imgs('.detail-grabs img');
|
|
|
|
|
2020-07-10 00:01:23 +00:00
|
|
|
const streamData = await http.get(`${origin}/video/source/${entryId}`, {
|
2020-11-22 03:07:09 +00:00
|
|
|
headers: {
|
|
|
|
host,
|
|
|
|
referer: url,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
interval: 5000,
|
|
|
|
concurrency: 1,
|
|
|
|
});
|
2020-07-06 02:13:48 +00:00
|
|
|
|
|
|
|
if (streamData.ok && streamData.body.status === 'success') {
|
2020-07-10 00:01:23 +00:00
|
|
|
release.trailer = {
|
|
|
|
stream: streamData.body.link,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
logger.warn(`Failed to fetch trailer for ${url}: ${streamData.ok ? streamData.body.status : streamData.status }`);
|
2020-07-06 02:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return release;
|
|
|
|
}
|
|
|
|
|
2020-07-07 02:37:12 +00:00
|
|
|
async function scrapeProfile(actor, entity, include) {
|
|
|
|
const profile = {};
|
|
|
|
|
|
|
|
if (actor.image) {
|
|
|
|
profile.avatar = `https://teencoreclub.com${actor.image}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include.releases) {
|
|
|
|
const res = await http.get(`https://teencoreclub.com/browsevideos/api/all?actor=${actor.id}`);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
profile.releases = scrapeAll(res.body.data, entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:42:20 +00:00
|
|
|
async function fetchLatest(entity, page = 1) {
|
|
|
|
// console.log(entity, page);
|
|
|
|
|
|
|
|
if (entity.parameters?.siteId) {
|
2020-07-07 02:37:12 +00:00
|
|
|
const res = await http.get(`https://teencoreclub.com/browsevideos/api/all?resType=latest&page=${page}&label=${entity.parameters.siteId}`);
|
2020-07-03 02:42:20 +00:00
|
|
|
|
|
|
|
if (res.ok) {
|
2020-07-07 02:37:12 +00:00
|
|
|
return scrapeAll(res.body.data, entity);
|
2020-07-03 02:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-06 02:13:48 +00:00
|
|
|
async function fetchScene(url, entity) {
|
2020-07-07 02:37:12 +00:00
|
|
|
const { pathname } = new URL(url);
|
|
|
|
const res = await qu.get(`https://teencoreclub.com${pathname}`);
|
2020-07-06 02:13:48 +00:00
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
return scrapeScene(res.item, url, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status;
|
|
|
|
}
|
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
async function fetchProfile({ name: actorName }, { entity }, include) {
|
2020-07-07 02:37:12 +00:00
|
|
|
const res = await http.get(`https://teencoreclub.com/api/actors?query=${actorName}`);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
const actor = res.body.data.find(item => slugify(item.name) === slugify(actorName));
|
|
|
|
|
|
|
|
if (actor) {
|
|
|
|
return scrapeProfile(actor, entity, include);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:42:20 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2020-07-06 02:13:48 +00:00
|
|
|
fetchScene,
|
2020-07-07 02:37:12 +00:00
|
|
|
fetchProfile,
|
2020-07-03 02:42:20 +00:00
|
|
|
};
|