2020-07-03 02:42:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-06 02:13:48 +00:00
|
|
|
const fs = require('fs');
|
2020-07-03 02:42:20 +00:00
|
|
|
const moment = require('moment');
|
2020-07-06 02:13:48 +00:00
|
|
|
const m3u8stream = require('m3u8stream');
|
2020-07-03 02:42:20 +00:00
|
|
|
|
2020-07-06 02:13:48 +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-03 02:42:20 +00:00
|
|
|
const { prefixUrl } = require('../utils/qu');
|
|
|
|
|
|
|
|
function scrapeLatest(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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-06 02:13:48 +00:00
|
|
|
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');
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:42:20 +00:00
|
|
|
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=all&page=${page}&label=${entity.parameters.siteId}`);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
return scrapeLatest(res.body.data, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-06 02:13:48 +00:00
|
|
|
async function fetchScene(url, entity) {
|
|
|
|
const res = await qu.get(url);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
return scrapeScene(res.item, url, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03 02:42:20 +00:00
|
|
|
};
|