diff --git a/src/scrapers/kink.js b/src/scrapers/kink.js index c1402e6d..18cf0a91 100755 --- a/src/scrapers/kink.js +++ b/src/scrapers/kink.js @@ -91,29 +91,38 @@ function scrapeScene({ query }, url, entity) { return release; } -async function fetchActorReleases(actorUrl, page = 1, accReleases = []) { - const res = await qu.get(`${actorUrl}?page=${page}`); +async function fetchActorReleases(actorId, entity, page = 1, accReleases = []) { + const networkUrl = entity.type === 'channel' ? entity.parent.url : entity.url; + const { tab } = await http.getBrowserSession('kink'); + const res = await tab.goto(`${networkUrl}/search?type=shoots&performerIds=${actorId}&sort=published&page=${page}`); - if (res.ok) { - const releases = scrapeAll(qu.initAll(res.item.el, '.shoot-list .shoot')); - const hasNextPage = res.item.query.exists('.paginated-nav li:last-child:not(.disabled)'); + if (res.status() === 200) { + const html = await tab.content(); + const item = unprint.init(html); + const releases = scrapeAll(unprint.initAll(html, '.results .shoot-card'), entity); + const hasNextPage = item.query.exists('.paginated-nav li:last-child:not(.disabled)'); + + await tab.close(); if (hasNextPage) { - return fetchActorReleases(actorUrl, page + 1, accReleases.concat(releases)); + return fetchActorReleases(actorId, entity, page + 1, accReleases.concat(releases)); } return accReleases.concat(releases); } + await tab.close(); + return accReleases; } -async function scrapeProfile({ query }, actorUrl, include) { +async function scrapeProfile({ query }, actorUrl, entity, include) { const profile = {}; - profile.description = query.content('.bio #expand-text'); + profile.entryId = actorUrl.match(/\/model\/(\d+)\//)?.[1] || query.attribute('.favorite-button.bio-favorite', 'data-id'); + profile.description = query.content('.bio-outer #expand-text'); - const tags = query.contents('.bio-tags a'); + const tags = query.contents('.bio-tags a').map((tag) => tag.toLowerCase()); if (tags.includes('brunette') || tags.includes('brunet')) profile.hairColor = 'brown'; if (tags.includes('blonde') || tags.includes('blond')) profile.hairColor = 'blonde'; @@ -138,12 +147,10 @@ async function scrapeProfile({ query }, actorUrl, include) { profile.avatar = query.img('.bio-slider-img, .bio-img:not([src*="Missing"])'); profile.social = query.urls('a.social-link'); - if (include.releases) { - profile.releases = await fetchActorReleases(actorUrl); + if (include.releases && profile.entryId) { + profile.releases = await fetchActorReleases(profile.entryId, entity); } - console.log(profile); - return profile; } @@ -215,7 +222,7 @@ async function fetchProfile({ name: actorName }, entity, options) { await tab.close(); - return scrapeProfile(item, actorUrl, options); + return scrapeProfile(item, actorUrl, entity, options); } await tab.close();