From 314ff985555f1447a0a0502ebee5d050ee699c8a Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Fri, 15 May 2020 12:26:39 +0200 Subject: [PATCH] [addon] adds better logging for alldebrid --- addon/moch/alldebrid.js | 15 +++++++++------ addon/moch/moch.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/addon/moch/alldebrid.js b/addon/moch/alldebrid.js index 469f907..cdc6636 100644 --- a/addon/moch/alldebrid.js +++ b/addon/moch/alldebrid.js @@ -13,7 +13,7 @@ async function getCachedStreams(streams, apiKey) { console.warn('Failed AllDebrid cached torrent availability request: ', error); return undefined; }); - return available && available.data && streams + return available && available.data && available.data.magnets && streams .reduce((mochStreams, stream) => { const cachedEntry = available.data.magnets.find(magnet => stream.infoHash === magnet.hash.toLowerCase()); const streamTitleParts = stream.title.replace(/\n👤.*/s, '').split('\n'); @@ -29,20 +29,23 @@ async function getCachedStreams(streams, apiKey) { } async function resolve({ ip, apiKey, infoHash, cachedEntryInfo, fileIndex }) { - console.log(`Unrestricting ${infoHash} [${fileIndex}]`); + console.log(`Unrestricting AllDebrid ${infoHash} [${fileIndex}]`); const options = await getDefaultOptions(apiKey, ip); const AD = new AllDebridClient(apiKey, options); const torrent = await _createOrFindTorrent(AD, infoHash); if (torrent && statusReady(torrent.statusCode)) { return _unrestrictLink(AD, torrent, cachedEntryInfo, fileIndex); } else if (torrent && statusDownloading(torrent.statusCode)) { + console.log(`Downloading to AllDebrid ${infoHash} [${fileIndex}]...`); return StaticResponse.DOWNLOADING; } else if (torrent && statusHandledError(torrent.statusCode)) { + console.log(`Retrying downloading to AllDebrid ${infoHash} [${fileIndex}]...`); return _retryCreateTorrent(AD, infoHash, cachedEntryInfo, fileIndex); } else if (torrent && errorExpiredSubscriptionError(torrent)) { + console.log(`Access denied to AllDebrid ${infoHash} [${fileIndex}]`); return StaticResponse.FAILED_ACCESS; } - return Promise.reject("Failed AllDebrid adding torrent"); + return Promise.reject(`Failed AllDebrid adding torrent ${torrent}`); } async function _createOrFindTorrent(AD, infoHash) { @@ -83,11 +86,11 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) { ? videos.find(video => targetFileName.includes(video.filename)) : videos.sort((a, b) => b.size - a.size)[0]; - if (!targetVideo.link || !targetVideo.link.length) { - return Promise.reject("No available links found"); + if (!targetVideo || targetVideo.link || !targetVideo.link.length) { + return Promise.reject(`No AllDebrid links found for [${torrent.hash}] ${encodedFileName}`); } const unrestrictedLink = await AD.link.unlock(targetVideo.link).then(response => response.data.link); - console.log(`Unrestricted ${torrent.hash} [${fileIndex}] to ${unrestrictedLink}`); + console.log(`Unrestricted AllDebrid ${torrent.hash} [${fileIndex}] to ${unrestrictedLink}`); return unrestrictedLink; } diff --git a/addon/moch/moch.js b/addon/moch/moch.js index c346098..6c8de28 100644 --- a/addon/moch/moch.js +++ b/addon/moch/moch.js @@ -70,7 +70,7 @@ async function applyMochs(streams, config) { async function resolve(parameters) { const moch = MOCHS[parameters.mochKey]; if (!moch) { - return Promise.reject('Not a valid moch provider'); + return Promise.reject(`Not a valid moch provider: ${parameters.mochKey}`); } if (!parameters.apiKey || !parameters.infoHash || !parameters.cachedEntryInfo) {