traxxx/src/scrapers/topwebmodels.js

145 lines
4.0 KiB
JavaScript
Raw Normal View History

2021-01-14 01:10:35 +00:00
'use strict';
2021-02-11 00:46:11 +00:00
const mime = require('mime');
2021-01-14 01:10:35 +00:00
const qu = require('../utils/qu');
const http = require('../utils/http');
const slugify = require('../utils/slugify');
2021-01-16 03:10:43 +00:00
const { convert } = require('../utils/convert');
2021-01-14 01:10:35 +00:00
function scrapeSceneX(scene) {
const release = {};
2021-01-14 01:10:35 +00:00
release.entryId = scene.id;
release.url = `https://tour.topwebmodels.com/scenes/${scene.id}/${slugify(scene.title, '-', { removePunctuation: true })}`;
2021-01-14 01:10:35 +00:00
release.title = scene.title;
release.description = scene.description;
2021-01-14 01:10:35 +00:00
release.duration = qu.durationToSeconds(scene.videos_duration);
release.date = new Date(scene.release_date);
2021-01-14 01:10:35 +00:00
release.actors = scene.models
.map((actor) => (/&/.test(actor.name)
? actor.name.split(/\s*&\s*/)
: {
name: actor.name,
gender: actor.gender || null,
avatar: actor.thumb,
url: `https://tour.topwebmodels.com/models/${actor.id}/${slugify(actor.name)}`,
}))
.flat();
2021-01-14 01:10:35 +00:00
release.stars = scene.rating;
release.tags = scene.tags.map((tag) => tag.name);
2021-01-14 01:10:35 +00:00
2021-02-11 00:46:11 +00:00
if (mime.getType(scene.thumb) === 'image/gif') {
release.teaser = scene.thumb;
} else {
release.poster = scene.thumb;
}
2021-01-14 01:10:35 +00:00
release.channel = slugify(scene.sites[0]?.name, '');
2021-01-14 01:10:35 +00:00
return release;
2021-01-14 01:10:35 +00:00
}
function scrapeAll(scenes) {
return scenes.map(scrapeSceneX);
}
2021-01-14 01:10:35 +00:00
2021-01-16 03:10:43 +00:00
async function scrapeProfile(actor, options) {
const profile = {};
profile.dateOfBirth = /1969-12-31/.test(actor.attributes.birthdate.value) ? null : qu.extractDate(actor.attributes.birthdate.value, 'YYYY-MM-DD'); // ignore epoch
profile.age = actor.attributes.age.value === 51 ? null : actor.attributes.age.value; // ignore epoch
profile.gender = actor.attributes.gender || null;
profile.height = convert(actor.attributes.height.value, 'cm');
profile.weight = convert(actor.attributes.weight.value, 'lb', 'kg');
const [bust, cup, waist, hip] = actor.attributes.measurements.value?.match(/(\d+)(\w+)-(\d+)-(\d+)/)?.slice(1) || [];
profile.bust = Number(bust);
profile.cup = cup;
profile.waist = Number(waist);
profile.hip = Number(hip);
profile.ethnicity = actor.attributes.ethnicity.value;
profile.birthPlace = actor.attributes.born.value;
profile.eyes = actor.attributes.eyes.value;
profile.hairColor = actor.attributes.hair.value.split('/')[0];
profile.url = `https://tour.topwebmodels.com/models/${actor.id}/${slugify(actor.name, '-', { removePunctuation: true })}`;
profile.avatar = actor.thumb;
if (options.includeActorScenes) {
const res = await http.get(profile.url, { extract: { runScripts: 'dangerously' } });
if (res.ok) {
profile.scenes = scrapeAll(res.window.__DATA__?.data?.videos?.items);
}
}
return profile;
}
async function fetchLatest(channel, page) {
2021-01-14 01:10:35 +00:00
const res = await http.get(`https://tour.topwebmodels.com/api/sites/${channel.parameters?.slug || channel.slug}?page=${page}`, {
headers: {
Referer: 'https://tour.topwebmodels.com',
'api-key': channel.parameters?.apiKey || channel.parent?.parameters?.apiKey,
'x-Requested-With': 'XMLHttpRequest',
},
2021-01-14 01:10:35 +00:00
});
if (res.ok) {
return scrapeAll(res.body.videos.items);
}
return res.status;
}
async function fetchScene(url) {
const res = await http.get(url, { extract: { runScripts: 'dangerously' } });
if (res.ok) {
return {
...scrapeSceneX(res.window.__DATA__.data.video),
...(/\.gif/.test(res.window.__DATA__.data.video.thumb) && { teaser: res.window.__DATA__.data.video.thumb }),
poster: res.window.__DATA__.data.file_poster,
};
}
return res.status;
}
2021-01-16 03:10:43 +00:00
async function fetchProfile(baseActor, entity, options) {
const searchRes = await http.get(`https://tour.topwebmodels.com/api/search-preview/${baseActor.name}`, {
headers: {
Referer: 'https://tour.topwebmodels.com',
'api-key': entity.parameters?.apiKey,
'x-Requested-With': 'XMLHttpRequest',
},
});
if (!searchRes.ok) {
return searchRes.status;
}
const actor = searchRes.body.models.items.find((model) => slugify(model.name) === slugify(baseActor.name));
2021-01-16 03:10:43 +00:00
if (actor) {
return scrapeProfile(actor, options);
}
return null;
}
2021-01-14 01:10:35 +00:00
module.exports = {
fetchLatest,
fetchScene,
2021-01-16 03:10:43 +00:00
fetchProfile,
2021-01-14 01:10:35 +00:00
};