Moved missing slug return in Vixen scraper.

This commit is contained in:
DebaucheryLibrarian 2023-07-06 05:30:51 +02:00
parent 6e79112f3a
commit 8bb46c5a6d
1 changed files with 13 additions and 4 deletions

View File

@ -256,12 +256,20 @@ async function scrapeSceneData(data, channel, options) {
release.channel = data.site;
release.stars = data.rating;
console.log(release);
return release;
}
async function fetchGraphqlScene(release, channel) {
const slug = new URL(release.url).pathname.match(/\/videos\/(.*)/)?.[1];
if (!slug) {
return null;
}
// the API won't reliable return results when the query is over ~30 characters for some reason
// it may still occasionally fail to return the relevant result, first, such as Blacked Raw - After the Show
const query = slug.split('-').reduce((acc, word) => {
const newAcc = `${acc} ${word}`;
@ -272,21 +280,19 @@ async function fetchGraphqlScene(release, channel) {
return newAcc;
}, '').trim();
if (!slug) {
return null;
}
const res = await http.post(`${channel.url}/graphql`, {
operationName: 'searchVideos',
variables: {
site: channel.slug.toUpperCase(),
query,
},
// ranking can be weird, use higher limit to increase likelihood of finding scene
query: `
query searchVideos($site: Site!, $query: String!) {
searchVideos(input: {
query: $query
site: $site
first: 50
}) {
edges {
node {
@ -349,9 +355,12 @@ async function fetchGraphqlScene(release, channel) {
});
if (res.ok) {
console.log(res.body.data.searchVideos.edges);
return res.body.data?.searchVideos?.edges?.find((edge) => edge.node.slug === slug)?.node || null;
}
console.log(res.body);
return null;
}