diff --git a/addon/addon.js b/addon/addon.js index fd4eaf3..184b45a 100644 --- a/addon/addon.js +++ b/addon/addon.js @@ -46,7 +46,7 @@ builder.defineCatalogHandler((args) => { cacheMaxAge: CATALOG_CACHE_MAX_AGE })) .catch(error => { - return Promise.reject(`Failed retrieving catalog ${args.id}: ${JSON.stringify(error)}`); + return Promise.reject(`Failed retrieving catalog ${args.id}: ${JSON.stringify(error.message || error)}`); }); }) diff --git a/addon/moch/premiumize.js b/addon/moch/premiumize.js index 128d849..6f2fb93 100644 --- a/addon/moch/premiumize.js +++ b/addon/moch/premiumize.js @@ -95,7 +95,7 @@ export async function resolve({ ip, isBrowser, apiKey, infoHash, cachedEntryInfo return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser) .catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)) .catch(error => { - if (error?.message?.includes('Account not premium.')) { + if (isAccessDeniedError(error)) { console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`); return StaticResponse.FAILED_ACCESS; } @@ -187,6 +187,15 @@ function statusReady(status) { return ['finished', 'seeding'].includes(status); } +function isAccessDeniedError(error) { + return ['Account not premium.'].some(value => error?.message?.includes(value)); +} + +function isLimitExceededError(error) { + return ['Fair use limit reached!', 'You already have a maximum of 25 active downloads in progress!'] + .some(value => error?.message?.includes(value)); +} + async function getDefaultOptions(ip) { return { timeout: 5000 }; } diff --git a/addon/moch/realdebrid.js b/addon/moch/realdebrid.js index 7e25e84..f3d18c6 100644 --- a/addon/moch/realdebrid.js +++ b/addon/moch/realdebrid.js @@ -120,14 +120,18 @@ export async function resolve({ ip, isBrowser, apiKey, infoHash, fileIndex }) { return _resolve(RD, infoHash, fileIndex, isBrowser) .catch(error => { - if (accessDeniedError(error)) { + if (isAccessDeniedError(error)) { console.log(`Access denied to RealDebrid ${infoHash} [${fileIndex}]`); return StaticResponse.FAILED_ACCESS; } - if (infringingFile(error)) { + if (isInfringingFileError(error)) { console.log(`Infringing file removed from RealDebrid ${infoHash} [${fileIndex}]`); return StaticResponse.FAILED_INFRINGEMENT; } + if (isLimitExceededError(error)) { + console.log(`Limits exceeded in RealDebrid ${infoHash} [${fileIndex}]`); + return StaticResponse.LIMITS_EXCEEDED; + } return Promise.reject(`Failed RealDebrid adding torrent ${JSON.stringify(error)}`); }); } @@ -307,7 +311,7 @@ export function toCommonError(error) { if (error && error.code === 8) { return BadTokenError; } - if (error && accessDeniedError(error)) { + if (error && isAccessDeniedError(error)) { return AccessDeniedError; } return undefined; @@ -337,12 +341,16 @@ function statusReady(status) { return ['downloaded', 'dead'].includes(status); } -function accessDeniedError(error) { - return [9, 20].includes(error?.code); +function isAccessDeniedError(error) { + return [8, 9, 20].includes(error?.code); } -function infringingFile(error) { - return error && error.code === 35; +function isInfringingFileError(error) { + return [35].includes(error?.code); +} + +function isLimitExceededError(error) { + return [21, 23, 26, 29, 36].includes(error?.code); } async function getDefaultOptions(ip) {