mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
try to handle common debrid error for catalog retrieval
This commit is contained in:
@@ -14,11 +14,8 @@ export async function getCachedStreams(streams, apiKey) {
|
|||||||
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)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.code === 'AUTH_BAD_APIKEY') {
|
if (toCommonError(error)) {
|
||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(error);
|
||||||
}
|
|
||||||
if (error && error.code === 'AUTH_USER_BANNED') {
|
|
||||||
return Promise.reject(AccessDeniedError);
|
|
||||||
}
|
}
|
||||||
console.warn(`Failed AllDebrid cached [${hashes[0]}] torrent availability request:`, error);
|
console.warn(`Failed AllDebrid cached [${hashes[0]}] torrent availability request:`, error);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -166,6 +163,16 @@ async function getDefaultOptions(ip) {
|
|||||||
return { base_agent: AGENT, timeout: 30000 };
|
return { base_agent: AGENT, timeout: 30000 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
if (error && error.code === 'AUTH_BAD_APIKEY') {
|
||||||
|
return BadTokenError;
|
||||||
|
}
|
||||||
|
if (error && error.code === 'AUTH_USER_BANNED') {
|
||||||
|
return AccessDeniedError;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusError(statusCode) {
|
function statusError(statusCode) {
|
||||||
return [5, 6, 7, 8, 9, 10, 11].includes(statusCode);
|
return [5, 6, 7, 8, 9, 10, 11].includes(statusCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export async function getCachedStreams(streams, apiKey) {
|
|||||||
.then(results => results.map(result => result.value))
|
.then(results => results.map(result => result.value))
|
||||||
.then(results => results.reduce((all, result) => Object.assign(all, result), {}))
|
.then(results => results.reduce((all, result) => Object.assign(all, result), {}))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error === 'badToken') {
|
if (toCommonError(error)) {
|
||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
console.warn('Failed DebridLink cached torrent availability request:', error);
|
console.warn('Failed DebridLink cached torrent availability request:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -135,6 +135,13 @@ async function getDefaultOptions(ip) {
|
|||||||
return { ip, timeout: 30000 };
|
return { ip, timeout: 30000 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
if (error === 'badToken') {
|
||||||
|
return BadTokenError;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusDownloading(torrent) {
|
function statusDownloading(torrent) {
|
||||||
return torrent.downloadPercent < 100
|
return torrent.downloadPercent < 100
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { cacheWrapResolvedUrl } from '../lib/cache.js';
|
|||||||
import { timeout } from '../lib/promises.js';
|
import { timeout } from '../lib/promises.js';
|
||||||
import { BadTokenError, streamFilename, AccessDeniedError, enrichMeta } from './mochHelper.js';
|
import { BadTokenError, streamFilename, AccessDeniedError, enrichMeta } from './mochHelper.js';
|
||||||
import { isStaticUrl } from './static.js';
|
import { isStaticUrl } from './static.js';
|
||||||
|
import { toCommonError } from "./realdebrid.js";
|
||||||
|
|
||||||
const RESOLVE_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
const RESOLVE_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
||||||
const MIN_API_KEY_SYMBOLS = 15;
|
const MIN_API_KEY_SYMBOLS = 15;
|
||||||
@@ -81,7 +82,8 @@ export async function applyMochs(streams, config) {
|
|||||||
}
|
}
|
||||||
return moch.instance.getCachedStreams(streams, config[moch.key])
|
return moch.instance.getCachedStreams(streams, config[moch.key])
|
||||||
.then(mochStreams => ({ moch, mochStreams }))
|
.then(mochStreams => ({ moch, mochStreams }))
|
||||||
.catch(error => {
|
.catch(rawError => {
|
||||||
|
const error = moch.instance.toCommonError(rawError) || rawError;
|
||||||
if (error === BadTokenError) {
|
if (error === BadTokenError) {
|
||||||
blackListToken(config[moch.key], moch.key);
|
blackListToken(config[moch.key], moch.key);
|
||||||
}
|
}
|
||||||
@@ -120,7 +122,14 @@ export async function getMochCatalog(mochKey, config) {
|
|||||||
if (isInvalidToken(config[mochKey], mochKey)) {
|
if (isInvalidToken(config[mochKey], mochKey)) {
|
||||||
return Promise.reject(new Error(`Invalid API key for moch provider: ${mochKey}`));
|
return Promise.reject(new Error(`Invalid API key for moch provider: ${mochKey}`));
|
||||||
}
|
}
|
||||||
return moch.instance.getCatalog(config[moch.key], config.skip, config.ip);
|
return moch.instance.getCatalog(config[moch.key], config.skip, config.ip)
|
||||||
|
.catch(rawError => {
|
||||||
|
const commonError = moch.instance.toCommonError(rawError);
|
||||||
|
if (commonError === BadTokenError) {
|
||||||
|
blackListToken(config[moch.key], moch.key);
|
||||||
|
}
|
||||||
|
return commonError ? [] : Promise.reject(rawError);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMochItemMeta(mochKey, itemId, config) {
|
export async function getMochItemMeta(mochKey, itemId, config) {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export async function getCachedStreams(streams, apiKey) {
|
|||||||
.then(results => results.map(result => result.cachedItems))
|
.then(results => results.map(result => result.cachedItems))
|
||||||
.then(results => results.reduce((all, result) => all.concat(result), []))
|
.then(results => results.reduce((all, result) => all.concat(result), []))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.error === 'NOAUTH') {
|
if (toCommonError(error)) {
|
||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
console.warn('Failed Offcloud cached torrent availability request:', error);
|
console.warn('Failed Offcloud cached torrent availability request:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -43,6 +43,7 @@ export async function getCatalog(apiKey, offset = 0) {
|
|||||||
const options = await getDefaultOptions();
|
const options = await getDefaultOptions();
|
||||||
const OC = new OffcloudClient(apiKey, options);
|
const OC = new OffcloudClient(apiKey, options);
|
||||||
return OC.cloud.history()
|
return OC.cloud.history()
|
||||||
|
.then(torrents => torrents)
|
||||||
.then(torrents => (torrents || [])
|
.then(torrents => (torrents || [])
|
||||||
.filter(torrent => torrent && statusReady(torrent))
|
.filter(torrent => torrent && statusReady(torrent))
|
||||||
.map(torrent => ({
|
.map(torrent => ({
|
||||||
@@ -137,6 +138,13 @@ async function getDefaultOptions(ip) {
|
|||||||
return { ip, timeout: 30000 };
|
return { ip, timeout: 30000 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
if (error?.error === 'NOAUTH' || error?.message?.startsWith('Cannot read property')) {
|
||||||
|
return BadTokenError;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusDownloading(torrent) {
|
function statusDownloading(torrent) {
|
||||||
return ['downloading', 'created'].includes(torrent.status);
|
return ['downloading', 'created'].includes(torrent.status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ async function _getCachedStreams(PM, apiKey, streams) {
|
|||||||
const hashes = streams.map(stream => stream.infoHash);
|
const hashes = streams.map(stream => stream.infoHash);
|
||||||
return PM.cache.check(hashes)
|
return PM.cache.check(hashes)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.message === 'Not logged in.') {
|
if (toCommonError(error)) {
|
||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
console.warn('Failed Premiumize cached torrent availability request:', error);
|
console.warn('Failed Premiumize cached torrent availability request:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -163,6 +163,13 @@ async function _retryCreateTorrent(PM, infoHash, encodedFileName, fileIndex) {
|
|||||||
: StaticResponse.FAILED_DOWNLOAD;
|
: StaticResponse.FAILED_DOWNLOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
if (error && error.message === 'Not logged in.') {
|
||||||
|
return BadTokenError;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusError(status) {
|
function statusError(status) {
|
||||||
return ['deleted', 'error', 'timeout'].includes(status);
|
return ['deleted', 'error', 'timeout'].includes(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { isVideo } from '../lib/extension.js';
|
|||||||
import { delay } from '../lib/promises.js';
|
import { delay } from '../lib/promises.js';
|
||||||
import StaticResponse from './static.js';
|
import StaticResponse from './static.js';
|
||||||
import { getMagnetLink } from '../lib/magnetHelper.js';
|
import { getMagnetLink } from '../lib/magnetHelper.js';
|
||||||
|
import { BadTokenError } from "./mochHelper.js";
|
||||||
|
|
||||||
export async function getCachedStreams(streams, apiKey) {
|
export async function getCachedStreams(streams, apiKey) {
|
||||||
return streams
|
return streams
|
||||||
@@ -140,6 +141,10 @@ async function _getPublicToken(Putio, targetVideoId) {
|
|||||||
return Putio.File.CreatePublicLink(targetVideoId).then(response => response.data.token);
|
return Putio.File.CreatePublicLink(targetVideoId).then(response => response.data.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusError(status) {
|
function statusError(status) {
|
||||||
return ['ERROR'].includes(status);
|
return ['ERROR'].includes(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,8 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3, maxChunkSize =
|
|||||||
.then(results => cacheAvailabilityResults(results))
|
.then(results => cacheAvailabilityResults(results))
|
||||||
.then(results => Object.assign(cachedResults, results))
|
.then(results => Object.assign(cachedResults, results))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.code === 8) {
|
if (toCommonError(error)) {
|
||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(error);
|
||||||
}
|
|
||||||
if (error && accessDeniedError(error)) {
|
|
||||||
return Promise.reject(AccessDeniedError);
|
|
||||||
}
|
}
|
||||||
if (!error && maxChunkSize !== 1) {
|
if (!error && maxChunkSize !== 1) {
|
||||||
// sometimes due to large response size RD responds with an empty body. Reduce chunk size to reduce body
|
// sometimes due to large response size RD responds with an empty body. Reduce chunk size to reduce body
|
||||||
@@ -355,6 +352,16 @@ async function _unrestrictFileLink(RD, fileLink, torrent, fileIndex, isBrowser)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCommonError(error) {
|
||||||
|
if (error && error.code === 8) {
|
||||||
|
return BadTokenError;
|
||||||
|
}
|
||||||
|
if (error && accessDeniedError(error)) {
|
||||||
|
return AccessDeniedError;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function statusError(status) {
|
function statusError(status) {
|
||||||
return ['error', 'magnet_error'].includes(status);
|
return ['error', 'magnet_error'].includes(status);
|
||||||
}
|
}
|
||||||
|
|||||||
8
addon/package-lock.json
generated
8
addon/package-lock.json
generated
@@ -21,7 +21,7 @@
|
|||||||
"magnet-uri": "^6.2.0",
|
"magnet-uri": "^6.2.0",
|
||||||
"name-to-imdb": "^3.0.4",
|
"name-to-imdb": "^3.0.4",
|
||||||
"named-queue": "^2.2.1",
|
"named-queue": "^2.2.1",
|
||||||
"offcloud-api": "^1.0.0",
|
"offcloud-api": "^1.0.1",
|
||||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
"premiumize-api": "^1.0.3",
|
"premiumize-api": "^1.0.3",
|
||||||
@@ -1392,9 +1392,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/offcloud-api": {
|
"node_modules/offcloud-api": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/offcloud-api/-/offcloud-api-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/offcloud-api/-/offcloud-api-1.0.1.tgz",
|
||||||
"integrity": "sha512-cJNoQSl2CJHKrXHRV/+6FMFqToZs/ungdYGNQQOdSuI1FKY7Y5bEOsqlL8BuAxRMd91wKzA4xBmjvrHq5ZllEg==",
|
"integrity": "sha512-O49iJRy4ein/VcaINw+3wSVWonEd4BEBCLbgD/fyxIHPf7eW1CSYnyEdrm6+E1k/lMlpTcvx7yk/hvh1iLfoOg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"request": "^2.83.0"
|
"request": "^2.83.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"magnet-uri": "^6.2.0",
|
"magnet-uri": "^6.2.0",
|
||||||
"name-to-imdb": "^3.0.4",
|
"name-to-imdb": "^3.0.4",
|
||||||
"named-queue": "^2.2.1",
|
"named-queue": "^2.2.1",
|
||||||
"offcloud-api": "^1.0.0",
|
"offcloud-api": "^1.0.1",
|
||||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#022408972c2a040f846331a912a6a8487746a654",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
"premiumize-api": "^1.0.3",
|
"premiumize-api": "^1.0.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user