mirror of
https://github.com/dirtydishes/dreamio.git
synced 2026-06-06 21:38:15 +00:00
accept plain stremio subtitle text
This commit is contained in:
parent
128b9518a5
commit
9693f65f45
3 changed files with 234 additions and 7 deletions
|
|
@ -17,6 +17,7 @@ struct StreamResolverTests {
|
|||
testOpenSubtitlesV3DownloadResponseResolution()
|
||||
testOpenSubtitlesNestedDownloadResponseResolution()
|
||||
await testSubtitleResolverCachesStremioDownloadBody()
|
||||
await testSubtitleResolverCachesPlainStremioDownloadBody()
|
||||
await testSubtitleResolverDownloadJSONReturningLink()
|
||||
await testSubtitleResolverRedirectToDirectSubtitle()
|
||||
await testSubtitleResolverRejectsNonSubtitleAPIResponse()
|
||||
|
|
@ -476,6 +477,41 @@ struct StreamResolverTests {
|
|||
assertEqual(cachedBody, subtitleBody)
|
||||
}
|
||||
|
||||
private static func testSubtitleResolverCachesPlainStremioDownloadBody() async {
|
||||
let sourceURL = "https://subs5.strem.io/en/download/subencoding-stremio-utf8/src-api/file/1952341942"
|
||||
let subtitleBody = """
|
||||
00:01.000 --> 00:02.000
|
||||
Plain cue text without an index
|
||||
|
||||
"""
|
||||
MockURLProtocol.handler = nil
|
||||
MockURLProtocol.handlers = [
|
||||
sourceURL: (
|
||||
200,
|
||||
URL(string: sourceURL)!,
|
||||
subtitleBody.data(using: .utf8)!
|
||||
)
|
||||
]
|
||||
|
||||
let cacheDirectory = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("DreamioSubtitleResolverTests-\(UUID().uuidString)", isDirectory: true)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: cacheDirectory)
|
||||
}
|
||||
|
||||
let resolver = SubtitleResolver(session: mockSession(), cacheDirectory: cacheDirectory)
|
||||
let candidate = await resolver.resolve(SubtitleCandidate(
|
||||
url: URL(string: sourceURL)!,
|
||||
label: "English",
|
||||
language: "eng"
|
||||
))
|
||||
|
||||
assertEqual(candidate?.url.isFileURL, true)
|
||||
assertEqual(candidate?.url.pathExtension, "srt")
|
||||
let cachedBody = try? String(contentsOf: candidate!.url, encoding: .utf8)
|
||||
assertEqual(cachedBody, subtitleBody)
|
||||
}
|
||||
|
||||
private static func testSubtitleResolverDownloadJSONReturningLink() async {
|
||||
MockURLProtocol.handler = nil
|
||||
MockURLProtocol.handlers = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue