-
Notifications
You must be signed in to change notification settings - Fork 178
Closed
Description
What do you think of providing a method of extracting time(s) from a Locator
There is a private extension on Locator which kind of does this, but looks like it only matches start time (my understanding is that end time can be specified).
swift-toolkit/Sources/Navigator/Audiobook/AudioNavigator.swift
Lines 389 to 409 in a62962b
| private extension Locator { | |
| private static let timeFragmentRegex = try! NSRegularExpression(pattern: #"t=(\d+(?:\.\d+)?)"#) | |
| // FIXME: Should probably be in `Locator` itself. | |
| func time(forDuration duration: Double? = nil) -> Double? { | |
| if let progression = locations.progression, let duration = duration { | |
| return progression * duration | |
| } else { | |
| for fragment in locations.fragments { | |
| let range = NSRange(fragment.startIndex ..< fragment.endIndex, in: fragment) | |
| if let match = Self.timeFragmentRegex.firstMatch(in: fragment, range: range) { | |
| let matchRange = match.range(at: 1) | |
| if matchRange.location != NSNotFound, let range = Range(matchRange, in: fragment) { | |
| return Double(fragment[range]) | |
| } | |
| } | |
| } | |
| } | |
| return nil | |
| } | |
| } |
Would you be open to a Locator.time property/function (() -> (Double?, Double?)?). I'd be open to providing a PR for this if you want.
Metadata
Metadata
Assignees
Labels
No labels