From 8d75cc170d59efa4d716fc88c4b0e27e2896e855 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:57 +0200 Subject: [PATCH] Added basic PornHub support. --- src/dissectLink.js | 4 ++++ src/methods/methods.js | 28 +++++++++++++++------------- src/methods/pornhub.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/methods/pornhub.js diff --git a/src/dissectLink.js b/src/dissectLink.js index 0ee0e11..27d6a8f 100644 --- a/src/dissectLink.js +++ b/src/dissectLink.js @@ -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) { diff --git a/src/methods/methods.js b/src/methods/methods.js index a31bab7..82d80aa 100644 --- a/src/methods/methods.js +++ b/src/methods/methods.js @@ -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, }; diff --git a/src/methods/pornhub.js b/src/methods/pornhub.js new file mode 100644 index 0000000..6240c30 --- /dev/null +++ b/src/methods/pornhub.js @@ -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;