diff --git a/seeds/00_tags.js b/seeds/00_tags.js index c22207f9..3bdb051b 100755 --- a/seeds/00_tags.js +++ b/seeds/00_tags.js @@ -928,9 +928,9 @@ const tags = [ group: 'position', }, { - name: 'natural tits', - slug: 'natural-tits', - rename: 'natural-boobs', + name: 'natural boobs', + slug: 'natural-boobs', + rename: 'natural-tits', group: 'body', }, { @@ -1757,9 +1757,8 @@ const aliases = [ for: 'big-butt', }, { - name: 'natural boobs', - for: 'natural-tits', - slug: 'natural-boobs', + name: 'natural tits', + for: 'natural-boobs', }, { name: 'big natural tits', @@ -2331,7 +2330,7 @@ const aliases = [ }, { name: 'natural', - for: 'natural-tits', + for: 'natural-boobs', }, { name: 'natural butt', @@ -3229,12 +3228,28 @@ const aliases = [ name: 'pleaser heels', for: 'pleasers', }, + { + name: 'b/b/g', + for: 'mfm', + }, + { + name: 'boobs - natural', + for: 'natural-boobs', + }, + { + name: 'cumshot - facial', + for: 'facial', + }, + { + name: 'ethnicity - caucasion', + for: 'white', + }, ]; const priorities = [ // higher index is higher priority ['blonde', 'brunette', 'black-hair', 'redhead'], ['asian', 'black', 'latina', 'white', 'interracial'], - ['fake-tits', 'natural-tits'], + ['fake-tits', 'natural-boobs'], ['bts'], ['blowjob', 'deepthroat', 'oil'], ['toys', 'toy-anal', 'toy-dp', 'piss-drinking'], @@ -3257,18 +3272,62 @@ const priorities = [ // higher index is higher priority return acc; }, {}); +// tables referencing a tag, with the columns that make a tag link unique besides tag_id +const tagReferences = { + releases_tags: ['release_id', 'actor_id'], + movies_tags: ['movie_id'], + chapters_tags: ['chapter_id'], + entities_tags: ['entity_id'], + alerts_tags: ['alert_id'], + feeds_tags: null, // no unique constraint + banners_tags: ['banner_id'], + tags_photos: ['media_id'], + tags_posters: [], // one poster per tag +}; + +// re-point everything linked to the aliases that are about to be deleted, instead of failing on foreign keys or losing cascaded links +async function moveTagReferences(knex, fromIds, toId) { + await Object.entries(tagReferences).reduce(async (chain, [table, uniqueColumns]) => { + await chain; + + const conflict = uniqueColumns + ? `AND NOT EXISTS (SELECT 1 FROM ${table} existing WHERE existing.tag_id = :toId ${uniqueColumns.map((column) => `AND existing.${column} IS NOT DISTINCT FROM ${table}.${column}`).join(' ')})` + : ''; + + await knex.raw(`UPDATE ${table} SET tag_id = :toId WHERE tag_id = ANY(:fromIds) ${conflict}`, { toId, fromIds }); + + // whatever is left already exists on the target tag + await knex(table).whereIn('tag_id', fromIds).delete(); + }, Promise.resolve()); + + await knex('tags').whereIn('alias_for', fromIds).update({ alias_for: toId }); +} + exports.seed = (knex) => Promise.resolve() .then(async () => upsert('tags_groups', groups, 'slug', knex)) .then(async () => { await Promise.all(tags.map((async (tag) => { if (tag.rename) { - await knex('tags') + const target = await knex('tags') + .where('slug', tag.rename) + .whereNull('alias_for') + .first(); + + const conflictingAliases = await knex('tags') .where((builder) => { builder .where('slug', tag.slug) .orWhere('name', tag.name); }) .whereNotNull('alias_for') + .pluck('id'); + + if (target && conflictingAliases.length > 0) { + await moveTagReferences(knex, conflictingAliases, target.id); + } + + await knex('tags') + .whereIn('id', conflictingAliases) .delete(); await knex('tags') diff --git a/seeds/01_networks.js b/seeds/01_networks.js index 2e9f270f..5ddab377 100755 --- a/seeds/01_networks.js +++ b/seeds/01_networks.js @@ -716,6 +716,11 @@ const networks = [ forceDeepUpdate: true, }, }, + { + slug: 'penthouse', + name: 'Penthouse', + url: 'https://penthouse.com', + }, { slug: 'perfectgonzo', name: 'Perfect Gonzo', diff --git a/seeds/02_sites.js b/seeds/02_sites.js index 1c024712..8aed7a3d 100755 --- a/seeds/02_sites.js +++ b/seeds/02_sites.js @@ -9524,6 +9524,13 @@ const sites = [ url: 'https://www.pascalssubsluts.com', tags: ['rough', 'bdsm'], }, + // PENTHOUSE + { + slug: 'penthousegold', + name: 'Penthouse Gold', + url: 'https://penthousegold.com', + parent: 'penthouse', + }, // PERFECT GONZO { slug: 'allinternal', diff --git a/src/scrapers/actors.js b/src/scrapers/actors.js index bfbf597c..f591f8ef 100644 --- a/src/scrapers/actors.js +++ b/src/scrapers/actors.js @@ -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, }; diff --git a/src/scrapers/penthouse.js b/src/scrapers/penthouse.js new file mode 100755 index 00000000..d7ee7ba2 --- /dev/null +++ b/src/scrapers/penthouse.js @@ -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, +}; diff --git a/src/scrapers/releases.js b/src/scrapers/releases.js index 6d8a811b..33b4d8d1 100644 --- a/src/scrapers/releases.js +++ b/src/scrapers/releases.js @@ -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, diff --git a/src/tags.js b/src/tags.js index 7ec46549..adce881e 100755 --- a/src/tags.js +++ b/src/tags.js @@ -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 }); diff --git a/tests/profiles.js b/tests/profiles.js index acd2fe55..e0885369 100644 --- a/tests/profiles.js +++ b/tests/profiles.js @@ -267,6 +267,7 @@ const actors = [ { entity: 'darkkotv', name: 'Aidra Fox', fields: ['avatar', 'description', 'dateOfBirth', 'birthPlace', 'ethnicity', 'height', 'weight', 'measurements', 'naturalBoobs', 'hasTattoos', 'hasPiercings'] }, { entity: 'jaxslayher', name: 'Eliza Ibarra', fields: ['avatar', 'description', 'eyes', 'height', 'weight', 'birthPlace', 'measurements', 'hairColor'] }, { entity: 'cosplayground', name: 'Anna Claire Clouds', url: 'https://cosplayground.com/models/anna-claire-clouds?models=Anna%20Claire%20Clouds', fields: ['avatar', 'description', 'dateOfBirth', 'birthPlace', 'height', 'measurements', 'hairColor', 'ethnicity'] }, + { entity: 'penthouse', name: 'Gianna Dior', fields: ['avatar', 'description', 'measurements', 'height'] }, ]; const actorScrapers = scrapers.actors;