[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

5
package-lock.json generated
View File

@@ -1995,9 +1995,8 @@
} }
}, },
"real-debrid-api": { "real-debrid-api": {
"version": "1.0.1", "version": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",
"resolved": "https://registry.npmjs.org/real-debrid-api/-/real-debrid-api-1.0.1.tgz", "from": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",
"integrity": "sha512-Rva3aZ62R/KDV7ydUALrVu8YbAuPLLmThWMlmVMshUEBQk74ybRyUv5WTvfrd9i94v+0V9YeZle0pldv5cQ2+g==",
"requires": { "requires": {
"request": "^2.83.0" "request": "^2.83.0"
} }

View File

@@ -37,7 +37,7 @@
"pg": "^7.8.2", "pg": "^7.8.2",
"pg-hstore": "^2.3.2", "pg-hstore": "^2.3.2",
"rarbg-api": "^1.1.3", "rarbg-api": "^1.1.3",
"real-debrid-api": "^1.0.1", "real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",
"sequelize": "^5.21.5", "sequelize": "^5.21.5",
"sugar-date": "^2.0.6", "sugar-date": "^2.0.6",
"torrent-stream": "^1.1.0", "torrent-stream": "^1.1.0",

View File

@@ -16,11 +16,4 @@ function getRandomProxy() {
return undefined; return undefined;
} }
function getProxy() { module.exports = { getRandomUserAgent, getRandomProxy };
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 };

View File

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