traxxx/src/scrapers/topwebmodels.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-01-14 01:10:35 +00:00
'use strict';
const qu = require('../utils/qu');
const http = require('../utils/http');
const slugify = require('../utils/slugify');
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 => ({
name: actor.name,
gender: actor.gender || null,
avatar: actor.thumb,
url: `https://tour.topwebmodels.com/models/${actor.id}/${slugify(actor.name)}`,
}));
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
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
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-14 01:10:35 +00:00
module.exports = {
fetchLatest,
fetchScene,
2021-01-14 01:10:35 +00:00
};