Scraping scene photos from Bang API.

This commit is contained in:
DebaucheryLibrarian
2021-02-04 22:55:19 +01:00
parent 4594dbc763
commit f217b161b4
12 changed files with 39 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const http = require('../utils/http');
const qu = require('../utils/qu');
const { extractDate } = require('../utils/qu');
const { inchesToCm } = require('../utils/convert');
const slugify = require('../utils/slugify');
@@ -37,7 +38,23 @@ function decodeId(id) {
.toString('hex');
}
function scrapeScene(scene) {
async function fetchPhotos(scene) {
const photoPaths = Array.from({ length: scene.photos }, (value, index) => `/${scene.dvd.id}/${scene.identifier}/final/${String(index + 1).padStart(6, '0')}.jpg`);
const res = await http.post('https://www.bang.com/sign-images', {
images: photoPaths,
}, {
encodeJSON: false,
});
if (res.ok) {
return res.body.images.map(image => qu.prefixUrl(image, 'https://photos.bang.com'));
}
return null;
}
async function scrapeScene(scene, entity, options) {
const release = {
entryId: scene.id,
title: scene.name,
@@ -58,17 +75,23 @@ function scrapeScene(scene) {
if (scene.gay) release.tags.push('gay');
const defaultPoster = scene.screenshots.find(photo => photo.default === true);
const photoset = scene.screenshots.filter(photo => photo.default === false);
const screens = scene.screenshots.filter(photo => photo.default === false);
const photos = defaultPoster ? photoset : photoset.slice(1);
const poster = defaultPoster || photoset[0];
const remainingScreens = defaultPoster ? screens : screens.slice(1);
const poster = defaultPoster || screens[0];
release.poster = getScreenUrl(poster, scene);
release.photos = photos.map(photo => getScreenUrl(photo, scene));
release.photos = remainingScreens.map(photo => getScreenUrl(photo, scene));
release.trailer = {
src: `https://i.bang.com/v/${scene.dvd.id}/${scene.identifier}/preview.mp4`,
};
if (options.includePhotos) {
const photos = await fetchPhotos(scene);
if (photos?.length > 0) {
release.photos = photos;
}
}
release.trailer = `https://i.bang.com/v/${scene.dvd.id}/${scene.identifier}/preview.mp4`;
release.channel = scene.series.name
.replace(/[! .]/g, '')
@@ -328,7 +351,7 @@ async function fetchUpcoming(site, page = 1) {
return scrapeAll(res.body.hits.hits, site);
}
async function fetchScene(url) {
async function fetchScene(url, entity, baseRelease, options) {
const encodedId = new URL(url).pathname.split('/')[2];
const entryId = decodeId(encodedId);
@@ -338,7 +361,7 @@ async function fetchScene(url) {
},
});
return scrapeScene(res.body._source); // eslint-disable-line no-underscore-dangle
return scrapeScene(res.body._source, entity, options); // eslint-disable-line no-underscore-dangle
}
async function fetchProfile({ name: actorName }, context, include) {