-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: accept tvp url and fetch m3u8 playlist under the hood
- Loading branch information
Showing
4 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './chat.interface'; | ||
export * from './message.interface'; | ||
export * from './video.interface'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IVideo { | ||
parse(url: URL): Promise<URL>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { fetch, ResponseType } from '@tauri-apps/api/http'; | ||
import { IVideo } from '../interfaces'; | ||
|
||
export class Tvp implements IVideo { | ||
async parse(url: URL): Promise<URL> { | ||
const { data } = await fetch<string>(url.toString(), { | ||
method: 'GET', | ||
responseType: ResponseType.Text, | ||
}); | ||
const [, videoId] = data.replace(/\s+/g, '').match(/"video_id":(\d+)/)!; | ||
const { data: json } = await fetch<Record<string, any>>( | ||
`https://api.tvp.pl/tokenizer/token/${videoId}`, | ||
); | ||
return new URL( | ||
json.formats.find( | ||
({ mimeType }: { mimeType: string }) => | ||
mimeType === 'application/x-mpegurl', | ||
).url, | ||
); | ||
} | ||
} |