chore: cleanup

This commit is contained in:
Adrian Castro
2024-02-15 20:07:48 +01:00
parent b81ff76d98
commit 53106d8b7b
2 changed files with 10 additions and 7 deletions

View File

@@ -169,7 +169,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({ data }) => {
let highestQuality;
let url;
let tracks;
let _tracks;
switch (stream.type) {
case "file":
@@ -178,16 +178,12 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({ data }) => {
return url ?? null;
case "hls":
url = stream.playlist;
tracks = await extractTracksFromHLS(url, {
_tracks = await extractTracksFromHLS(url, {
...stream.preferredHeaders,
...stream.headers,
});
}
if (tracks) {
console.log(tracks);
}
setVideoSrc({
uri: url,
headers: {

View File

@@ -1,3 +1,4 @@
import type { Item } from "parse-hls";
import hls from "parse-hls";
import { default as toWebVTT } from "srt-webvtt";
@@ -105,10 +106,16 @@ export function findHighestQuality(
return undefined;
}
export interface HLSPlaylist {
video: Item[];
audio: Item[];
subtitles: Item[];
}
export async function extractTracksFromHLS(
playlistUrl: string,
headers: Record<string, string>,
) {
): Promise<HLSPlaylist | null> {
try {
const response = await fetch(playlistUrl, { headers }).then((res) =>
res.text(),