forked from DebaucheryLibrarian/traxxx
162 lines
4.7 KiB
JavaScript
162 lines
4.7 KiB
JavaScript
'use strict';
|
|
|
|
/* eslint-disable newline-per-chained-call */
|
|
// const Promise = require('bluebird');
|
|
const { JSDOM } = require('jsdom');
|
|
const moment = require('moment');
|
|
|
|
const http = require('../utils/http');
|
|
const slugify = require('../utils/slugify');
|
|
const qu = require('../utils/qu');
|
|
|
|
async function getPhotos(albumUrl) {
|
|
const res = await http.get(albumUrl);
|
|
const html = res.body.toString();
|
|
const { document } = new JSDOM(html).window;
|
|
|
|
const lastPhotoPage = Array.from(document.querySelectorAll('.preview-image-container a')).slice(-1)[0].href;
|
|
const lastPhotoIndex = parseInt(lastPhotoPage.match(/\d+.jpg/)[0], 10);
|
|
|
|
const photoUrls = Array.from({ length: lastPhotoIndex }, (value, index) => {
|
|
const pageUrl = `https://blacksonblondes.com${lastPhotoPage.replace(/\d+.jpg/, `${(index + 1).toString().padStart(3, '0')}.jpg`)}`;
|
|
|
|
return {
|
|
url: pageUrl,
|
|
extract: ({ query }) => query.img('.scenes-module img'),
|
|
};
|
|
});
|
|
|
|
return photoUrls;
|
|
}
|
|
|
|
function scrapeLatest(html, site, filter = true) {
|
|
const { document } = new JSDOM(html).window;
|
|
const sceneElements = Array.from(document.querySelectorAll('.recent-updates'));
|
|
|
|
return sceneElements.map((element) => {
|
|
const siteUrl = element.querySelector('.recent-details-title .help-block, .model-details-title .site-name').textContent;
|
|
|
|
if (filter && `www.${siteUrl.toLowerCase()}` !== new URL(site.url).host) {
|
|
// different dogfart site
|
|
return null;
|
|
}
|
|
|
|
const sceneLinkElement = element.querySelector('.thumbnail');
|
|
const url = qu.prefixUrl(sceneLinkElement.href, 'https://dogfartnetwork.com');
|
|
const { pathname } = new URL(url);
|
|
const entryId = `${site.slug}_${pathname.split('/')[4]}`;
|
|
|
|
const title = element.querySelector('.scene-title').textContent;
|
|
const actors = title.split(/[,&]|\band\b/).map(actor => actor.replace(/BTS/i, '').trim());
|
|
|
|
const poster = `https:${element.querySelector('img').src}`;
|
|
const teaser = sceneLinkElement.dataset.preview_clip_url;
|
|
|
|
const channel = siteUrl?.match(/(.*).com/)?.[1].toLowerCase();
|
|
|
|
return {
|
|
url,
|
|
entryId,
|
|
title,
|
|
actors,
|
|
poster,
|
|
teaser: {
|
|
src: teaser,
|
|
},
|
|
site,
|
|
channel,
|
|
};
|
|
}).filter(Boolean);
|
|
}
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
const { document } = new JSDOM(html).window;
|
|
|
|
const title = document.querySelector('.description-title').textContent;
|
|
const actors = Array.from(document.querySelectorAll('.more-scenes a')).map(({ textContent }) => textContent);
|
|
const metaDescription = document.querySelector('meta[itemprop="description"]').content;
|
|
const description = metaDescription
|
|
? metaDescription.content
|
|
: document.querySelector('.description')
|
|
.textContent
|
|
.replace(/[ \t\n]{2,}/g, ' ')
|
|
.replace('...read more', '')
|
|
.trim();
|
|
|
|
const channel = document.querySelector('.site-name').textContent.split('.')[0].toLowerCase();
|
|
const { origin, pathname } = new URL(url);
|
|
const entryId = `${channel}_${pathname.split('/').slice(-2)[0]}`;
|
|
|
|
const date = new Date(document.querySelector('meta[itemprop="uploadDate"]').content);
|
|
const duration = moment
|
|
.duration(`00:${document
|
|
.querySelectorAll('.extra-info p')[1]
|
|
.textContent
|
|
.match(/\d+:\d+$/)[0]}`)
|
|
.asSeconds();
|
|
|
|
const trailerElement = document.querySelector('.html5-video');
|
|
const poster = `https:${trailerElement.dataset.poster}`;
|
|
const { trailer } = trailerElement.dataset;
|
|
|
|
const lastPhotosUrl = Array.from(document.querySelectorAll('.pagination a')).slice(-1)[0]?.href;
|
|
const photos = lastPhotosUrl ? await getPhotos(`${origin}${pathname}${lastPhotosUrl}`, site, url) : [];
|
|
|
|
const stars = Math.floor(Number(document.querySelector('span[itemprop="average"]')?.textContent || document.querySelector('span[itemprop="ratingValue"]')?.textContent) / 2);
|
|
const tags = Array.from(document.querySelectorAll('.scene-details .categories a')).map(({ textContent }) => textContent);
|
|
|
|
return {
|
|
entryId,
|
|
url: `${origin}${pathname}`,
|
|
title,
|
|
description,
|
|
actors,
|
|
date,
|
|
duration,
|
|
poster,
|
|
photos,
|
|
trailer: {
|
|
src: trailer,
|
|
},
|
|
tags,
|
|
rating: {
|
|
stars,
|
|
},
|
|
site,
|
|
channel,
|
|
};
|
|
}
|
|
|
|
async function fetchLatest(site, page = 1) {
|
|
const res = await http.get(`https://dogfartnetwork.com/tour/scenes/?p=${page}`);
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
}
|
|
|
|
async function fetchScene(url, site) {
|
|
const res = await http.get(url);
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
}
|
|
|
|
async function fetchProfile(baseActor, entity) {
|
|
const slug = slugify(baseActor.name, '+');
|
|
const url = `https://www.dogfartnetwork.com/tour/girls/${slug}/`;
|
|
|
|
const res = await http.get(url);
|
|
|
|
if (res.ok) {
|
|
const scenes = scrapeLatest(res.body, entity, false);
|
|
|
|
return { scenes };
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchScene,
|
|
fetchProfile,
|
|
};
|