fix opensubtitles manifest subtitle urls

This commit is contained in:
dirtydishes 2026-05-25 12:18:45 -04:00
parent 07741bae96
commit 6008272d0a
6 changed files with 275 additions and 5 deletions

View file

@ -115,6 +115,26 @@ final class DreamioWebViewController: UIViewController {
}
};
const isOpenSubtitlesManifestID = (url) => {
try {
const parsed = new URL(url, window.location.href);
return /opensubtitles/i.test(parsed.hostname)
&& /\/manifest\.json(?:_\d+)?$/i.test(parsed.pathname);
} catch (_) {
return false;
}
};
const isSubtitleURL = (url) => {
if (!url || isOpenSubtitlesManifestID(url)) {
return false;
}
subtitleURLPattern.lastIndex = 0;
const matches = subtitleURLPattern.test(url) || /api\.opensubtitles\.com\/api\/v1\/download/i.test(url);
subtitleURLPattern.lastIndex = 0;
return matches;
};
const findResolverURL = () => {
const links = Array.from(document.querySelectorAll("a[href], [data-href], [data-url]"));
const match = links
@ -200,15 +220,12 @@ final class DreamioWebViewController: UIViewController {
entry.fileURL
);
let url = absoluteURL(rawURL);
if (!url && entry && entry.file_id) {
if ((!url || isOpenSubtitlesManifestID(url)) && entry && entry.file_id) {
url = `https://api.opensubtitles.com/api/v1/download/${encodeURIComponent(String(entry.file_id))}`;
}
subtitleURLPattern.lastIndex = 0;
if (!url || (!subtitleURLPattern.test(url) && !/api\.opensubtitles\.com\/api\/v1\/download/i.test(url))) {
subtitleURLPattern.lastIndex = 0;
if (!isSubtitleURL(url)) {
return;
}
subtitleURLPattern.lastIndex = 0;
if (subtitleCandidates.some((candidate) => candidate.url === url)) {
return;
}

View file

@ -245,6 +245,9 @@ enum SubtitleCandidateParser {
}
let lowercased = url.absoluteString.lowercased()
if isOpenSubtitlesManifestIdentifier(url) {
return nil
}
guard supportedExtensions.contains(url.pathExtension.lowercased())
|| supportedExtensions.contains(where: { lowercased.contains(".\($0)?") || lowercased.contains(".\($0)&") })
|| lowercased.contains("subtitle")
@ -256,6 +259,14 @@ enum SubtitleCandidateParser {
return url
}
private static func isOpenSubtitlesManifestIdentifier(_ url: URL) -> Bool {
guard url.host?.localizedCaseInsensitiveContains("opensubtitles") == true else {
return false
}
let path = url.path.lowercased()
return path == "/manifest.json" || path.range(of: #"/manifest\.json_\d+$"#, options: .regularExpression) != nil
}
private static func openSubtitlesDownloadURL(from value: Any?) -> URL? {
let id: String?
if let string = value as? String, !string.isEmpty {