mirror of
https://github.com/cranci1/Sora.git
synced 2026-01-11 20:10:24 +00:00
updated the subfetching stuff
This commit is contained in:
parent
8d6d2acc7e
commit
2bb4234712
1 changed files with 4 additions and 15 deletions
|
|
@ -13,7 +13,7 @@ struct SubtitleCue: Identifiable {
|
|||
let endTime: Double
|
||||
let text: String
|
||||
let lines: [String]
|
||||
|
||||
|
||||
init(startTime: Double, endTime: Double, text: String) {
|
||||
self.startTime = startTime
|
||||
self.endTime = endTime
|
||||
|
|
@ -46,7 +46,8 @@ class VTTSubtitlesLoader: ObservableObject {
|
|||
return
|
||||
}
|
||||
|
||||
let detectedFormat = self.determineSubtitleFormat(from: url)
|
||||
let trimmed = subtitleContent.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let detectedFormat: SubtitleFormat = trimmed.contains("WEBVTT") ? .vtt : .srt
|
||||
|
||||
DispatchQueue.main.async {
|
||||
switch detectedFormat {
|
||||
|
|
@ -55,7 +56,7 @@ class VTTSubtitlesLoader: ObservableObject {
|
|||
case .srt:
|
||||
self.cues = self.parseSRT(content: subtitleContent)
|
||||
case .unknown:
|
||||
if subtitleContent.trimmingCharacters(in: .whitespacesAndNewlines).hasPrefix("WEBVTT") {
|
||||
if trimmed.contains("WEBVTT") {
|
||||
self.cues = self.parseVTT(content: subtitleContent)
|
||||
} else {
|
||||
self.cues = self.parseSRT(content: subtitleContent)
|
||||
|
|
@ -65,18 +66,6 @@ class VTTSubtitlesLoader: ObservableObject {
|
|||
}.resume()
|
||||
}
|
||||
|
||||
private func determineSubtitleFormat(from url: URL) -> SubtitleFormat {
|
||||
let fileExtension = url.pathExtension.lowercased()
|
||||
switch fileExtension {
|
||||
case "vtt", "webvtt":
|
||||
return .vtt
|
||||
case "srt":
|
||||
return .srt
|
||||
default:
|
||||
return .unknown
|
||||
}
|
||||
}
|
||||
|
||||
private func parseVTT(content: String) -> [SubtitleCue] {
|
||||
let contentLines = content.components(separatedBy: .newlines)
|
||||
var subtitleCues: [SubtitleCue] = []
|
||||
|
|
|
|||
Loading…
Reference in a new issue