From 20129eca5d2253cb10628e1987df8267e7e7f608 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 26 Feb 2021 02:52:39 +0100 Subject: [PATCH] Fixed Bang scraper. --- migrations/20190325001339_releases.js | 3 ++- src/scrapers/bang.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/migrations/20190325001339_releases.js b/migrations/20190325001339_releases.js index 35f93264..146995c7 100644 --- a/migrations/20190325001339_releases.js +++ b/migrations/20190325001339_releases.js @@ -1001,7 +1001,8 @@ exports.up = knex => Promise.resolve() // allow vim fold return knex.raw(` /* We need both the release entries and their search ranking, and PostGraphile does not seem to allow virtual foreign keys on function results. - * Using a view as a proxy for the search results allows us to get both a reference to the releases table, and the ranking */ + * Using a view as a proxy for the search results allows us to get both a reference to the releases table, and the ranking. + * A composite type does not seem to be compatible with PostGraphile's @sortable. */ CREATE VIEW releases_search_results AS SELECT NULL::integer as id, NULL::real as rank; diff --git a/src/scrapers/bang.js b/src/scrapers/bang.js index 8d075cb1..34665ae0 100644 --- a/src/scrapers/bang.js +++ b/src/scrapers/bang.js @@ -83,7 +83,7 @@ async function scrapeScene(scene, entity, options) { release.poster = getScreenUrl(poster, scene); release.photos = remainingScreens.map(photo => getScreenUrl(photo, scene)); - if (options.includePhotos) { + if (options?.includePhotos) { const photos = await fetchPhotos(scene); if (photos?.length > 0) { @@ -100,11 +100,11 @@ async function scrapeScene(scene, entity, options) { return release; } -function scrapeAll(scenes) { - return scenes.map(({ _source: scene }) => scrapeScene(scene)); +function scrapeAll(scenes, entity) { + return scenes.map(({ _source: scene }) => scrapeScene(scene, entity)); } -async function fetchActorReleases(actor) { +async function fetchActorReleases(actor, entity) { const res = await http.post(`https://${clusterId}.us-east-1.aws.found.io/videos/video/_search`, { size: 50, query: { @@ -158,10 +158,10 @@ async function fetchActorReleases(actor) { }, }); - return scrapeAll(res.body.hits.hits); + return scrapeAll(res.body.hits.hits, entity); } -async function scrapeProfile(actor, include) { +async function scrapeProfile(actor, entity, include) { const profile = {}; profile.aliases = actor.aliases; @@ -193,7 +193,7 @@ async function scrapeProfile(actor, include) { if (actor.image) profile.avatar = `https://i.bang.com/pornstars/${actor.identifier}.jpg`; if (include.releases) { - profile.releases = await fetchActorReleases(actor); + profile.releases = await fetchActorReleases(actor, entity); } return profile; @@ -402,7 +402,7 @@ async function fetchProfile({ name: actorName }, context, include) { const actor = res.body.hits.hits.find(hit => hit._source.name.toLowerCase() === actorName.toLowerCase()); if (actor) { - return scrapeProfile(actor._source, include); + return scrapeProfile(actor._source, context.entity, include); } return null;