From fa82ecb0e2f3dbeef42e2318ef1bb087da310e2f Mon Sep 17 00:00:00 2001 From: himanshu8443 Date: Wed, 9 Jul 2025 15:11:38 +0530 Subject: [PATCH] fix: implement pagination for episode retrieval in NetflixMirror --- dist/netflixMirror/episodes.js | 38 ++++++++++++++++---------- providers/netflixMirror/episodes.ts | 42 +++++++++++++++++------------ 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/dist/netflixMirror/episodes.js b/dist/netflixMirror/episodes.js index f6d54a9..5fdafb2 100644 --- a/dist/netflixMirror/episodes.js +++ b/dist/netflixMirror/episodes.js @@ -24,22 +24,32 @@ const getEpisodes = function (_a) { "&t=" + Math.round(new Date().getTime() / 1000); console.log("nfEpisodesUrl", url); - const res = yield axios.get(url, { - headers: { - "Content-Type": "application/json", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", - "Accept-Language": "en-US,en;q=0.9", - }, - }); - const data = res.data; - console.log("nfEpisodes", data); + let page = 1; + let hasMorePages = true; const episodeList = []; - (_b = data === null || data === void 0 ? void 0 : data.episodes) === null || _b === void 0 ? void 0 : _b.map((episode) => { - episodeList.push({ - title: "Episode " + (episode === null || episode === void 0 ? void 0 : episode.ep.replace("E", "")), - link: episode === null || episode === void 0 ? void 0 : episode.id, + while (hasMorePages) { + const res = yield axios.get(url + `&page=${page}`, { + headers: { + "Content-Type": "application/json", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", + "Accept-Language": "en-US,en;q=0.9", + }, }); - }); + const data = res.data; + console.log("nfEpisodes", data); + (_b = data === null || data === void 0 ? void 0 : data.episodes) === null || _b === void 0 ? void 0 : _b.map((episode) => { + episodeList.push({ + title: "Episode " + (episode === null || episode === void 0 ? void 0 : episode.ep.replace("E", "")), + link: episode === null || episode === void 0 ? void 0 : episode.id, + }); + }); + if (data === null || data === void 0 ? void 0 : data.nextPageShow) { + page++; + } + else { + hasMorePages = false; + } + } return episodeList; } catch (err) { diff --git a/providers/netflixMirror/episodes.ts b/providers/netflixMirror/episodes.ts index 0356949..da2f0d0 100644 --- a/providers/netflixMirror/episodes.ts +++ b/providers/netflixMirror/episodes.ts @@ -21,25 +21,33 @@ export const getEpisodes = async function ({ "&t=" + Math.round(new Date().getTime() / 1000); console.log("nfEpisodesUrl", url); - const res = await axios.get(url, { - headers: { - "Content-Type": "application/json", - "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", - "Accept-Language": "en-US,en;q=0.9", - }, - }); - const data = res.data; - console.log("nfEpisodes", data); - + let page = 1; + let hasMorePages = true; const episodeList: EpisodeLink[] = []; - - data?.episodes?.map((episode: any) => { - episodeList.push({ - title: "Episode " + episode?.ep.replace("E", ""), - link: episode?.id, + while (hasMorePages) { + const res = await axios.get(url + `&page=${page}`, { + headers: { + "Content-Type": "application/json", + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", + "Accept-Language": "en-US,en;q=0.9", + }, }); - }); + const data = res.data; + console.log("nfEpisodes", data); + + data?.episodes?.map((episode: any) => { + episodeList.push({ + title: "Episode " + episode?.ep.replace("E", ""), + link: episode?.id, + }); + }); + if (data?.nextPageShow) { + page++; + } else { + hasMorePages = false; + } + } return episodeList; } catch (err) {