128 lines
4.0 KiB
JavaScript
128 lines
4.0 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const bhttp = require('bhttp');
|
||
|
|
||
|
function encodeId(id) {
|
||
|
return Buffer
|
||
|
.from(id, 'hex')
|
||
|
.toString('base64')
|
||
|
.replace(/\+/g, '-')
|
||
|
.replace(/\//g, '_')
|
||
|
.replace(/=/g, ',');
|
||
|
}
|
||
|
|
||
|
function scrapeLatest(scenes, site) {
|
||
|
return scenes.map(({ _source: scene }) => {
|
||
|
const release = {
|
||
|
site,
|
||
|
entryId: encodeId(scene.id),
|
||
|
title: scene.name,
|
||
|
description: scene.description,
|
||
|
actors: scene.actors.map(actor => actor.name),
|
||
|
tags: scene.genres.concat(scene.actions).map(genre => genre.name),
|
||
|
duration: scene.duration,
|
||
|
};
|
||
|
|
||
|
const slug = release.title.toLowerCase().trim().replace(/\s+/g, '-');
|
||
|
release.url = `https://www.bang.com/video/${release.entryId}/${slug}`;
|
||
|
|
||
|
const date = new Date(scene.releaseDate);
|
||
|
release.date = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
||
|
|
||
|
if (scene.is4k) release.tags.push('4k');
|
||
|
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 photos = defaultPoster ? photoset : photoset.slice(1);
|
||
|
const poster = defaultPoster || photoset[0];
|
||
|
|
||
|
release.poster = `https://i.bang.com/screenshots/${scene.dvd.id}/movie/1/${poster.screenId}.jpg`;
|
||
|
release.photos = photos.map(photo => `https://i.bang.com/screenshots/${scene.dvd.id}/movie/1/${photo.screenId}.jpg`);
|
||
|
|
||
|
release.trailer = {
|
||
|
src: `https://i.bang.com/v/${scene.dvd.id}/${scene.identifier}/preview.mp4`,
|
||
|
};
|
||
|
|
||
|
release.studio = scene.series.name
|
||
|
.replace(/[! .]/g, '')
|
||
|
.replace('&', 'and');
|
||
|
|
||
|
return release;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async function fetchLatest(site, page = 1) {
|
||
|
const clusterId = '617fb597b659459bafe6472470d9073a';
|
||
|
const authKey = 'YmFuZy1yZWFkOktqVDN0RzJacmQ1TFNRazI=';
|
||
|
|
||
|
const res = await bhttp.post(`https://${clusterId}.us-east-1.aws.found.io/videos/video/_search`, {
|
||
|
size: 50,
|
||
|
from: (page - 1) * 50,
|
||
|
query: {
|
||
|
bool: {
|
||
|
must: [
|
||
|
{
|
||
|
match: {
|
||
|
status: 'ok',
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
range: {
|
||
|
releaseDate: {
|
||
|
lte: 'now',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
nested: {
|
||
|
path: 'studio',
|
||
|
query: {
|
||
|
bool: {
|
||
|
must: [
|
||
|
{
|
||
|
match: {
|
||
|
'studio.name': {
|
||
|
operator: 'AND',
|
||
|
query: 'bang! originals',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
must_not: [
|
||
|
{
|
||
|
match: {
|
||
|
type: 'trailer',
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
sort: [
|
||
|
{
|
||
|
releaseDate: {
|
||
|
order: 'desc',
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
}, {
|
||
|
encodeJSON: true,
|
||
|
headers: {
|
||
|
Authorization: `Basic ${authKey}`,
|
||
|
},
|
||
|
});
|
||
|
|
||
|
return scrapeLatest(res.body.hits.hits, site);
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
fetchLatest,
|
||
|
// fetchScene,
|
||
|
};
|