Added dynamic dividers to patterns. Fixed PornHub module. Updated README.

This commit is contained in:
2024-09-11 05:16:57 +02:00
parent c4d434ecdf
commit 5c7dca19e5
8 changed files with 899 additions and 122 deletions

View File

@@ -1,38 +1,31 @@
'use strict';
const fetch = require('node-fetch');
const youtubedl = require('youtube-dl');
const dateFns = require('date-fns');
async function pornhub(host, post) {
const res = await fetch(`https://www.pornhub.com/view_video.php?viewkey=${host.id}`);
async function pornhub(host) {
const data = await new Promise((resolve, reject) => {
youtubedl.getInfo(`https://www.pornhub.com/view_video.php?viewkey=${host.id}`, null, (error, info) => {
if (error) {
reject(error);
}
if (res.status !== 200) {
throw new Error(`Could not fetch info PornHub video '${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;
resolve(info);
});
});
return {
album: null,
items: [{
id: host.id,
url,
title: post ? post.title : null,
type: 'video/mp4',
datetime: post ? post.datetime : null,
}],
items: [
{
id: data.id,
url: data.url,
title: data.fulltitle || data.title,
type: `video/${data.ext}`,
datetime: dateFns.format(data.upload_date, 'YYYYMMDD'),
original: data,
},
],
};
}