From 78b3dda9e392946bc4f72c16abeb7cb151953008 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 17 Mar 2020 19:19:32 +0100 Subject: [PATCH] [addon] fixed file selection for multiple files on undefined index --- addon/moch/realdebrid.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addon/moch/realdebrid.js b/addon/moch/realdebrid.js index 213681f..0bc60f8 100644 --- a/addon/moch/realdebrid.js +++ b/addon/moch/realdebrid.js @@ -44,7 +44,8 @@ async function _unrestrict(apiKey, infoHash, fileIndex) { console.log(`Retrieved torrentId: ${torrentId}`); if (torrentId) { const info = await RD.torrents.info(torrentId); - const targetFile = info.files.find(file => file.id === fileIndex + 1); + const targetFile = info.files.find(file => file.id === fileIndex + 1) + || info.files.filter(file => file.selected).sort((a, b) => b.bytes - a.bytes)[0]; const selectedFiles = info.files.filter(file => file.selected); const fileLink = info.links.length === 1 ? info.links[0]