mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 17:03:26 +00:00
feat: add function to parse hls tracks
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
"@movie-web/eslint-config": "workspace:^0.2.0",
|
||||
"@movie-web/prettier-config": "workspace:^0.1.0",
|
||||
"@movie-web/tsconfig": "workspace:^0.1.0",
|
||||
"@types/hls-parser": "^0.8.7",
|
||||
"eslint": "^8.56.0",
|
||||
"prettier": "^3.1.1",
|
||||
"typescript": "^5.3.3"
|
||||
@@ -30,6 +31,7 @@
|
||||
"prettier": "@movie-web/prettier-config",
|
||||
"dependencies": {
|
||||
"@movie-web/providers": "^2.2.0",
|
||||
"hls-parser": "^0.10.8",
|
||||
"srt-webvtt": "^2.0.0",
|
||||
"tmdb-ts": "^1.6.1"
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { parse } from "hls-parser";
|
||||
import { MasterPlaylist } from "hls-parser/types";
|
||||
import { default as toWebVTT } from "srt-webvtt";
|
||||
|
||||
import type {
|
||||
@@ -103,3 +105,28 @@ export function findHighestQuality(
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export async function extractTracksFromHLS(
|
||||
playlistUrl: string,
|
||||
headers: Record<string, string>,
|
||||
) {
|
||||
try {
|
||||
const response = await fetch(playlistUrl, { headers }).then((res) =>
|
||||
res.text(),
|
||||
);
|
||||
const playlist = parse(response);
|
||||
if (!playlist.isMasterPlaylist) return null;
|
||||
if (!(playlist instanceof MasterPlaylist)) return null;
|
||||
|
||||
const tracks = playlist.variants.map((variant) => {
|
||||
return {
|
||||
video: variant.video,
|
||||
audio: variant.audio,
|
||||
subtitles: variant.subtitles,
|
||||
};
|
||||
});
|
||||
return tracks;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user