2020-01-06 04:19:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const slugify = require('../utils/slugify');
|
|
|
|
|
|
|
|
const clusterId = '617fb597b659459bafe6472470d9073a';
|
|
|
|
const authKey = 'YmFuZy1yZWFkOktqVDN0RzJacmQ1TFNRazI=';
|
|
|
|
|
2020-02-09 22:25:54 +00:00
|
|
|
const genderMap = {
|
|
|
|
M: 'male',
|
|
|
|
F: 'female',
|
|
|
|
};
|
|
|
|
|
2020-01-08 04:12:14 +00:00
|
|
|
function getScreenUrl(item, scene) {
|
|
|
|
return `https://i.bang.com/screenshots/${scene.dvd.id}/movie/${scene.order}/${item.screenId}.jpg`;
|
|
|
|
}
|
|
|
|
|
2020-01-06 04:19:38 +00:00
|
|
|
function encodeId(id) {
|
|
|
|
return Buffer
|
|
|
|
.from(id, 'hex')
|
|
|
|
.toString('base64')
|
|
|
|
.replace(/\+/g, '-')
|
|
|
|
.replace(/\//g, '_')
|
|
|
|
.replace(/=/g, ',');
|
|
|
|
}
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
function decodeId(id) {
|
|
|
|
const restoredId = id
|
|
|
|
.replace(/-/g, '+')
|
|
|
|
.replace(/_/g, '/')
|
|
|
|
.replace(/,/g, '=');
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
return Buffer
|
|
|
|
.from(restoredId, 'base64')
|
|
|
|
.toString('hex');
|
|
|
|
}
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
function scrapeScene(scene, site) {
|
|
|
|
const release = {
|
|
|
|
site,
|
|
|
|
entryId: scene.id,
|
|
|
|
title: scene.name,
|
|
|
|
description: scene.description,
|
|
|
|
tags: scene.genres.concat(scene.actions).map(genre => genre.name),
|
|
|
|
duration: scene.duration,
|
|
|
|
};
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const slug = slugify(release.title);
|
|
|
|
release.url = `https://www.bang.com/video/${encodeId(release.entryId)}/${slug}`;
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const date = new Date(scene.releaseDate);
|
|
|
|
release.date = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-02-09 22:25:54 +00:00
|
|
|
release.actors = scene.actors.map(actor => ({ name: actor.name, gender: genderMap[actor.gender] }));
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
if (scene.is4k) release.tags.push('4k');
|
|
|
|
if (scene.gay) release.tags.push('gay');
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const defaultPoster = scene.screenshots.find(photo => photo.default === true);
|
|
|
|
const photoset = scene.screenshots.filter(photo => photo.default === false);
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
const photos = defaultPoster ? photoset : photoset.slice(1);
|
|
|
|
const poster = defaultPoster || photoset[0];
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-08 04:12:14 +00:00
|
|
|
release.poster = getScreenUrl(poster, scene);
|
|
|
|
release.photos = photos.map(photo => getScreenUrl(photo, scene));
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
release.trailer = {
|
|
|
|
src: `https://i.bang.com/v/${scene.dvd.id}/${scene.identifier}/preview.mp4`,
|
|
|
|
};
|
|
|
|
|
|
|
|
release.channel = scene.series.name
|
|
|
|
.replace(/[! .]/g, '')
|
|
|
|
.replace('&', 'and');
|
|
|
|
|
|
|
|
return release;
|
2020-01-06 04:19:38 +00:00
|
|
|
}
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
function scrapeLatest(scenes, site) {
|
|
|
|
return scenes.map(({ _source: scene }) => scrapeScene(scene, site));
|
|
|
|
}
|
2020-01-06 04:19:38 +00:00
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
2020-01-06 04:19:38 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-07 03:23:28 +00:00
|
|
|
/*
|
|
|
|
* global fetch
|
2020-01-06 04:19:38 +00:00
|
|
|
{
|
|
|
|
nested: {
|
|
|
|
path: 'studio',
|
|
|
|
query: {
|
|
|
|
bool: {
|
|
|
|
must: [
|
|
|
|
{
|
|
|
|
match: {
|
|
|
|
'studio.name': {
|
|
|
|
operator: 'AND',
|
|
|
|
query: 'bang! originals',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-07 03:23:28 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
nested: {
|
|
|
|
path: 'series',
|
|
|
|
query: {
|
|
|
|
bool: {
|
|
|
|
must: [
|
|
|
|
{
|
|
|
|
match: {
|
|
|
|
'series.id': {
|
|
|
|
operator: 'AND',
|
|
|
|
query: site.parameters.siteId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-06 04:19:38 +00:00
|
|
|
],
|
|
|
|
must_not: [
|
|
|
|
{
|
|
|
|
match: {
|
|
|
|
type: 'trailer',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sort: [
|
|
|
|
{
|
|
|
|
releaseDate: {
|
|
|
|
order: 'desc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}, {
|
|
|
|
encodeJSON: true,
|
|
|
|
headers: {
|
|
|
|
Authorization: `Basic ${authKey}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return scrapeLatest(res.body.hits.hits, site);
|
|
|
|
}
|
|
|
|
|
2020-01-07 03:23:28 +00:00
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const encodedId = new URL(url).pathname.split('/')[2];
|
|
|
|
const entryId = decodeId(encodedId);
|
|
|
|
|
|
|
|
const res = await bhttp.get(`https://${clusterId}.us-east-1.aws.found.io/videos/video/${entryId}`, {
|
|
|
|
headers: {
|
|
|
|
Authorization: `Basic ${authKey}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return scrapeScene(res.body._source, site); // eslint-disable-line no-underscore-dangle
|
|
|
|
}
|
|
|
|
|
2020-01-06 04:19:38 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2020-01-07 03:23:28 +00:00
|
|
|
fetchScene,
|
2020-01-06 04:19:38 +00:00
|
|
|
};
|