You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
import { RunOutput } from "@movie-web/providers"; |
|
|
|
import { |
|
SourceFileStream, |
|
SourceQuality, |
|
SourceSliceSource, |
|
} from "@/stores/player/utils/qualities"; |
|
|
|
const allowedQualitiesMap: Record<SourceQuality, SourceQuality> = { |
|
"1080": "1080", |
|
"480": "480", |
|
"360": "360", |
|
"720": "720", |
|
unknown: "unknown", |
|
}; |
|
const allowedQualities = Object.keys(allowedQualitiesMap); |
|
const allowedFileTypes = ["mp4"]; |
|
|
|
function isAllowedQuality(inp: string): inp is SourceQuality { |
|
return allowedQualities.includes(inp); |
|
} |
|
|
|
export function convertRunoutputToSource(out: { |
|
stream: RunOutput["stream"]; |
|
}): SourceSliceSource { |
|
if (out.stream.type === "hls") { |
|
return { |
|
type: "hls", |
|
url: out.stream.playlist, |
|
}; |
|
} |
|
if (out.stream.type === "file") { |
|
const qualities: Partial<Record<SourceQuality, SourceFileStream>> = {}; |
|
Object.entries(out.stream.qualities).forEach((entry) => { |
|
if (!isAllowedQuality(entry[0])) { |
|
console.warn(`unrecognized quality: ${entry[0]}`); |
|
return; |
|
} |
|
if (!allowedFileTypes.includes(entry[1].type)) { |
|
console.warn(`unrecognized file type: ${entry[1].type}`); |
|
return; |
|
} |
|
qualities[entry[0]] = { |
|
type: entry[1].type, |
|
url: entry[1].url, |
|
}; |
|
}); |
|
return { |
|
type: "file", |
|
qualities, |
|
}; |
|
} |
|
throw new Error("unrecognized type"); |
|
}
|
|
|