Added basic PornHub support.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:57 +02:00
parent f47b99501a
commit 8d75cc170d
3 changed files with 58 additions and 13 deletions

View File

@ -50,6 +50,10 @@ const hosts = [{
method: 'eroshareItem',
label: 'eroshare',
pattern: new UrlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)'),
}, {
method: 'pornhub',
label: 'pornhub',
pattern: new UrlPattern('http(s)\\://(www.)pornhub.com/view_video.php?viewkey=(:id)(?*)'),
}];
module.exports = function dissectLink(url) {

View File

@ -1,17 +1,18 @@
'use strict';
const self = require('./self.js');
const redditImage = require('./redditImage.js');
const redditVideo = require('./redditVideo.js');
const redditPreview = require('./redditPreview.js');
const imgurImage = require('./imgurImage.js');
const imgurAlbum = require('./imgurAlbum.js');
const vidbleImage = require('./vidbleImage.js');
const vidbleVideo = require('./vidbleVideo.js');
const vidbleAlbum = require('./vidbleAlbum.js');
const gfycat = require('./gfycat.js');
const eroshareAlbum = require('./eroshareAlbum.js');
const eroshareItem = require('./eroshareItem.js');
const self = require('./self');
const redditImage = require('./redditImage');
const redditVideo = require('./redditVideo');
const redditPreview = require('./redditPreview');
const imgurImage = require('./imgurImage');
const imgurAlbum = require('./imgurAlbum');
const vidbleImage = require('./vidbleImage');
const vidbleVideo = require('./vidbleVideo');
const vidbleAlbum = require('./vidbleAlbum');
const gfycat = require('./gfycat');
const eroshareAlbum = require('./eroshareAlbum');
const eroshareItem = require('./eroshareItem');
const pornhub = require('./pornhub');
module.exports = {
self,
@ -25,5 +26,6 @@ module.exports = {
vidbleAlbum,
gfycat,
eroshareAlbum,
eroshareItem
eroshareItem,
pornhub,
};

39
src/methods/pornhub.js Normal file
View File

@ -0,0 +1,39 @@
'use strict';
const fetch = require('node-fetch');
async function pornhub(post) {
const res = await fetch(`https://www.pornhub.com/view_video.php?viewkey=${post.host.id}`);
if (res.status !== 200) {
throw new Error(`Could not fetch info for vidble album '${post.host.id}': '${res.error}'`);
}
const html = await res.text();
const dataString = html.replace(/\s+/g, ' ').match(/var flashvars_.* = (.*); var player_mp4_seek/)[1];
const data = JSON.parse(dataString);
const url = data.mediaDefinitions.sort((sourceA, sourceB) => {
if (sourceA.quality < sourceB.quality) {
return 1;
}
if (sourceA.quality > sourceB.quality) {
return -1;
}
return 0;
})[0].videoUrl;
return {
album: null,
items: [{
id: post.host.id,
url,
title: post.title,
type: 'video/mp4',
datetime: post.datetime,
}],
};
}
module.exports = pornhub;