1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-22 07:37:29 +00:00

Sort formats from Invidious extractor correctly

This commit is contained in:
Cadence Ember 2021-11-05 16:13:20 +13:00
parent a11febd426
commit 741a1199dd
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -43,19 +43,23 @@ function formatOrder(format) {
}
function sortFormats(video, preference) {
const standard = video.formatStreams.slice().sort((a, b) => b.second__height - a.second__height)
const adaptive = video.adaptiveFormats.filter(f => f.type.startsWith("video") && f.qualityLabel).sort((a, b) => a.second__order - b.second__order)
let formats = standard.concat(adaptive)
// Add second__ extensions to format objects, required if Invidious was the extractor
let formats = video.formatStreams.concat(video.adaptiveFormats)
for (const format of formats) {
if (!format.second__height && format.resolution) format.second__height = +format.resolution.slice(0, -1)
if (!format.second__order) format.second__order = formatOrder(format)
format.cloudtube__label = `${format.qualityLabel} ${format.container}`
}
for (const format of adaptive) {
format.cloudtube__label += " *"
}
// Properly build and order format list
const standard = video.formatStreams.slice().sort((a, b) => b.second__height - a.second__height)
const adaptive = video.adaptiveFormats.filter(f => f.type.startsWith("video") && f.qualityLabel).sort((a, b) => a.second__order - b.second__order)
for (const format of adaptive) {
if (!format.cloudtube__label.endsWith("*")) format.cloudtube__label += " *"
}
formats = standard.concat(adaptive)
// Reorder fomats based on user preference
if (preference === 1) { // best dash
formats.sort((a, b) => {
const a1 = a.second__height + a.fps / 100