feat: add Consumet as provider for stream URL
Summary: Test Plan:
This commit is contained in:
36
src/controllers/episodes/getEpisodeUrl/consumet.ts
Normal file
36
src/controllers/episodes/getEpisodeUrl/consumet.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { aniList } from "~/consumet";
|
||||
import { sortByProperty } from "~/libs/sortByProperty";
|
||||
|
||||
import { qualityPriority, subtitlesPriority } from "./priorities";
|
||||
import type { FetchUrlResponse } from "./responseType";
|
||||
|
||||
export async function getSourcesFromConsumet(
|
||||
watchId: string,
|
||||
): Promise<FetchUrlResponse | null> {
|
||||
try {
|
||||
const { sources, subtitles, intro, outro } =
|
||||
await aniList.fetchEpisodeSources(watchId);
|
||||
|
||||
if (sources.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const source = sources.sort(sortByProperty(qualityPriority, "quality"))[0]
|
||||
?.url;
|
||||
subtitles?.sort(sortByProperty(subtitlesPriority, "lang"));
|
||||
|
||||
return {
|
||||
source,
|
||||
subtitles: subtitles ?? [],
|
||||
audio: [],
|
||||
intro: intro ? [intro.start, intro.end] : undefined,
|
||||
outro: outro ? [outro.start, outro.end] : undefined,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.message === "Episode not found.") {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user