Added basic PornHub support.

This commit is contained in:
ThePendulum 2018-07-08 01:08:20 +02:00
parent 346a946244
commit 1b29d8fb96
3 changed files with 58 additions and 13 deletions

View File

@ -50,6 +50,10 @@ const hosts = [{
method: 'eroshareItem', method: 'eroshareItem',
label: 'eroshare', label: 'eroshare',
pattern: new UrlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)'), 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) { module.exports = function dissectLink(url) {

View File

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