[scraper] uses forked rd library

This commit is contained in:
TheBeastLT
2020-04-03 10:28:49 +02:00
parent 2833c9d3a2
commit c2e42634b7
4 changed files with 16 additions and 15 deletions

View File

@@ -16,11 +16,4 @@ function getRandomProxy() {
return undefined;
}
function getProxy() {
if (PROXY_HOSTS && PROXY_HOSTS.length && PROXY_USERNAME && PROXY_PASSWORD) {
return `http://${PROXY_USERNAME}:${PROXY_PASSWORD}@${PROXY_HOSTS[0]}`;
}
return undefined;
}
module.exports = { getRandomUserAgent, getRandomProxy, getProxy };
module.exports = { getRandomUserAgent, getRandomProxy };

View File

@@ -2,7 +2,7 @@ const { encode } = require('magnet-uri');
const RealDebridClient = require('real-debrid-api');
const namedQueue = require('named-queue');
const { cacheWrapResolvedUrl } = require('../lib/cache');
const { getProxy } = require('../lib/request_helper');
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
const unrestrictQueue = new namedQueue((task, callback) => task.method()
.then(result => callback(false, result))
@@ -22,7 +22,7 @@ async function resolve(apiKey, infoHash, cachedFileIds, fileIndex) {
async function _unrestrict(apiKey, infoHash, cachedFileIds, fileIndex) {
console.log(`Unrestricting ${infoHash} [${fileIndex}]`);
const RD = new RealDebridClient(apiKey);
const RD = new RealDebridClient(apiKey, getDefaultOptions());
const torrentId = await _createOrFindTorrentId(RD, infoHash, cachedFileIds);
if (torrentId) {
const info = await RD.torrents.info(torrentId);
@@ -56,7 +56,7 @@ async function _unrestrictLink(RD, link) {
if (!link || !link.length) {
return Promise.reject("No available links found");
}
return RD._post('unrestrict/link', { form: { link }, proxy: getProxy() })
return RD.unrestrict.link(link)
.then(unrestrictedLink => unrestrictedLink.download);
// .then(unrestrictedLink => RD.streaming.transcode(unrestrictedLink.id))
// .then(transcodedLink => {
@@ -67,4 +67,13 @@ async function _unrestrictLink(RD, link) {
// });
}
function getDefaultOptions() {
return {
proxy: getRandomProxy(),
headers: {
'User-Agent': getRandomUserAgent()
}
};
}
module.exports = { resolve };