From 2086c6f67946203487e32581c3499623822ce1e4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 13 Aug 2022 16:16:02 +0200 Subject: [PATCH] Fix parsing video links Fix alert on macOS --- Shared Tests/URLParserTests.swift | 1 + Shared/OpenURLHandler.swift | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Shared Tests/URLParserTests.swift b/Shared Tests/URLParserTests.swift index d2902205..a4ed4da0 100644 --- a/Shared Tests/URLParserTests.swift +++ b/Shared Tests/URLParserTests.swift @@ -4,6 +4,7 @@ final class URLParserTests: XCTestCase { private static let videos: [String: String] = [ "https://www.youtube.com/watch?v=_E0PWQvW-14&list=WL&index=4&t=155s": "_E0PWQvW-14", "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://invidious.snopyta.org/watch?v=XpowfENlJAw": "XpowfENlJAw", "/watch?v=VQ_f5RymW70": "VQ_f5RymW70", diff --git a/Shared/OpenURLHandler.swift b/Shared/OpenURLHandler.swift index 13750fc6..4dbf6429 100644 --- a/Shared/OpenURLHandler.swift +++ b/Shared/OpenURLHandler.swift @@ -27,7 +27,7 @@ struct OpenURLHandler { } #endif - let parser = URLParser(url: urlByRemovingYatteeProtocol(url)) + let parser = URLParser(url: urlByReplacingYatteeProtocol(url)) switch parser.destination { case .video: @@ -66,6 +66,10 @@ struct OpenURLHandler { #endif default: 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 } - private func urlByRemovingYatteeProtocol(_ url: URL) -> URL! { + private func urlByReplacingYatteeProtocol(_ url: URL, with urlProtocol: String = "https") -> URL! { var urlAbsoluteString = url.absoluteString guard urlAbsoluteString.hasPrefix(Self.yatteeProtocol) else { @@ -84,7 +88,7 @@ struct OpenURLHandler { urlAbsoluteString = String(urlAbsoluteString.dropFirst(Self.yatteeProtocol.count)) - return URL(string: urlAbsoluteString) + return URL(string: "\(urlProtocol)://\(urlAbsoluteString)") } private func handleVideoUrlOpen(_ parser: URLParser) {