mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
fix: refactor episode retrieval to support pagination and sort episodes by title
This commit is contained in:
@@ -8,7 +8,7 @@ export const getEpisodes = async function ({
|
||||
providerContext: ProviderContext;
|
||||
}): Promise<EpisodeLink[]> {
|
||||
const { getBaseUrl, axios } = providerContext;
|
||||
let providerValue = "primeMirror";
|
||||
let providerValue = "netflixMirror";
|
||||
try {
|
||||
const baseUrl = await getBaseUrl("nfMirror");
|
||||
const url =
|
||||
@@ -21,27 +21,38 @@ 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;
|
||||
|
||||
return episodeList;
|
||||
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.sort((a, b) => {
|
||||
const aNum = parseInt(a.title.replace("Episode ", ""));
|
||||
const bNum = parseInt(b.title.replace("Episode ", ""));
|
||||
return aNum - bNum;
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("nfGetEpisodes error", err);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user