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