Skip to content

Commit

Permalink
fix(route): pornhub cookie (#13182)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Sep 1, 2023
1 parent 90a2db4 commit 3135946
Show file tree
Hide file tree
Showing 19 changed files with 304 additions and 200 deletions.
12 changes: 6 additions & 6 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ router.get('/konachan.com/post/popular_recent/:period', lazyloadRouteHandler('./
router.get('/konachan.net/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post_popular_recent'));

// PornHub
router.get('/pornhub/category/:caty', lazyloadRouteHandler('./routes/pornhub/category'));
router.get('/pornhub/search/:keyword', lazyloadRouteHandler('./routes/pornhub/search'));
router.get('/pornhub/:language?/category_url/:url?', lazyloadRouteHandler('./routes/pornhub/category_url'));
router.get('/pornhub/:language?/users/:username', lazyloadRouteHandler('./routes/pornhub/users'));
router.get('/pornhub/:language?/model/:username/:sort?', lazyloadRouteHandler('./routes/pornhub/model'));
router.get('/pornhub/:language?/pornstar/:username/:sort?', lazyloadRouteHandler('./routes/pornhub/pornstar'));
// router.get('/pornhub/category/:caty', lazyloadRouteHandler('./routes/pornhub/category'));
// router.get('/pornhub/search/:keyword', lazyloadRouteHandler('./routes/pornhub/search'));
// router.get('/pornhub/:language?/category_url/:url?', lazyloadRouteHandler('./routes/pornhub/category_url'));
// router.get('/pornhub/:language?/users/:username', lazyloadRouteHandler('./routes/pornhub/users'));
// router.get('/pornhub/:language?/model/:username/:sort?', lazyloadRouteHandler('./routes/pornhub/model'));
// router.get('/pornhub/:language?/pornstar/:username/:sort?', lazyloadRouteHandler('./routes/pornhub/pornstar'));

// yande.re
router.get('/yande.re/post/popular_recent', lazyloadRouteHandler('./routes/yande.re/post_popular_recent'));
Expand Down
22 changes: 0 additions & 22 deletions lib/routes/pornhub/category.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/routes/pornhub/category_url.js

This file was deleted.

35 changes: 0 additions & 35 deletions lib/routes/pornhub/model.js

This file was deleted.

35 changes: 0 additions & 35 deletions lib/routes/pornhub/pornstar.js

This file was deleted.

22 changes: 0 additions & 22 deletions lib/routes/pornhub/search.js

This file was deleted.

35 changes: 0 additions & 35 deletions lib/routes/pornhub/users.js

This file was deleted.

44 changes: 44 additions & 0 deletions lib/v2/pornhub/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { defaultDomain, renderDescription } = require('./utils');
const config = require('@/config').value;

module.exports = async (ctx) => {
const category = ctx.params.caty;

const categories = await ctx.cache.tryGet('pornhub:categories', async () => {
const { data } = await got(`${defaultDomain}/webmasters/categories`);
return data.categories;
});

const categoryId = isNaN(category) ? categories.find((item) => item.category === category)?.id : category;
const categoryName = isNaN(category) ? category : categories.find((item) => item.id === parseInt(category)).category;

const response = await ctx.cache.tryGet(
`pornhub:category:${categoryName}`,
async () => {
const { data } = await got(`${defaultDomain}/webmasters/search?category=${categoryName}`);
return data;
},
config.cache.routeExpire,
false
);

if (response.code) {
throw Error(response.message);
}

const list = response.videos.map((item) => ({
title: item.title,
link: item.url,
description: renderDescription({ thumbs: item.thumbs }),
pubDate: parseDate(item.publish_date),
category: [...new Set([...item.tags.map((t) => t.tag_name), ...item.categories.map((c) => c.category)])],
}));

ctx.state.data = {
title: `Pornhub - ${categoryName}`,
link: `${defaultDomain}/video?c=${categoryId}`,
item: list,
};
};
25 changes: 25 additions & 0 deletions lib/v2/pornhub/category_url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { isValidHost } = require('@/utils/valid-host');
const { headers, parseItems } = require('./utils');

module.exports = async (ctx) => {
const { language = 'www', url = 'video' } = ctx.params;
const link = `https://${language}.pornhub.com/${url}`;
if (!isValidHost(language)) {
throw Error('Invalid language');
}

const { data: response } = await got(link, { headers });
const $ = cheerio.load(response);
const items = $('#videoCategory .videoBox')
.toArray()
.map((e) => parseItems($(e)));

ctx.state.data = {
title: $('title').first().text(),
link,
language: $('html').attr('lang'),
item: items,
};
};
8 changes: 8 additions & 0 deletions lib/v2/pornhub/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
'/category/:caty': ['nczitzk'],
'/search/:keyword': ['nczitzk'],
'/:language?/category_url/:url?': ['I2IMk', 'queensferryme'],
'/:language?/model/:username/:sort?': ['I2IMk', 'queensferryme'],
'/:language?/pornstar/:username/:sort?': ['I2IMk', 'queensferryme'],
'/:language?/users/:username': ['I2IMk', 'queensferryme'],
};
29 changes: 29 additions & 0 deletions lib/v2/pornhub/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { isValidHost } = require('@/utils/valid-host');
const { headers, parseItems } = require('./utils');

module.exports = async (ctx) => {
const { language = 'www', username, sort = '' } = ctx.params;
const link = `https://${language}.pornhub.com/model/${username}/videos${sort ? `?o=${sort}` : ''}`;
if (!isValidHost(language)) {
throw Error('Invalid language');
}

const { data: response } = await got(link, { headers });
const $ = cheerio.load(response);
const items = $('#mostRecentVideosSection .videoBox')
.toArray()
.map((e) => parseItems($(e)));

ctx.state.data = {
title: $('title').first().text(),
description: $('section.aboutMeSection').text().trim(),
link,
image: $('#coverPictureDefault').attr('src'),
logo: $('#getAvatar').attr('src'),
icon: $('#getAvatar').attr('src'),
language: $('html').attr('lang'),
item: items,
};
};
29 changes: 29 additions & 0 deletions lib/v2/pornhub/pornstar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { isValidHost } = require('@/utils/valid-host');
const { headers, parseItems } = require('./utils');

module.exports = async (ctx) => {
const { language = 'www', username, sort = 'mr' } = ctx.params;
const link = `https://${language}.pornhub.com/pornstar/${username}/videos?o=${sort}`;
if (!isValidHost(language)) {
throw Error('Invalid language');
}

const { data: response } = await got(link, { headers });
const $ = cheerio.load(response);
const items = $('#mostRecentVideosSection .videoBox')
.toArray()
.map((e) => parseItems($(e)));

ctx.state.data = {
title: $('title').first().text(),
description: $('section.aboutMeSection').text().trim(),
link,
image: $('#coverPictureDefault').attr('src'),
logo: $('#getAvatar').attr('src'),
icon: $('#getAvatar').attr('src'),
language: $('html').attr('lang'),
item: items,
};
};
46 changes: 46 additions & 0 deletions lib/v2/pornhub/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
'pornhub.com': {
_name: 'PornHub',
'.': [
{
title: 'Category',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
source: ['/categories/:caty', '/video'],
target: (params, url) => {
if (params.caty) {
return `/pornhub/category/${params.caty}`;
}
return `/pornhub/category/${new URL(url).searchParams.get('c')}`;
},
},
{
title: 'Keyword Search',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
source: ['/video/search'],
target: (_, url) => `/pornhub/category/${new URL(url).searchParams.get('search')}`,
},
{
title: 'Users',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
source: ['/users/:username/*'],
target: '/pornhub/users/:username',
},
{
title: 'Verified amateur / Model',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
source: ['/model/:username/*'],
target: '/pornhub/model/:username',
},
{
title: 'Verified model / Pornstar',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
source: ['/pornstar/:username/*'],
target: '/pornhub/pornstar/:username',
},
{
title: 'Video List',
docs: 'https://docs.rsshub.app/routes/multimedia#pornhub',
},
],
},
};
Loading

0 comments on commit 3135946

Please sign in to comment.