[addon] remove user-agent header from debrid services
This commit is contained in:
@@ -2,15 +2,13 @@ const AllDebridClient = require('all-debrid-api');
|
||||
const { Type } = require('../lib/types');
|
||||
const { isVideo, isArchive } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheUserAgent } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
const KEY = 'alldebrid';
|
||||
const AGENT = 'torrentio';
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const AD = new AllDebridClient(apiKey, options);
|
||||
const hashes = streams.map(stream => stream.infoHash);
|
||||
const available = await AD.magnet.instant(hashes)
|
||||
@@ -37,7 +35,7 @@ async function getCatalog(apiKey, offset = 0) {
|
||||
if (offset > 0) {
|
||||
return [];
|
||||
}
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const AD = new AllDebridClient(apiKey, options);
|
||||
return AD.magnet.status()
|
||||
.then(response => response.data.magnets)
|
||||
@@ -51,7 +49,7 @@ async function getCatalog(apiKey, offset = 0) {
|
||||
}
|
||||
|
||||
async function getItemMeta(itemId, apiKey) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const AD = new AllDebridClient(apiKey, options);
|
||||
return AD.magnet.status(itemId)
|
||||
.then(response => response.data.magnets)
|
||||
@@ -74,7 +72,7 @@ async function getItemMeta(itemId, apiKey) {
|
||||
|
||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||
console.log(`Unrestricting AllDebrid ${infoHash} [${fileIndex}]`);
|
||||
const options = await getDefaultOptions(apiKey, ip);
|
||||
const options = await getDefaultOptions(ip);
|
||||
const AD = new AllDebridClient(apiKey, options);
|
||||
|
||||
return _resolve(AD, infoHash, cachedEntryInfo, fileIndex)
|
||||
@@ -149,10 +147,8 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
|
||||
return unrestrictedLink;
|
||||
}
|
||||
|
||||
async function getDefaultOptions(id, ip) {
|
||||
const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent());
|
||||
|
||||
return { base_agent: AGENT, timeout: 30000, headers: { 'User-Agent': userAgent } };
|
||||
async function getDefaultOptions(ip) {
|
||||
return { base_agent: AGENT, timeout: 30000 };
|
||||
}
|
||||
|
||||
function statusError(statusCode) {
|
||||
|
||||
@@ -3,14 +3,12 @@ const magnet = require('magnet-uri');
|
||||
const { Type } = require('../lib/types');
|
||||
const { isVideo } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheUserAgent } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
const KEY = 'premiumize';
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const PM = new PremiumizeClient(apiKey, options);
|
||||
const hashes = streams.map(stream => stream.infoHash);
|
||||
const available = await PM.cache.check(hashes)
|
||||
@@ -36,7 +34,7 @@ async function getCatalog(apiKey, offset = 0) {
|
||||
if (offset > 0) {
|
||||
return [];
|
||||
}
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const PM = new PremiumizeClient(apiKey, options);
|
||||
return PM.folder.list()
|
||||
.then(response => response.content)
|
||||
@@ -50,7 +48,7 @@ async function getCatalog(apiKey, offset = 0) {
|
||||
}
|
||||
|
||||
async function getItemMeta(itemId, apiKey, ip) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const PM = new PremiumizeClient(apiKey, options);
|
||||
const rootFolder = await PM.folder.list(itemId, null);
|
||||
return getFolderContents(PM, itemId, ip)
|
||||
@@ -85,7 +83,7 @@ async function getFolderContents(PM, itemId, ip, folderPrefix = '') {
|
||||
|
||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||
console.log(`Unrestricting Premiumize ${infoHash} [${fileIndex}] for IP ${ip}`);
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const PM = new PremiumizeClient(apiKey, options);
|
||||
|
||||
const cachedLink = await _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip).catch(() => undefined);
|
||||
@@ -169,10 +167,8 @@ function statusReady(status) {
|
||||
return ['finished', 'seeding'].includes(status);
|
||||
}
|
||||
|
||||
async function getDefaultOptions(id) {
|
||||
const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent());
|
||||
|
||||
return { timeout: 30000, headers: { 'User-Agent': userAgent } };
|
||||
async function getDefaultOptions(ip) {
|
||||
return { timeout: 30000 };
|
||||
}
|
||||
|
||||
module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta };
|
||||
@@ -3,8 +3,6 @@ const { Type } = require('../lib/types');
|
||||
const { isVideo, isArchive } = require('../lib/extension');
|
||||
const delay = require('./delay');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheUserAgent } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
const MIN_SIZE = 5 * 1024 * 1024; // 5 MB
|
||||
@@ -32,7 +30,7 @@ async function getCachedStreams(streams, apiKey) {
|
||||
}
|
||||
|
||||
async function _getInstantAvailable(hashes, apiKey, retries = 3) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
const options = await getDefaultOptions();
|
||||
const RD = new RealDebridClient(apiKey, options);
|
||||
return RD.torrents.instantAvailability(hashes)
|
||||
.then(response => {
|
||||
@@ -77,7 +75,7 @@ async function getCatalog(apiKey, offset, ip) {
|
||||
if (offset > 0) {
|
||||
return [];
|
||||
}
|
||||
const options = await getDefaultOptions(apiKey, ip);
|
||||
const options = await getDefaultOptions(ip);
|
||||
const RD = new RealDebridClient(apiKey, options);
|
||||
return _getAllTorrents(RD)
|
||||
.then(torrents => Array.isArray(torrents) ? torrents : [])
|
||||
@@ -100,7 +98,7 @@ async function _getAllTorrents(RD, page = 1) {
|
||||
}
|
||||
|
||||
async function getItemMeta(itemId, apiKey, ip) {
|
||||
const options = await getDefaultOptions(apiKey, ip);
|
||||
const options = await getDefaultOptions(ip);
|
||||
const RD = new RealDebridClient(apiKey, options);
|
||||
return _getTorrentInfo(RD, itemId)
|
||||
.then(torrent => ({
|
||||
@@ -123,7 +121,7 @@ async function getItemMeta(itemId, apiKey, ip) {
|
||||
|
||||
async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) {
|
||||
console.log(`Unrestricting RealDebrid ${infoHash} [${fileIndex}]`);
|
||||
const options = await getDefaultOptions(apiKey, ip);
|
||||
const options = await getDefaultOptions(ip);
|
||||
const RD = new RealDebridClient(apiKey, options);
|
||||
|
||||
return _resolve(RD, infoHash, cachedEntryInfo, fileIndex)
|
||||
@@ -290,10 +288,8 @@ function accessDeniedError(error) {
|
||||
return [9, 20].includes(error && error.code);
|
||||
}
|
||||
|
||||
async function getDefaultOptions(id, ip) {
|
||||
const userAgent = await cacheUserAgent(id, () => getRandomUserAgent()).catch(() => getRandomUserAgent());
|
||||
|
||||
return { ip, timeout: 30000, headers: { 'User-Agent': userAgent } };
|
||||
async function getDefaultOptions(ip) {
|
||||
return { ip, timeout: 30000 };
|
||||
}
|
||||
|
||||
module.exports = { getCachedStreams, resolve, getCatalog, getItemMeta };
|
||||
Reference in New Issue
Block a user