fix: resolve unknown speed flickering and ultra-wide high-resolution detection

- Ignore 'Unknown' or '-' speed/ETA updates if a valid speed is already known to prevent UI flickering.
- Improve high-resolution video detection by checking 'format_note', parsing the 'resolution' string, and using more relaxed height tolerances to correctly identify ultra-wide formats (e.g., 2160p with a 1920 height).
This commit is contained in:
NimBold
2026-06-11 14:04:57 +03:30
parent 1c8f189b54
commit aa9b3aad2a
2 changed files with 46 additions and 6 deletions
+10 -4
View File
@@ -554,8 +554,11 @@ final class DownloadController: ObservableObject {
guard $0.status == .downloading else { return }
$0.progress = progress.fraction
$0.bytesText = progress.bytesText
$0.speedText = progress.speedText
$0.etaText = progress.etaText
let isUnknown = progress.speedText.lowercased() == "unknown" || progress.speedText == "-"
if !isUnknown || $0.speedText == "-" || $0.speedText.lowercased() == "unknown" {
$0.speedText = progress.speedText
$0.etaText = progress.etaText
}
$0.connectionCount = progress.connectionCount
if $0.message == "Starting" {
$0.message = "Downloading Media"
@@ -612,8 +615,11 @@ final class DownloadController: ObservableObject {
guard $0.status == .downloading else { return }
$0.progress = progress.fraction
$0.bytesText = progress.bytesText
$0.speedText = progress.speedText
$0.etaText = progress.etaText
let isUnknown = progress.speedText.lowercased() == "unknown" || progress.speedText == "-"
if !isUnknown || $0.speedText == "-" || $0.speedText.lowercased() == "unknown" {
$0.speedText = progress.speedText
$0.etaText = progress.etaText
}
$0.connectionCount = progress.connectionCount
$0.message = "Downloading"
}
+36 -2
View File
@@ -271,7 +271,7 @@ enum MediaExtractionEngine {
let availableResolutions = standardResolutions.filter { resolution, _ in
rawFormats.contains { format in
isVideo(format) && (format.height ?? 0) > 0 && (format.height ?? 0) <= resolution && (format.height ?? 0) >= resolution - 100
isVideo(format) && matchesHeight(format, height: resolution)
}
}
let videoQualities = [(nil as Int?, "Best")] + availableResolutions.map { (Optional($0.0), $0.1) }
@@ -415,8 +415,42 @@ enum MediaExtractionEngine {
private static func matchesHeight(_ format: RawMediaFormat, height: Int?) -> Bool {
guard let height else { return true }
if let note = format.format_note {
if height == 2160 && (note.contains("2160p") || note.contains("4K") || note.contains("4k")) { return true }
if height == 1440 && note.contains("1440p") { return true }
if height == 1080 && note.contains("1080p") { return true }
if height == 720 && note.contains("720p") { return true }
if height == 480 && note.contains("480p") { return true }
if height == 360 && note.contains("360p") { return true }
}
if let res = format.resolution {
let parts = res.split(separator: "x").compactMap { Int($0) }
if parts.count == 2 {
let maxDim = max(parts[0], parts[1])
switch height {
case 2160: return maxDim >= 3800
case 1440: return maxDim >= 2500 && maxDim < 3800
case 1080: return maxDim >= 1900 && maxDim < 2500
case 720: return maxDim >= 1200 && maxDim < 1900
case 480: return maxDim >= 800 && maxDim < 1200
case 360: return maxDim >= 600 && maxDim < 800
default: break
}
}
}
guard let formatHeight = format.height else { return false }
return formatHeight <= height && formatHeight >= height - 100
let tolerance: Int
if height >= 2160 { tolerance = 600 }
else if height >= 1440 { tolerance = 400 }
else if height >= 1080 { tolerance = 300 }
else if height >= 720 { tolerance = 200 }
else { tolerance = 100 }
return formatHeight <= height && formatHeight >= height - tolerance
}
private static func formatSize(_ format: RawMediaFormat) -> Int64? {