mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] improves rd catalog pagination
This commit is contained in:
@@ -75,20 +75,8 @@ async function getCatalog(apiKey, offset = 0) {
|
|||||||
}
|
}
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
let page = 1;
|
return _getAllTorrents(RD)
|
||||||
return RD.torrents.get(page - 1, page, CATALOG_PAGE_SIZE)
|
.then(torrents => Array.isArray(torrents) ? torrents : [])
|
||||||
.then(torrents => torrents && torrents.length === CATALOG_PAGE_SIZE && page < CATALOG_MAX_PAGE
|
|
||||||
? RD.torrents.get(page, page = page + 1)
|
|
||||||
.then(nextTorrents => torrents.concat(nextTorrents))
|
|
||||||
.catch(() => torrents)
|
|
||||||
: torrents)
|
|
||||||
.then(torrents => {
|
|
||||||
if (Array.isArray(torrents)) {
|
|
||||||
return torrents;
|
|
||||||
}
|
|
||||||
console.log(`Received non array response for RealDebrid catalog: `, torrents)
|
|
||||||
return [];
|
|
||||||
})
|
|
||||||
.then(torrents => torrents
|
.then(torrents => torrents
|
||||||
.filter(torrent => statusReady(torrent.status))
|
.filter(torrent => statusReady(torrent.status))
|
||||||
.map(torrent => ({
|
.map(torrent => ({
|
||||||
@@ -98,6 +86,15 @@ async function getCatalog(apiKey, offset = 0) {
|
|||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function _getAllTorrents(RD, page = 1) {
|
||||||
|
return RD.torrents.get(page - 1, page, CATALOG_PAGE_SIZE)
|
||||||
|
.then(torrents => torrents && torrents.length === CATALOG_PAGE_SIZE && page < CATALOG_MAX_PAGE
|
||||||
|
? _getAllTorrents(RD, page + 1)
|
||||||
|
.then(nextTorrents => torrents.concat(nextTorrents))
|
||||||
|
.catch(() => torrents)
|
||||||
|
: torrents)
|
||||||
|
}
|
||||||
|
|
||||||
async function getItemMeta(itemId, apiKey) {
|
async function getItemMeta(itemId, apiKey) {
|
||||||
const options = await getDefaultOptions(apiKey);
|
const options = await getDefaultOptions(apiKey);
|
||||||
const RD = new RealDebridClient(apiKey, options);
|
const RD = new RealDebridClient(apiKey, options);
|
||||||
|
|||||||
Reference in New Issue
Block a user