Added movie support to MindGeek scraper.
This commit is contained in:
@@ -11,6 +11,12 @@ const slugify = require('../utils/slugify');
|
||||
const http = require('../utils/http');
|
||||
const { inchesToCm, lbsToKg } = require('../utils/convert');
|
||||
|
||||
function getBasePath(channel, path = '/scene') {
|
||||
return channel.parameters?.scene
|
||||
|| ((channel.parameters?.native || channel.type === 'network') && `${channel.url}${path}`)
|
||||
|| `${channel.parent.url}${path}`;
|
||||
}
|
||||
|
||||
function getThumbs(scene) {
|
||||
if (scene.images.poster) {
|
||||
return Object.values(scene.images.poster) // can be { 0: {}, 1: {}, ... } instead of array
|
||||
@@ -18,7 +24,7 @@ function getThumbs(scene) {
|
||||
.map((image) => image.xl.url);
|
||||
}
|
||||
|
||||
if (scene.images.card_main_rect) {
|
||||
if (Array.isArray(scene.images.card_main_rect)) {
|
||||
return scene.images.card_main_rect
|
||||
.concat(scene.images.card_secondary_rect || [])
|
||||
.map((image) => image.xl.url.replace('.thumb', ''));
|
||||
@@ -27,6 +33,20 @@ function getThumbs(scene) {
|
||||
return [];
|
||||
}
|
||||
|
||||
function getCovers(images) {
|
||||
return [
|
||||
[
|
||||
images.cover[0].md?.url,
|
||||
images.cover[0].sm?.url,
|
||||
images.cover[0].xs?.url,
|
||||
// bigger but usually upscaled
|
||||
images.cover[0].xx?.url,
|
||||
images.cover[0].xl?.url,
|
||||
images.cover[0].lg?.url,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
function getVideos(data) {
|
||||
const teaserSources = data.videos.mediabook?.files;
|
||||
const trailerSources = data.children.find((child) => child.type === 'trailer')?.videos.full?.files;
|
||||
@@ -51,9 +71,7 @@ function scrapeLatestX(data, site, filterChannel) {
|
||||
description: data.description,
|
||||
};
|
||||
|
||||
const basepath = site.parameters?.scene
|
||||
|| (site.parameters?.native && `${site.url}/scene`)
|
||||
|| `${site.parent.url}/scene`;
|
||||
const basepath = getBasePath(site);
|
||||
|
||||
release.url = `${basepath}/${release.entryId}/${slugify(release.title)}`;
|
||||
release.date = new Date(data.dateReleased);
|
||||
@@ -96,7 +114,7 @@ async function scrapeLatest(items, site, filterChannel) {
|
||||
};
|
||||
}
|
||||
|
||||
function scrapeScene(data, url, _site, networkName) {
|
||||
function scrapeRelease(data, url, channel, networkName) {
|
||||
const release = {};
|
||||
|
||||
const { id: entryId, title, description } = data;
|
||||
@@ -129,6 +147,29 @@ function scrapeScene(data, url, _site, networkName) {
|
||||
|
||||
release.url = url || `https://www.${networkName || data.brand}.com/scene/${entryId}/`;
|
||||
|
||||
if (data.parent?.type === 'movie') {
|
||||
release.movie = {
|
||||
entryId: data.parent.id,
|
||||
url: `${getBasePath(channel, '/movie')}/${data.parent.id}/${slugify(data.parent.title, '-', { removePunctuation: true })}`,
|
||||
title: data.parent.title,
|
||||
description: data.parent.description,
|
||||
date: new Date(data.parent.dateReleased),
|
||||
channel: slugify(data.parent.collections?.name || data.parent.brand),
|
||||
covers: getCovers(data.parent.images),
|
||||
shallow: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (data.type === 'movie') {
|
||||
release.covers = getCovers(data.images);
|
||||
release.scenes = data.children?.map((scene) => ({
|
||||
entryId: scene.id,
|
||||
url: `${getBasePath(channel)}/${scene.id}/${slugify(scene.title)}`,
|
||||
title: scene.title,
|
||||
shallow: true,
|
||||
}));
|
||||
}
|
||||
|
||||
return release;
|
||||
}
|
||||
|
||||
@@ -230,7 +271,7 @@ function scrapeProfile(data, html, releases = [], networkName) {
|
||||
profile.naturalBoobs = false;
|
||||
}
|
||||
|
||||
profile.releases = releases.map((release) => scrapeScene(release, null, null, networkName));
|
||||
profile.releases = releases.map((release) => scrapeRelease(release, null, null, networkName));
|
||||
|
||||
return profile;
|
||||
}
|
||||
@@ -292,8 +333,8 @@ async function fetchUpcoming(site, page, options) {
|
||||
return res.statusCode;
|
||||
}
|
||||
|
||||
async function fetchScene(url, site, baseScene, options) {
|
||||
if (baseScene?.entryId) {
|
||||
async function fetchRelease(url, site, baseScene, options) {
|
||||
if (baseScene?.entryId && !baseScene.shallow) {
|
||||
// overview and deep data is the same, don't hit server unnecessarily
|
||||
return baseScene;
|
||||
}
|
||||
@@ -312,7 +353,7 @@ async function fetchScene(url, site, baseScene, options) {
|
||||
|
||||
if (res.status === 200 && res.body.result) {
|
||||
return {
|
||||
scene: scrapeScene(res.body.result, url, site),
|
||||
scene: scrapeRelease(res.body.result, url, site),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -374,6 +415,7 @@ module.exports = {
|
||||
scrapeLatestX,
|
||||
fetchLatest,
|
||||
fetchUpcoming,
|
||||
fetchScene,
|
||||
fetchScene: fetchRelease,
|
||||
fetchMovie: fetchRelease,
|
||||
fetchProfile,
|
||||
};
|
||||
|
||||
@@ -142,6 +142,7 @@ async function getTrailer(scene, channel, url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
async function getPhotosLegacy(url) {
|
||||
const htmlRes = await http.get(url, {
|
||||
extract: {
|
||||
@@ -169,6 +170,7 @@ async function getPhotosLegacy(url) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
async function getPhotos(url) {
|
||||
const htmlRes = await http.get(url, {
|
||||
|
||||
Reference in New Issue
Block a user