Filter False OpenSubtitles Subtitle Candidates

Dreamio now stops treating OpenSubtitles addon artwork and base addon endpoints as native subtitle files, so VLC is no longer asked to resolve junk candidates before external subtitle tracks can appear.

Summary

The pasted runtime log showed two false external subtitle candidates: an opensubtitles-logo.png image and https://opensubtitles.strem.io/stremio/v1. Both were being buffered and resolved as if they were subtitles, then rejected downstream. This change tightens subtitle candidate detection at both the injected JavaScript bridge and Swift parser layers.

Changes Made

Context

VLC was correctly detecting and selecting the embedded MKV subtitle track. The failure was earlier: Dreamio’s bridge discovered two candidates, but neither was an actual external subtitle file. The native resolver then rejected both, leaving the UI with only embedded subtitles.

Important Implementation Details

The previous heuristic accepted any URL containing opensubtitles or subtitle. That was too broad because addon logos, metadata endpoints, and app API routes can contain those words. The new logic keeps permissive support for real subtitle files and known OpenSubtitles download flows while rejecting common media, image, script, and manifest-style assets.

Relevant Diff Snippets

Dreamio/DreamioWebViewController.swift

Dreamio/DreamioWebViewController.swift
-4+46
83 unmodified lines
84
85
86
87
88
89
35 unmodified lines
125
126
127
128
129
130
131
132
133
134
135
136
137
138
83 unmodified lines
const postedSubtitleURLs = new Set();
const subtitleURLPattern = /https?:\/\/[^\s"'<>]+(?:\.srt|\.vtt|\.ass|\.ssa|\.sub|opensubtitles|subtitle)[^\s"'<>]*/ig;
const subtitleSignalPattern = /subtitle|subtitles|opensubtitles|vtt|srt|ass|ssa/i;
const subtitleObjectKeys = [
"attributes",
"files",
35 unmodified lines
}
};
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 = () => {
83 unmodified lines
84
85
86
87
88
89
90
91
92
93
94
35 unmodified lines
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
83 unmodified lines
const postedSubtitleURLs = new Set();
const subtitleURLPattern = /https?:\/\/[^\s"'<>]+(?:\.srt|\.vtt|\.ass|\.ssa|\.sub|opensubtitles|subtitle)[^\s"'<>]*/ig;
const subtitleSignalPattern = /subtitle|subtitles|opensubtitles|vtt|srt|ass|ssa/i;
const subtitleExtensions = new Set(["srt", "vtt", "ass", "ssa", "sub"]);
const nonSubtitleExtensions = new Set([
"aac", "avi", "bmp", "css", "gif", "heic", "ico", "jpeg", "jpg", "js", "json",
"m4a", "m4v", "mkv", "mov", "mp3", "mp4", "mpeg", "mpg", "png", "svg", "ts", "webm", "webp"
]);
const subtitleObjectKeys = [
"attributes",
"files",
35 unmodified lines
}
};
const isDirectSubtitleFileURL = (url) => {
try {
const parsed = new URL(url, window.location.href);
const extension = parsed.pathname.split(".").pop().toLowerCase();
return subtitleExtensions.has(extension)
|| Array.from(subtitleExtensions).some((ext) => parsed.href.toLowerCase().includes(`.${ext}?`) || parsed.href.toLowerCase().includes(`.${ext}&`));
} catch (_) {
return false;
}
};
const isProbablyNonSubtitleAssetURL = (url) => {
try {
const extension = new URL(url, window.location.href).pathname.split(".").pop().toLowerCase();
return nonSubtitleExtensions.has(extension);
} catch (_) {
return false;
}
};
const isOpenSubtitlesDownloadURL = (url) => {
try {
const parsed = new URL(url, window.location.href);
const host = parsed.hostname.toLowerCase();
const path = parsed.pathname.toLowerCase();
if (!host.includes("opensubtitles")) {
return false;
}
if (/\/manifest\.json(?:_\d+)?$/i.test(path)) {
return false;
}
return /\/api\/v1\/download(?:\/|$)/i.test(path)
|| /\/download(?:\/|$)/i.test(path)
|| /\/subtitles?(?:\/|$)/i.test(path);
} catch (_) {
return false;
}
};
const isSubtitleURL = (url) => {
if (!url || isOpenSubtitlesManifestID(url)) {
return false;
}
return !isProbablyNonSubtitleAssetURL(url)
&& (isDirectSubtitleFileURL(url) || isOpenSubtitlesDownloadURL(url));
};
const findResolverURL = () => {

Dreamio/StreamCandidate.swift

Dreamio/StreamCandidate.swift
-5+28
131 unmodified lines
132
133
134
135
136
137
106 unmodified lines
244
245
246
247
248
249
250
251
252
253
254
255
256
257
1 unmodified line
259
260
261
262
263
264
131 unmodified lines
enum SubtitleCandidateParser {
private static let supportedExtensions = ["srt", "vtt", "ass", "ssa", "sub"]
private static let urlFields = ["url", "href", "src", "link", "subtitles", "subtitle", "subtitleUrl", "subtitleURL", "file", "download", "fileUrl", "fileURL"]
private static let labelFields = ["label", "name", "title", "file_name", "filename", "lang", "language", "id"]
private struct CandidateContext {
106 unmodified lines
return nil
}
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")
|| lowercased.contains("opensubtitles")
else {
return nil
}
1 unmodified line
return url
}
private static func isOpenSubtitlesManifestIdentifier(_ url: URL) -> Bool {
guard url.host?.localizedCaseInsensitiveContains("opensubtitles") == true else {
return false
131 unmodified lines
132
133
134
135
136
137
138
139
140
141
106 unmodified lines
248
249
250
251
252
253
254
255
256
257
258
259
260
261
1 unmodified line
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
131 unmodified lines
enum SubtitleCandidateParser {
private static let supportedExtensions = ["srt", "vtt", "ass", "ssa", "sub"]
private static let nonSubtitleExtensions = [
"aac", "avi", "bmp", "css", "gif", "heic", "ico", "jpeg", "jpg", "js", "json",
"m4a", "m4v", "mkv", "mov", "mp3", "mp4", "mpeg", "mpg", "png", "svg", "ts", "webm", "webp"
]
private static let urlFields = ["url", "href", "src", "link", "subtitles", "subtitle", "subtitleUrl", "subtitleURL", "file", "download", "fileUrl", "fileURL"]
private static let labelFields = ["label", "name", "title", "file_name", "filename", "lang", "language", "id"]
private struct CandidateContext {
106 unmodified lines
return nil
}
if isOpenSubtitlesManifestIdentifier(url) {
return nil
}
guard !nonSubtitleExtensions.contains(url.pathExtension.lowercased()) else {
return nil
}
guard isDirectSubtitleFile(url)
|| isOpenSubtitlesDownloadURL(url)
else {
return nil
}
1 unmodified line
return url
}
private static func isDirectSubtitleFile(_ url: URL) -> Bool {
let lowercased = url.absoluteString.lowercased()
return supportedExtensions.contains(url.pathExtension.lowercased())
|| supportedExtensions.contains(where: { lowercased.contains(".\($0)?") || lowercased.contains(".\($0)&") })
}
private static func isOpenSubtitlesDownloadURL(_ url: URL) -> Bool {
guard url.host?.localizedCaseInsensitiveContains("opensubtitles") == true else {
return false
}
let path = url.path.lowercased()
guard !isOpenSubtitlesManifestIdentifier(url) else {
return false
}
return path.range(of: #"(^|/)api/v1/download(/|$)"#, options: .regularExpression) != nil
|| path.range(of: #"(^|/)download(/|$)"#, options: .regularExpression) != nil
|| path.range(of: #"(^|/)subtitles?(/|$)"#, options: .regularExpression) != nil
}
private static func isOpenSubtitlesManifestIdentifier(_ url: URL) -> Bool {
guard url.host?.localizedCaseInsensitiveContains("opensubtitles") == true else {
return false

Tests/StreamResolverTests.swift

Tests/StreamResolverTests.swift
+27
11 unmodified lines
12
13
14
15
16
17
195 unmodified lines
213
214
215
216
217
218
11 unmodified lines
testOpenSubtitlesV3CandidateParsing()
testOpenSubtitlesNestedAttributesFilesParsing()
testOpenSubtitlesManifestIDsAreNotResolvedAsSubtitles()
testOpenSubtitlesV3DownloadResponseResolution()
testOpenSubtitlesNestedDownloadResponseResolution()
await testSubtitleResolverDownloadJSONReturningLink()
195 unmodified lines
assertEqual(candidates[0].language, "eng")
}
private static func testOpenSubtitlesV3DownloadResponseResolution() {
let payload = """
{
11 unmodified lines
12
13
14
15
16
17
18
195 unmodified lines
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
11 unmodified lines
testOpenSubtitlesV3CandidateParsing()
testOpenSubtitlesNestedAttributesFilesParsing()
testOpenSubtitlesManifestIDsAreNotResolvedAsSubtitles()
testOpenSubtitlesArtworkAndAddonEndpointsAreIgnored()
testOpenSubtitlesV3DownloadResponseResolution()
testOpenSubtitlesNestedDownloadResponseResolution()
await testSubtitleResolverDownloadJSONReturningLink()
195 unmodified lines
assertEqual(candidates[0].language, "eng")
}
private static func testOpenSubtitlesArtworkAndAddonEndpointsAreIgnored() {
let payload: [String: Any] = [
"subtitles": [
[
"label": "External Subtitle",
"url": "http://www.strem.io/images/addons/opensubtitles-logo.png"
],
[
"label": "External Subtitle",
"url": "https://opensubtitles.strem.io/stremio/v1"
],
[
"label": "English",
"url": "https://opensubtitles.example.test/subtitles/movie.en.srt"
]
],
"body": "metadata https://www.strem.io/images/addons/opensubtitles-logo.png"
]
let candidates = SubtitleCandidateParser.candidates(in: payload)
assertEqual(candidates.count, 1)
assertEqual(candidates[0].url.absoluteString, "https://opensubtitles.example.test/subtitles/movie.en.srt")
assertEqual(candidates[0].label, "English")
}
private static func testOpenSubtitlesV3DownloadResponseResolution() {
let payload = """
{

Expected Impact for End-Users

External subtitle discovery should stop burning time on addon images and base endpoints. In the exact logged scenario, Dreamio should no longer buffer the PNG or /stremio/v1 endpoint as external subtitles. Real OpenSubtitles download candidates remain eligible for resolution and attachment.

Validation

Issues, Limitations, and Mitigations

This fix removes the false positives visible in the log, but it may not by itself surface the actual OpenSubtitles external file if Stremio is hiding it behind a different internal payload shape. The mitigation is that future logs should now be cleaner: if external subtitles are still missing, the remaining bridge messages should point at the real undiscovered payload instead of the addon logo noise.

Follow-up Work

No new Beads follow-up was filed. The next useful manual check is to replay the same OpenSubtitlesV3 stream and confirm the bridge no longer logs candidates with ext=png or ext=none for the addon base endpoint.