Fetching old scene links from Vivid search API.

This commit is contained in:
2020-02-11 19:05:12 +01:00
parent 4caf0dbe95
commit df4a2b0bb3
2 changed files with 47 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ const bhttp = require('bhttp');
const { get, date } = require('../utils/q');
const { fetchApiLatest, fetchApiUpcoming, fetchScene, fetchApiProfile } = require('./gamma');
const slugify = require('../utils/slugify');
function scrapeLatestNative(scenes, site) {
return scenes.map((scene) => {
@@ -103,6 +104,26 @@ async function fetchSceneNative(url, site, release) {
async function fetchSceneWrapper(url, site, release) {
const scene = await fetchScene(url, site, release);
if (scene.date - new Date(site.parameters.lastNative) <= 0) {
// scene is probably still available on Vivid site, use search API to get URL and original date
const searchUrl = `${site.url}/videos/api/?limit=10&sort=datedesc&search=${encodeURI(scene.title)}`;
const searchRes = await bhttp.get(searchUrl, {
decodeJSON: true,
});
if (searchRes.statusCode === 200 && searchRes.body.code === 200) {
const sceneMatch = searchRes.body.responseData.find(item => slugify(item.name) === slugify(scene.title));
if (sceneMatch) {
return {
...scene,
url: `${site.url}${sceneMatch.url}`,
date: date(sceneMatch.release_date, 'YYYY-MM-DD'),
};
}
}
}
return scene;
}