keep stremio subtitle loads untouched

This commit is contained in:
dirtydishes 2026-05-25 07:07:59 -04:00
parent dc11afc45f
commit 6a29dde857
5 changed files with 196 additions and 8 deletions

View file

@ -129,7 +129,7 @@ enum SubtitleCandidateParser {
if let candidate = candidate(from: dictionary) {
results.append(candidate)
}
dictionary.values.forEach { collect(from: $0, into: &results) }
orderedNestedValues(in: dictionary).forEach { collect(from: $0, into: &results) }
case let array as [Any]:
array.forEach { collect(from: $0, into: &results) }
case let string as String:
@ -159,6 +159,27 @@ enum SubtitleCandidateParser {
)
}
private static func orderedNestedValues(in dictionary: [String: Any]) -> [Any] {
let preferredKeys = ["subtitles", "subtitle", "files", "downloads", "download"]
var visitedKeys = Set<String>()
var values: [Any] = []
preferredKeys.forEach { key in
if let value = dictionary[key] {
values.append(value)
visitedKeys.insert(key)
}
}
dictionary.keys
.filter { !visitedKeys.contains($0) && !urlFields.contains($0) }
.sorted()
.compactMap { dictionary[$0] }
.forEach { values.append($0) }
return values
}
private static func subtitleURL(from string: String?) -> URL? {
guard let string,
let url = URL(string: string),