Refactored various modules for entities. Updated and refactored Kink scraper.

This commit is contained in:
2020-06-27 02:57:30 +02:00
parent 4959dfd14f
commit af56378ee2
107 changed files with 539 additions and 414 deletions

View File

@@ -1,117 +1,97 @@
'use strict';
const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const { get, getAll } = require('../utils/qu');
function scrapeLatest(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const sceneElements = $('.shoot-list .shoot').toArray();
function scrapeLatest(scenes) {
return scenes.map(({ qu }) => {
const release = {};
return sceneElements.map((element) => {
const sceneLinkElement = $(element).find('.shoot-thumb-title a');
const href = sceneLinkElement.attr('href');
const url = `https://kink.com${href}`;
const shootId = href.split('/')[2];
const title = sceneLinkElement.text().trim();
const href = qu.url('.shoot-thumb-title a');
release.url = `https://kink.com${href}`;
const poster = $(element).find('.adimage').attr('src');
const photos = $(element).find('.rollover .roll-image').map((photoIndex, photoElement) => $(photoElement).attr('data-imagesrc')).toArray();
release.shootId = href.split('/').slice(-1)[0];
release.entryId = release.shootId;
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;
release.title = qu.q('.shoot-thumb-title a', true);
release.date = qu.date('.date', 'MMM DD, YYYY');
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();
release.actors = qu.all('.shoot-thumb-models a', true);
release.stars = qu.q('.average-rating', 'data-rating') / 10;
return {
url,
shootId,
entryId: shootId,
title,
actors,
date,
photos,
poster,
rating: {
stars,
},
duration,
site,
};
release.poster = qu.img('.adimage');
release.photos = qu.imgs('.rollover .roll-image', 'data-imagesrc').map(photo => [
photo.replace('410/', '830/'),
photo,
]);
release.duration = qu.dur('.video span');
return release;
});
}
async function scrapeScene(html, url, shootId, ratingRes, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
async function scrapeScene({ qu }, url) {
const release = { url };
// 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');
release.shootId = new URL(url).pathname.split('/')[2];
release.entryId = release.shootId;
const photos = $('.gallery .thumb img').map((photoIndex, photoElement) => $(photoElement).attr('data-image-file')).toArray();
const trailerVideo = $('.player span[data-type="trailer-src"]').attr('data-url');
const trailerPoster = $('.player video#kink-player').attr('poster');
release.title = qu.q('.shoot-title span.favorite-button', 'data-title');
release.description = qu.q('.description-text', true);
const date = moment.utc($(actorsRaw)
.prev()
.text()
.trim()
.replace('Date: ', ''),
'MMMM DD, YYYY')
.toDate();
release.date = qu.date('.shoot-date', 'MMMM DD, YYYY');
release.actors = qu.all('.names a', true).map(actor => actor.replace(/,\s*/, ''));
release.director = qu.q('.director-name', true);
const actors = $(actorsRaw).find('span.names a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
const description = $('.shoot-info .description').text().trim();
release.photos = qu.imgs('.gallery .thumb img', 'data-image-file');
release.poster = qu.poster();
const { average: stars } = ratingRes.body;
release.tags = qu.all('.tag-list a[href*="/tag"]', true).map(tag => tag.replace(/,\s*/, ''));
const siteName = $('.shoot-logo a').attr('href').split('/')[2];
const siteSlug = siteName.replace(/\s+/g, '').toLowerCase();
const trailer = qu.q('.player span[data-type="trailer-src"]', 'data-url');
const tags = $('.tag-list > a[href*="/tag"]').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
const channel = siteSlug;
return {
url,
shootId,
entryId: shootId,
title,
date,
actors,
description,
photos,
poster: trailerPoster,
trailer: {
src: trailerVideo,
release.trailer = [
{
src: trailer.replace('480p', '1080p'),
quality: 1080,
},
{
src: trailer.replace('480p', '720p'),
quality: 720,
},
{
src: trailer,
quality: 480,
},
rating: {
stars,
{
src: trailer.replace('480p', '360p'),
quality: 360,
},
tags,
site,
channel,
};
];
release.channel = qu.url('.shoot-logo a').split('/').slice(-1)[0];
return release;
}
async function fetchLatest(site, page = 1) {
const res = await bhttp.get(`${site.url}/latest/page/${page}`);
const res = await getAll(`${site.url}/latest/page/${page}`, '.shoot-list .shoot');
return scrapeLatest(res.body.toString(), site);
if (res.ok) {
return scrapeLatest(res.items, site);
}
return res.status;
}
async function fetchScene(url, site) {
const shootId = new URL(url).pathname.split('/')[2];
const res = await get(url);
const [res, ratingRes] = await Promise.all([
bhttp.get(url),
bhttp.get(`https://kink.com/api/ratings/${shootId}`),
]);
if (res.ok) {
return scrapeScene(res.item, url, site);
}
return scrapeScene(res.body.toString(), url, shootId, ratingRes, site);
return res.status;
}
module.exports = {