Skip to content

Commit

Permalink
Merge pull request #333 from Etherna/fix/EDD-411-importer-sources
Browse files Browse the repository at this point in the history
fix current source initial loading
  • Loading branch information
mattiaz9 authored Aug 24, 2024
2 parents 29e11be + a00d6ae commit baf3044
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/stores/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ export type PlayerState = {
export const QUALITY_STORAGE_KEY = "etherna:player-quality"
export const PLAYER_INITIAL_QUALITY = "360p"

const AUDIO_REGEX = /audio(\/playlist)?\.(mpd|m3u8)$/
const VIDEO_REGEX = /(?<q>([0-9]{3,}p)|([0-9]{3,}p))(\/playlist)?\.(mpd|m3u8)$/
const MANFIEST_REGEX = /(manifest|master)\.(mpd|m3u8)$/

const getCurrentSource = (sources: VideoSource[], quality: PlayerQuality) => {
if (quality === "Audio") {
return sources.find(s => s.type !== "mp4" && s.path.match(/audio\.(mpd|m3u8)$/))
return sources.find(s => s.type !== "mp4" && s.path.match(AUDIO_REGEX))
}
const isAdaptive = sources.some(s => s.type !== "mp4")
if (isAdaptive) {
return sources.find(s => s.type !== "mp4" && s.path.match(/manifest\.(mpd|m3u8)$/))
return sources.find(s => s.type !== "mp4" && s.path.match(MANFIEST_REGEX))
}
const mp4Source =
sources.find(s => s.type === "mp4" && s.quality === quality) ??
Expand Down Expand Up @@ -172,12 +176,9 @@ const actions = (set: SetFunc, get: GetFunc) => ({
setSources(hash: string, sources: VideoSource[]) {
set(state => {
const getAdaptiveSourceQuality = (source: VideoSource & { type: "hls" | "dash" }) => {
if (source.path.match(/audio\.(mpd|m3u8)$/)) return "Audio"
if (source.path.match(/audio\/playlist\.(mpd|m3u8)$/)) return "Audio"
if (source.path.match(/[0-9]{3,}p\.(mpd|m3u8)$/))
return source.path.match(/([0-9]{3,}p)\.(mpd|m3u8)$/)![1] as VideoQuality
if (source.path.match(/[0-9]{3,}p\/playlist\.(mpd|m3u8)$/))
return source.path.match(/([0-9]{3,}p)\/playlist\.(mpd|m3u8)$/)![1] as VideoQuality
if (source.path.match(AUDIO_REGEX)) return "Audio"
if (source.path.match(VIDEO_REGEX))
return source.path.match(VIDEO_REGEX)!.groups!.q as VideoQuality
return "Auto"
}
const preferredQuality = state.currentQuality
Expand Down

0 comments on commit baf3044

Please # to comment.