Added fix if no sources are found it returns an error in json

This commit is contained in:
Inside4ndroid
2024-07-14 14:23:17 +01:00
parent 21ac9bf72a
commit b5ba2990d2
+26 -8
View File
@@ -5,11 +5,19 @@ import randomUserAgent from 'random-useragent';
import { vidsrcBase, vidplayBase } from "./constants.js"; import { vidsrcBase, vidplayBase } from "./constants.js";
export async function getVidsrctoStreams(sourcesId) { export async function getVidsrctoStreams(sourcesId) {
let vidplay;
const sources = await getVidsrcSources(sourcesId); const sources = await getVidsrcSources(sourcesId);
console.log(sources); console.log(sources);
const vidplay = sources.result.find((v) => v.title.toLowerCase() === 'f2cloud'); try {
vidplay = sources.result.find((v) => v.title.toLowerCase() === 'f2cloud');
} catch (error) {
return { data: sources };
}
if (!vidplay) { if (!vidplay) {
const data = { const data = {
@@ -45,13 +53,13 @@ export async function getVidsrctoStreams(sourcesId) {
return { data: data }; return { data: data };
} else { } else {
const data = { const data = {
file: source, file: source,
sub: subtitles sub: subtitles
}; };
return { data: data }; return { data: data };
} }
} }
@@ -71,9 +79,19 @@ export async function getVidsrcSourcesId(tmdbId, seasonNumber, episodeNumber) {
} }
async function getVidsrcSources(sourceId) { async function getVidsrcSources(sourceId) {
const data = await (await fetch(`${vidsrcBase}/ajax/embed/episode/${sourceId}/sources`)).json(); try {
const response = await fetch(`${vidsrcBase}/ajax/embed/episode/${sourceId}/sources`);
if (!response.ok) {
return 'No Sources Found';
} else {
const data = await response.json();
return data;
}
return data; } catch (error) {
console.error("Error fetching or parsing JSON:", error);
return null; // or handle the error as needed
}
} }
async function getVidsrcSourceDetails(sourceId) { async function getVidsrcSourceDetails(sourceId) {