mirror of
https://github.com/dirtydishes/dreamio.git
synced 2026-06-06 13:37:24 +00:00
keep stremio subtitle loads untouched
This commit is contained in:
parent
dc11afc45f
commit
6a29dde857
5 changed files with 196 additions and 8 deletions
|
|
@ -194,7 +194,16 @@ final class DreamioWebViewController: UIViewController {
|
|||
window.fetch = async (...args) => {
|
||||
const response = await originalFetch(...args);
|
||||
try {
|
||||
response.clone().text().then(inspectSubtitlePayload).catch(() => {});
|
||||
const contentType = response.headers && response.headers.get("content-type") || "";
|
||||
const url = response.url || "";
|
||||
subtitleURLPattern.lastIndex = 0;
|
||||
const shouldInspect = !contentType
|
||||
|| /json|text|javascript|xml|subtitle|vtt|srt/i.test(contentType)
|
||||
|| subtitleURLPattern.test(url);
|
||||
if (shouldInspect) {
|
||||
subtitleURLPattern.lastIndex = 0;
|
||||
response.clone().text().then(inspectSubtitlePayload).catch(() => {});
|
||||
}
|
||||
} catch (_) {}
|
||||
return response;
|
||||
};
|
||||
|
|
@ -203,7 +212,15 @@ final class DreamioWebViewController: UIViewController {
|
|||
const originalXHRSend = XMLHttpRequest.prototype.send;
|
||||
XMLHttpRequest.prototype.send = function(...args) {
|
||||
try {
|
||||
this.addEventListener("load", () => inspectSubtitlePayload(this.responseText));
|
||||
this.addEventListener("load", () => {
|
||||
try {
|
||||
const responseType = this.responseType || "";
|
||||
if (responseType && responseType !== "text") {
|
||||
return;
|
||||
}
|
||||
inspectSubtitlePayload(this.responseText);
|
||||
} catch (_) {}
|
||||
});
|
||||
} catch (_) {}
|
||||
return originalXHRSend.apply(this, args);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue