forked from DebaucheryLibrarian/traxxx
Added tag page. Added default 'anal' tag to Vixen scraper for Tushy and Tushy Raw.
This commit is contained in:
@@ -23,9 +23,7 @@ async function storePoster(release, releaseEntry) {
|
||||
console.log(`Storing poster for (${release.site.name}, ${releaseEntry.id}) "${release.title}"`);
|
||||
|
||||
const res = await bhttp.get(release.poster);
|
||||
const thumbnail = await sharp(res.body)
|
||||
.resize({ width: Math.floor((config.media.thumbnailSize / 9) * 16), height: config.media.thumbnailSize }) // ensure thumbnail is 16:9
|
||||
.toBuffer();
|
||||
const thumbnail = await sharp(res.body).resize({ height: config.media.thumbnailSize }).toBuffer();
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
const { pathname } = new URL(release.poster);
|
||||
|
||||
@@ -143,9 +143,32 @@ async function fetchActorReleases(actorId, actorSlug) {
|
||||
return curateReleases(releases);
|
||||
}
|
||||
|
||||
async function fetchTagReleases(tagId, tagSlug) {
|
||||
const releases = await knex('tags_associated')
|
||||
.where({ 'tags.id': tagId })
|
||||
.orWhere({ 'tags.slug': tagSlug })
|
||||
.select(
|
||||
'releases.*',
|
||||
'tags.name as tag_name',
|
||||
'sites.name as site_name', 'sites.slug as site_slug', 'sites.url as site_url', 'sites.network_id',
|
||||
'studios.name as studio_name', 'sites.slug as site_slug', 'studios.url as studio_url',
|
||||
'networks.name as network_name', 'networks.slug as network_slug', 'networks.url as network_url',
|
||||
)
|
||||
.leftJoin('releases', 'tags_associated.release_id', 'releases.id')
|
||||
.leftJoin('tags', 'tags_associated.tag_id', 'tags.id')
|
||||
.leftJoin('sites', 'releases.site_id', 'sites.id')
|
||||
.leftJoin('studios', 'releases.studio_id', 'studios.id')
|
||||
.leftJoin('networks', 'sites.network_id', 'networks.id')
|
||||
.orderBy([{ column: 'releases.date', order: 'desc' }, { column: 'releases.created_at', order: 'desc' }])
|
||||
.limit(100);
|
||||
|
||||
return curateReleases(releases);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchReleases,
|
||||
fetchActorReleases,
|
||||
fetchSiteReleases,
|
||||
fetchNetworkReleases,
|
||||
fetchTagReleases,
|
||||
};
|
||||
|
||||
@@ -7,6 +7,15 @@ const moment = require('moment');
|
||||
|
||||
const { matchTags } = require('../tags');
|
||||
|
||||
const defaultTags = {
|
||||
blacked: ['bbc'],
|
||||
blackedraw: ['bbc'],
|
||||
tushy: ['anal'],
|
||||
tushyraw: ['anal'],
|
||||
vixen: [],
|
||||
deeper: [],
|
||||
};
|
||||
|
||||
function scrapeLatest(html, site) {
|
||||
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
||||
|
||||
@@ -73,7 +82,7 @@ async function scrapeScene(html, url, site) {
|
||||
} = scene;
|
||||
|
||||
const date = new Date(scene.releaseDate);
|
||||
const tags = await matchTags(rawTags);
|
||||
const tags = await matchTags([...defaultTags[site.slug], ...rawTags]);
|
||||
|
||||
return {
|
||||
url,
|
||||
|
||||
53
src/tags.js
53
src/tags.js
@@ -2,6 +2,49 @@
|
||||
|
||||
const knex = require('./knex');
|
||||
|
||||
async function curateTag(tag) {
|
||||
const aliases = await knex('tags').where({ alias_for: tag.id });
|
||||
|
||||
return {
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
description: tag.description,
|
||||
group: {
|
||||
id: tag.group_id,
|
||||
name: tag.group_name,
|
||||
description: tag.group_description,
|
||||
slug: tag.group_slug,
|
||||
},
|
||||
aliases: aliases.map(({ name }) => name),
|
||||
};
|
||||
}
|
||||
|
||||
function curateTags(tags) {
|
||||
return Promise.all(tags.map(async tag => curateTag(tag)));
|
||||
}
|
||||
|
||||
async function storeTags(release, releaseEntry) {
|
||||
return knex('tags_associated').insert(release.tags.map(tagId => ({
|
||||
tag_id: tagId,
|
||||
release_id: releaseEntry.id,
|
||||
})));
|
||||
}
|
||||
|
||||
async function fetchTags(tagId, tagSlug) {
|
||||
const tags = await knex('tags')
|
||||
.where({ 'tags.id': tagId })
|
||||
.orWhere({ 'tags.slug': tagSlug })
|
||||
.andWhere({ 'tags.alias_for': null })
|
||||
.select(
|
||||
'tags.*',
|
||||
'tags_groups.id as group_id', 'tags_groups.name as group_name', 'tags_groups.slug as group_slug', 'tags_groups.description as groups_description',
|
||||
)
|
||||
.leftJoin('tags_groups', 'tags.group_id', 'tags_groups.id')
|
||||
.limit(100);
|
||||
|
||||
return curateTags(tags);
|
||||
}
|
||||
|
||||
async function matchTags(rawTags) {
|
||||
const tags = rawTags
|
||||
.concat(rawTags.map(tag => tag.toLowerCase()))
|
||||
@@ -25,14 +68,8 @@ async function matchTags(rawTags) {
|
||||
return tagEntries;
|
||||
}
|
||||
|
||||
async function storeTags(release, releaseEntry) {
|
||||
return knex('tags_associated').insert(release.tags.map(tagId => ({
|
||||
tag_id: tagId,
|
||||
release_id: releaseEntry.id,
|
||||
})));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
matchTags,
|
||||
storeTags,
|
||||
fetchTags,
|
||||
matchTags,
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ const {
|
||||
fetchActorReleases,
|
||||
fetchNetworkReleases,
|
||||
fetchSiteReleases,
|
||||
fetchTagReleases,
|
||||
} = require('../releases');
|
||||
|
||||
async function fetchReleasesApi(req, res) {
|
||||
@@ -40,9 +41,19 @@ async function fetchSiteReleasesApi(req, res) {
|
||||
res.send(releases);
|
||||
}
|
||||
|
||||
async function fetchTagReleasesApi(req, res) {
|
||||
const tagId = typeof req.params.tagId === 'number' ? req.params.tagId : null;
|
||||
const tagSlug = typeof req.params.tagId === 'string' ? req.params.tagId : null;
|
||||
|
||||
const releases = await fetchTagReleases(tagId, tagSlug);
|
||||
|
||||
res.send(releases);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchReleases: fetchReleasesApi,
|
||||
fetchActorReleases: fetchActorReleasesApi,
|
||||
fetchNetworkReleases: fetchNetworkReleasesApi,
|
||||
fetchSiteReleases: fetchSiteReleasesApi,
|
||||
fetchTagReleases: fetchTagReleasesApi,
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ const {
|
||||
fetchActorReleases,
|
||||
fetchNetworkReleases,
|
||||
fetchSiteReleases,
|
||||
fetchTagReleases,
|
||||
} = require('./releases');
|
||||
|
||||
const {
|
||||
@@ -20,6 +21,7 @@ const {
|
||||
|
||||
const { fetchActors } = require('./actors');
|
||||
const { fetchSites } = require('./sites');
|
||||
const { fetchTags } = require('./tags');
|
||||
|
||||
function initServer() {
|
||||
const app = express();
|
||||
@@ -50,6 +52,10 @@ function initServer() {
|
||||
router.get('/api/sites/:siteId', fetchSites);
|
||||
router.get('/api/sites/:siteId/releases', fetchSiteReleases);
|
||||
|
||||
router.get('/api/tags', fetchTags);
|
||||
router.get('/api/tags/:tagId', fetchTags);
|
||||
router.get('/api/tags/:tagId/releases', fetchTagReleases);
|
||||
|
||||
router.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../../public/index.html'));
|
||||
});
|
||||
|
||||
16
src/web/tags.js
Normal file
16
src/web/tags.js
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const { fetchTags } = require('../tags');
|
||||
|
||||
async function fetchTagsApi(req, res) {
|
||||
const tagId = typeof req.params.tagId === 'number' ? req.params.tagId : null;
|
||||
const tagSlug = typeof req.params.tagId === 'string' ? req.params.tagId : null;
|
||||
|
||||
const tags = await fetchTags(tagId, tagSlug);
|
||||
|
||||
res.send(tags);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchTags: fetchTagsApi,
|
||||
};
|
||||
Reference in New Issue
Block a user