Added Bang Bros scraper.

This commit is contained in:
2019-04-12 03:12:53 +02:00
parent 17480be79a
commit b486b6abdd
8 changed files with 204 additions and 93 deletions

100
src/scrapers/bangbros.js Normal file
View File

@@ -0,0 +1,100 @@
'use strict';
/* eslint-disable newline-per-chained-call */
const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const knex = require('../knex');
const { matchTags } = require('../tags');
function scrapeLatest(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const sceneElements = $('.echThumb').toArray();
return sceneElements.map((element) => {
const sceneLinkElement = $(element).find('.thmb_lnk');
const title = sceneLinkElement.attr('title');
const url = `https://bangbros.com${sceneLinkElement.attr('href')}`;
const shootId = sceneLinkElement.attr('id') && sceneLinkElement.attr('id').split('-')[1];
const entryId = url.split('/')[3].slice(5);
const date = moment.utc($(element).find('.thmb_mr_2 span.faTxt').text(), 'MMM D, YYYY').toDate();
const actors = $(element).find('.cast-wrapper a.cast').map((actorIndex, actorElement) => $(actorElement).text().trim()).toArray();
const duration = moment.duration(`0:${$(element).find('.thmb_pic b.tTm').text()}`).asSeconds();
return {
url,
entryId,
shootId,
title,
actors,
date,
duration,
rating: null,
site,
};
});
}
async function scrapeScene(html, url, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const sceneElement = $('.playerSection');
const shootId = sceneElement.find('.vdoCast:contains("Release")').text().replace('Release: ', '');
const entryId = url.split('/')[3].slice(5);
const title = sceneElement.find('.ps-vdoHdd h1').text();
const description = sceneElement.find('.vdoDesc').text().trim();
const [siteName, ...actors] = sceneElement.find('.vdoCast a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
const siteId = siteName.replace(/[\s']+/g, '').toLowerCase();
const rawTags = $('.vdoTags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
const [channelSite, tags] = await Promise.all([
knex('sites')
.where({ id: siteId })
.orWhere({ name: siteName })
.first(),
matchTags(rawTags),
]);
const stars = Number(sceneElement.find('.bVdPl_it_like .bVdPl_txt').text().replace('% like', '')) / 20;
return {
url,
shootId,
entryId,
title,
description,
actors,
tags,
rating: {
stars,
},
site: channelSite || site,
};
}
async function fetchLatest(site, page = 1) {
const res = await bhttp.get(`https://bangbros.com/websites/${site.id}/${page}`);
return scrapeLatest(res.body.toString(), site);
}
async function fetchScene(url, site) {
const { origin } = new URL(url);
const res = await bhttp.get(url);
if (origin !== 'https://bangbros.com') {
throw new Error('Cannot fetch from this URL. Please find the scene on https://bangbros.com and try again.');
}
return scrapeScene(res.body.toString(), url, site);
}
module.exports = {
fetchLatest,
fetchScene,
};

View File

@@ -1,6 +1,7 @@
'use strict';
const twentyonesextury = require('./21sextury');
const bangbros = require('./bangbros');
const blowpass = require('./blowpass');
const brazzers = require('./brazzers');
const ddfnetwork = require('./ddfnetwork');
@@ -17,6 +18,7 @@ const xempire = require('./xempire');
module.exports = {
'21sextury': twentyonesextury,
bangbros,
blowpass,
brazzers,
ddfnetwork,

View File

@@ -1,51 +0,0 @@
'use strict';
const Promise = require('bluebird');
const bhttp = require('bhttp');
const fs = Promise.promisifyAll(require('fs'));
const knex = require('../knex');
const argv = require('../argv');
const options = {
responseTimeout: 30000,
};
async function tryLinks() {
const sites = await knex('sites').whereIn('network_id', argv.network);
const results = await Promise.all(sites.map(async (site) => {
console.log(`Trying ${site.name} URLs`);
const [resHttp, resHttpWww, resHttps, resHttpsWww] = await Promise.all([
bhttp.get(`http://${site.id}.com/`, options).catch(error => ({ statusCode: error.message })),
bhttp.get(`http://www.${site.id}.com/`, options).catch(error => ({ statusCode: error.message })),
bhttp.get(`https://${site.id}.com/`, options).catch(error => ({ statusCode: error.message })),
bhttp.get(`https://www.${site.id}.com/`, options).catch(error => ({ statusCode: error.message })),
]);
console.log(`Got results for ${site.name}`);
return {
...site,
url: (resHttp.statusCode === 200 && `http://${site.id}.com`)
|| (resHttpWww.statusCode === 200 && `http://www.${site.id}.com`)
|| (resHttps.statusCode === 200 && `https://${site.id}.com`)
|| (resHttpsWww.statusCode === 200 && `https://www.${site.id}.com`)
|| site.url,
network_id: site.network_id,
};
}));
const sortedResults = results.sort((siteA, siteB) => {
if (siteA.id > siteB.id) return 1;
if (siteA.id < siteB.id) return -1;
return 0;
});
console.log(sortedResults);
await fs.writeFileAsync('./src/utils/link-results.json', JSON.stringify(sortedResults, null, 4));
}
tryLinks();