Added Kink scraper with elaborate site specification.

This commit is contained in:
2019-03-24 05:28:18 +01:00
parent e85a0f45f9
commit 845f46e9ad
16 changed files with 590 additions and 143 deletions

View File

@@ -0,0 +1,44 @@
'use strict';
/* eslint-disable */
const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const tagMap = {};
function scrapeLatest(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
}
function scrapeUpcoming(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
}
function scrapeScene(html, url, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
}
async function fetchLatest(site) {
const res = await bhttp.get(`${site.url}/url`);
return scrapeLatest(res.body.toString(), site);
}
async function fetchUpcoming(site) {
const res = await bhttp.get(`${site.url}/url`);
return scrapeUpcoming(res.body.toString(), site);
}
async function fetchScene(url, site) {
const res = await bhttp.get(url);
return scrapeScene(res.body.toString(), url, site);
}
module.exports = {
fetchLatest,
fetchUpcoming,
fetchScene,
};

View File

@@ -2,12 +2,14 @@
const xempire = require('./xempire');
const julesjordan = require('./julesjordan');
const kink = require('./kink');
const legalporno = require('./legalporno');
const pervcity = require('./pervcity');
module.exports = {
xempire,
julesjordan,
kink,
legalporno,
pervcity,
};

127
src/scrapers/kink.js Normal file
View File

@@ -0,0 +1,127 @@
'use strict';
const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const { kink } = require('../networks');
const tagMap = {
Airtight: 'airtight',
Anal: 'anal',
Asian: 'asian',
BDSM: 'BDSM',
Blowbang: 'blowbang',
Blowjob: 'blowjob',
Bondage: 'bondage',
Choking: 'choking',
'Corporal Punishment': 'corporal punishment',
'Double Penetration': 'DP',
Gangbang: 'gangbang',
'High Heels': 'high heels',
Petite: 'petite',
'Role Play': 'roleplay',
'Rope Bondage': 'bondage',
'Rough Sex': 'rough',
Shaved: 'shaved',
Slapping: 'slapping',
'Small Tits': 'small boobs',
Squirting: 'squirting',
White: 'white',
};
function scrapeLatest(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const sceneElements = $('.shoot-list .shoot').toArray();
return sceneElements.map((element) => {
const sceneLinkElement = $(element).find('.shoot-thumb-title a');
const href = sceneLinkElement.attr('href');
const url = `https://kink.com${href}`;
const id = href.split('/')[2];
const title = sceneLinkElement.text();
const date = moment.utc($(element).find('.date').text(), 'MMM DD, YYYY').toDate();
const actors = $(element).find('.shoot-thumb-models a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
const stars = $(element).find('.average-rating').attr('data-rating') / 10;
const timestamp = $(element).find('.video span').text();
const timestampComponents = timestamp.split(':'); // fix mixed hh:mm:ss and mm:ss format
const duration = moment.duration(timestampComponents.length > 2 ? timestamp : `0:${timestamp}`).asSeconds();
return {
url,
id,
title,
actors,
date,
rating: {
stars,
},
duration,
site,
};
});
}
async function scrapeScene(html, url, id, ratingRes, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
// const title = $('h1.shoot-title').text().replace(/\ue800/, ''); // fallback, special character is 'like'-heart
const title = $('h1.shoot-title span.favorite-button').attr('data-title');
const actorsRaw = $('.shoot-info p.starring');
const sitename = $('.shoot-logo a').attr('href').split('/')[2];
const channelSite = kink.sites[sitename];
const date = moment.utc($(actorsRaw)
.prev()
.text()
.trim()
.replace('Date: ', ''),
'MMMM DD, YYYY')
.toDate();
const actors = $(actorsRaw).find('span.names a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
const description = $('.shoot-info .description').text();
const { average: stars } = ratingRes.body;
const rawTags = $('.tag-list > a[href*="/tag"]').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
const tags = rawTags.reduce((accTags, tag) => (tagMap[tag] ? [...accTags, tagMap[tag]] : accTags), []);
return {
url,
id,
title,
date,
actors,
description,
rating: {
stars,
},
tags,
site: channelSite || site,
};
}
async function fetchLatest(site) {
const res = await bhttp.get(`${site.url}/latest`);
return scrapeLatest(res.body.toString(), site);
}
async function fetchScene(url, site) {
const id = new URL(url).pathname.split('/')[2];
const [res, ratingRes] = await Promise.all([
bhttp.get(url),
bhttp.get(`https://kink.com/api/ratings/${id}`),
]);
return scrapeScene(res.body.toString(), url, id, ratingRes, site);
}
module.exports = {
fetchLatest,
fetchScene,
};

View File

@@ -65,8 +65,7 @@ function scrapeScene(html, url, site) {
.find('a[href*="com/model"]')
.map((actorIndex, actorElement) => $(actorElement).text()).toArray();
const runtime = $('span[title="Runtime"]').text().trim().split(':');
const duration = Number(runtime[0]) * 3600 + Number(runtime[1]) * 60 + Number(runtime[2]);
const duration = moment.duration($('span[title="Runtime"]').text().trim()).asSeconds();
const rawTags = $(tagsElement).find('a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
const tags = rawTags.reduce((accTags, tag) => (tagMap[tag] ? [...accTags, tagMap[tag]] : accTags), []);

View File

@@ -119,8 +119,7 @@ function scrapeScene(html, url, site) {
const description = data.description || undefined;
const stars = (data.aggregateRating.ratingValue / data.aggregateRating.bestRating) * 5;
const runtime = data.duration.slice(2).split(':');
const duration = Number(runtime[0]) * 3600 + Number(runtime[1]) * 60 + Number(runtime[2]);
const duration = moment.duration(data.duration.slice(2).split(':')).asSeconds();
const rawTags = data.keywords.split(', ');
const tags = rawTags.reduce((accTags, tag) => (tagMap[tag] ? [...accTags, tagMap[tag]] : accTags), []);