forked from DebaucheryLibrarian/traxxx
169 lines
4.2 KiB
JavaScript
169 lines
4.2 KiB
JavaScript
'use strict';
|
|
|
|
const moment = require('moment');
|
|
// const fs = require('fs');
|
|
// const m3u8stream = require('m3u8stream');
|
|
|
|
// const logger = require('../logger')(__filename);
|
|
const http = require('../utils/http');
|
|
const qu = require('../utils/qu');
|
|
const slugify = require('../utils/slugify');
|
|
const { prefixUrl } = require('../utils/qu');
|
|
|
|
function scrapeAll(scenes, entity) {
|
|
return scenes.map((scene) => {
|
|
const release = {};
|
|
|
|
release.entryId = scene.id;
|
|
release.url = `${entity.url}/video/${scene.id}/${scene.slug}`;
|
|
|
|
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 => ({
|
|
name: actor.name,
|
|
avatar: actor.image,
|
|
}));
|
|
|
|
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;
|
|
});
|
|
}
|
|
|
|
async function scrapeScene({ query }, url, _entity) {
|
|
const release = {};
|
|
|
|
const entryId = new URL(url).pathname.match(/\/video\/(\d+)/)[1];
|
|
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');
|
|
|
|
release.actors = [query.q('.detail-hero-title h1', true)];
|
|
|
|
release.poster = query.q('.detail-hero').style['background-image'].match(/url\((.+)\)/)[1];
|
|
release.photos = query.imgs('.detail-grabs img');
|
|
|
|
/*
|
|
// example https://video.pictalk.com/5d13d6e5f7533152a61ee20e/2020-07-06/ab92b1e24d1c249e508bf5c73f047baf.m3u8
|
|
m3u8stream('https://video.pictalk.com/5d13d6e5f7533152a61ee20e/2020-07-06/ab92b1e24d1c249e508bf5c73f047baf.m3u8')
|
|
.pipe(fs.createWriteStream('./test.mp4'));
|
|
|
|
const streamData = await http.get(`${entity.url}/video/source/${entryId}`, {
|
|
host: new URL(entity.url).host,
|
|
referer: url,
|
|
});
|
|
|
|
if (streamData.ok && streamData.body.status === 'success') {
|
|
console.log(streamData.body);
|
|
|
|
await m3u8stream(streamData.body.link)
|
|
.pipe(fs.createWriteStream('./trailer.mp4'))
|
|
.on('progress', status => console.log(status))
|
|
.on('error', error => console.log(error));
|
|
}
|
|
|
|
if (streamData.body.status !== 'success') {
|
|
logger.warn(`Could not retrieve trailer from ${entity.name} (Teen Core Club): ${streamData.body.status}`);
|
|
}
|
|
*/
|
|
|
|
return release;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
console.log(profile);
|
|
return profile;
|
|
}
|
|
|
|
async function fetchLatest(entity, page = 1) {
|
|
// console.log(entity, page);
|
|
|
|
if (entity.parameters?.siteId) {
|
|
const res = await http.get(`https://teencoreclub.com/browsevideos/api/all?resType=latest&page=${page}&label=${entity.parameters.siteId}`);
|
|
|
|
if (res.ok) {
|
|
return scrapeAll(res.body.data, entity);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
async function fetchScene(url, entity) {
|
|
// TODO: don't assign site URL for old sites
|
|
const { pathname } = new URL(url);
|
|
const res = await qu.get(`https://teencoreclub.com${pathname}`);
|
|
|
|
if (res.ok) {
|
|
return scrapeScene(res.item, url, entity);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
async function fetchProfile(actorName, { entity }, include) {
|
|
const res = await http.get(`https://teencoreclub.com/api/actors?query=${actorName}`);
|
|
|
|
if (res.ok) {
|
|
console.log(res.body);
|
|
const actor = res.body.data.find(item => slugify(item.name) === slugify(actorName));
|
|
|
|
if (actor) {
|
|
return scrapeProfile(actor, entity, include);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchScene,
|
|
fetchProfile,
|
|
};
|