1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30

Fix parsing video links

Fix alert on macOS
This commit is contained in:
Arkadiusz Fal 2022-08-13 16:16:02 +02:00
parent 2c81808125
commit 2086c6f679
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ final class URLParserTests: XCTestCase {
private static let videos: [String: String] = [ private static let videos: [String: String] = [
"https://www.youtube.com/watch?v=_E0PWQvW-14&list=WL&index=4&t=155s": "_E0PWQvW-14", "https://www.youtube.com/watch?v=_E0PWQvW-14&list=WL&index=4&t=155s": "_E0PWQvW-14",
"https://youtu.be/IRsc57nK8mg?t=20": "IRsc57nK8mg", "https://youtu.be/IRsc57nK8mg?t=20": "IRsc57nK8mg",
"yattee://youtu.be/oCtYBqcN7QE": "oCtYBqcN7QE",
"https://www.youtube-nocookie.com/watch?index=4&v=cE1PSQrWc11&list=WL&t=155s": "cE1PSQrWc11", "https://www.youtube-nocookie.com/watch?index=4&v=cE1PSQrWc11&list=WL&t=155s": "cE1PSQrWc11",
"https://invidious.snopyta.org/watch?v=XpowfENlJAw": "XpowfENlJAw", "https://invidious.snopyta.org/watch?v=XpowfENlJAw": "XpowfENlJAw",
"/watch?v=VQ_f5RymW70": "VQ_f5RymW70", "/watch?v=VQ_f5RymW70": "VQ_f5RymW70",

View File

@ -27,7 +27,7 @@ struct OpenURLHandler {
} }
#endif #endif
let parser = URLParser(url: urlByRemovingYatteeProtocol(url)) let parser = URLParser(url: urlByReplacingYatteeProtocol(url))
switch parser.destination { switch parser.destination {
case .video: case .video:
@ -66,6 +66,10 @@ struct OpenURLHandler {
#endif #endif
default: default:
navigation.presentAlert(title: "Error", message: "This URL could not be opened") navigation.presentAlert(title: "Error", message: "This URL could not be opened")
#if os(macOS)
guard !Windows.main.isOpen else { return }
navigation.presentingAlertInVideoPlayer = true
#endif
} }
} }
@ -75,7 +79,7 @@ struct OpenURLHandler {
navigation.presentingPlaylist = false navigation.presentingPlaylist = false
} }
private func urlByRemovingYatteeProtocol(_ url: URL) -> URL! { private func urlByReplacingYatteeProtocol(_ url: URL, with urlProtocol: String = "https") -> URL! {
var urlAbsoluteString = url.absoluteString var urlAbsoluteString = url.absoluteString
guard urlAbsoluteString.hasPrefix(Self.yatteeProtocol) else { guard urlAbsoluteString.hasPrefix(Self.yatteeProtocol) else {
@ -84,7 +88,7 @@ struct OpenURLHandler {
urlAbsoluteString = String(urlAbsoluteString.dropFirst(Self.yatteeProtocol.count)) urlAbsoluteString = String(urlAbsoluteString.dropFirst(Self.yatteeProtocol.count))
return URL(string: urlAbsoluteString) return URL(string: "\(urlProtocol)://\(urlAbsoluteString)")
} }
private func handleVideoUrlOpen(_ parser: URLParser) { private func handleVideoUrlOpen(_ parser: URLParser) {