Improved tag aliasing. Added Penthouse scraper.

This commit is contained in:
DebaucheryLibrarian
2026-11-24 00:39:08 +01:00
parent 7042023c61
commit 49ea9bbec7
8 changed files with 260 additions and 14 deletions
+2
View File
@@ -29,6 +29,7 @@ const karups = require('./karups');
const kellymadison = require('./kellymadison');
const kink = require('./kink');
const mariskax = require('./mariskax');
const penthouse = require('./penthouse');
const pornbox = require('./pornbox');
const littlecapricedreams = require('./littlecapricedreams');
const loveherfilms = require('./loveherfilms');
@@ -283,4 +284,5 @@ module.exports = {
adultempire,
allherluv: missax,
manyvids,
penthouse,
};
+118
View File
@@ -0,0 +1,118 @@
'use strict';
const unprint = require('unprint');
const slugify = require('../utils/slugify');
const tryUrls = require('../utils/try-urls');
const { convert } = require('../utils/convert');
function getEntryId(url) {
return slugify(new URL(url).pathname.match(/\/scenes\/([\w-]+)/)[1]?.replace(/_vids$/, ''));
}
function scrapeAll(scenes) {
return scenes.map(({ query }) => {
const release = {};
release.url = query.url('h3 a');
release.entryId = getEntryId(release.url);
release.title = query.content('h3 a');
release.date = query.date('.scene-date', 'DD MMM YYYY', { match: null });
release.actors = query.all('.scene-models a').map((actorEl) => ({
name: unprint.query.content(actorEl),
url: unprint.query.url(actorEl, null),
}));
release.poster = query.sourceSet('a picture img');
release.teaser = query.video('.mobile_trailer source');
if (query.exists('.scene-details .ultrahdlabel')) {
release.qualities = [2160];
}
return release;
});
}
async function fetchLatest(channel, page = 1) {
const url = `${channel.origin}/categories/videos_${page}_d.html`;
const res = await unprint.get(url, { selectAll: '.scene' });
if (res.ok) {
return scrapeAll(res.context, channel);
}
return res.status;
}
const qualityMap = {
'4k': 2160,
'1080p': 1080,
'720p': 720,
sd: 480,
// hd: 540, // ???
};
function scrapeScene({ query }, { url }) {
const release = {};
release.entryId = getEntryId(url);
release.title = query.content('.video-content h1');
release.description = query.content('.panel-body p');
release.actors = query.all('.pornstars .model').map((actorEl) => ({
name: unprint.query.content(actorEl, '.model-info h3 a') || unprint.query.content(actorEl, 'a[title]'),
avatar: unprint.query.sourceSet(actorEl, 'picture img'),
}));
release.tags = query.contents('.tags a');
release.poster = query.img('#trailer_player_finished > img') || query.img('meta[itemprop="thumbnailUrl"]', { attribute: 'content' });
release.trailer = query.video('#trailer_player source') || query.video('meta[itemprop="contentURL"]', { attribute: 'content' });
release.qualities = query.contents('.panel-body .full_download_link').map((quality) => qualityMap[quality?.split(' ')[0]?.toLowerCase()]).filter(Boolean);
return release;
}
function scrapeProfile({ query }) {
const profile = {};
const bio = Object.fromEntries(query.all('.model-facts li:nth-child(n+2)').map((bioEl) => [
slugify(unprint.query.content(bioEl, 'em'), '_'),
unprint.query.text(bioEl),
]));
profile.description = query.content('.model-facts-long .toggle-text');
profile.measurements = bio.measurements;
profile.height = convert(bio.height, 'cm');
profile.avatar = query.sourceSet('.img-pornstar img');
return profile;
}
async function fetchProfile({ name: actorName, url: actorUrl }, entity) {
const { res } = await tryUrls([
actorUrl,
`https://penthousegold.com/models/${slugify(actorName, '-')}.html`,
`https://penthousegold.com/models/${slugify(actorName, '')}.html`,
]);
if (res.ok) {
return scrapeProfile(res.context, entity);
}
return res.status;
}
module.exports = {
fetchLatest,
fetchProfile,
scrapeScene,
};
+2
View File
@@ -51,6 +51,7 @@ const naughtyamerica = require('./naughtyamerica');
const newsensations = require('./newsensations');
const nubiles = require('./nubiles');
const pascalssubsluts = require('./pascalssubsluts');
const penthouse = require('./penthouse');
const perfectgonzo = require('./perfectgonzo');
const pervcity = require('./pervcity');
const pierrewoodman = require('./pierrewoodman');
@@ -161,6 +162,7 @@ module.exports = {
newsensations,
nubiles,
pascalssubsluts,
penthouse,
perfectgonzo,
pervcity,
pierrewoodman,
+57 -5
View File
@@ -86,7 +86,8 @@ async function matchTags(rawTags) {
// array binding, large batches can easily exceed the bindings limit otherwise
const tagEntries = await knex('tags')
.select('tags.id', 'tags.name', 'tags.alias_for', 'tags.implied_tag_ids')
.whereRaw('lower(tags.name) = ANY(:tags)', { tags });
// normalize stored names the same way as the input, otherwise names with other characters (b/b/g, p.o.v.) never match
.whereRaw('trim(regexp_replace(lower(tags.name), \'[^a-z0-9()-]+\', \' \', \'g\')) = ANY(:tags)', { tags });
const tagIdsBySlug = tagEntries
.reduce((acc, tag) => ({
@@ -97,6 +98,41 @@ async function matchTags(rawTags) {
return tagIdsBySlug;
}
// implied tag IDs per matched slug, including the implications of an alias' main tag and implications of implied tags
async function matchImpliedTags(tagIdsBySlug) {
const implications = await knex('tags')
.select('id', 'name', 'implied_tag_ids')
.whereRaw('cardinality(implied_tag_ids) > 0');
if (implications.length === 0) {
return {};
}
const impliedIdsById = Object.fromEntries(implications.map((tag) => [tag.id, tag.implied_tag_ids.filter(Boolean)]));
const aliasImpliedIdsBySlug = Object.fromEntries(implications.map((tag) => [slugify(tag.name), tag.implied_tag_ids.filter(Boolean)]));
function resolve(tagIds, seen = new Set()) {
tagIds.forEach((tagId) => {
if (seen.has(tagId)) {
return;
}
seen.add(tagId);
resolve(impliedIdsById[tagId] || [], seen);
});
return seen;
}
return Object.fromEntries(Object.entries(tagIdsBySlug).map(([slug, tagId]) => {
const impliedIds = resolve([tagId, ...(aliasImpliedIdsBySlug[slug] || [])]);
impliedIds.delete(tagId);
return [slug, Array.from(impliedIds)];
}).filter(([, impliedIds]) => impliedIds.length > 0));
}
async function getEntityTags(releases) {
const entityIds = Array.from(new Set(releases.map((release) => release.entity?.id).filter(Boolean)));
@@ -121,7 +157,21 @@ async function getEntityTags(releases) {
return entityTagIdsByEntityId;
}
function buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntityId, type) {
function buildImpliedTagAssociations(release, tags, impliedIdsBySlug, type) {
const tagIds = new Set(tags.map((tag) => tag.tag_id).filter(Boolean));
const impliedIds = Array.from(new Set(tags.flatMap((tag) => (tag.original_tag && impliedIdsBySlug[slugify(tag.original_tag)]) || [])))
.filter((tagId) => !tagIds.has(tagId));
return impliedIds.map((tagId) => ({
[`${type}_id`]: release.id,
tag_id: tagId,
original_tag: null, // implied rows are not rematched by original tag
...(type === 'chapter' ? {} : { source: 'implied' }), // chapters_tags has no source column
}));
}
function buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntityId, type, impliedIdsBySlug = {}) {
const tagAssociations = releases
.map((release) => {
const entityTagIds = entityTagIdsByEntityId[release.entity?.id]?.map((tag) => ({ id: tag.id, original: tag.name })) || [];
@@ -146,7 +196,7 @@ function buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntit
original_tag: tag.original,
}));
return tags;
return tags.concat(buildImpliedTagAssociations(release, tags, impliedIdsBySlug, type));
})
.flat();
@@ -158,10 +208,12 @@ async function associateReleaseTags(releases, type = 'release') {
return {};
}
const tagIdsBySlug = await matchTags(releases.flatMap((release) => release.tags));
const rawTags = releases.flatMap((release) => release.tags);
const entityTagIdsByEntityId = await getEntityTags(releases);
const tagIdsBySlug = await matchTags(rawTags.concat(Object.values(entityTagIdsByEntityId).flat().map((tag) => tag.name)));
const impliedIdsBySlug = await matchImpliedTags(tagIdsBySlug);
const tagAssociations = buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntityId, type);
const tagAssociations = buildReleaseTagAssociations(releases, tagIdsBySlug, entityTagIdsByEntityId, type, impliedIdsBySlug);
await batchInsert(`${type}s_tags`, tagAssociations, { conflict: false });