diff --git a/Shared/Player/Video Details/VideoDescription.swift b/Shared/Player/Video Details/VideoDescription.swift index 6d6bff25..c098517a 100644 --- a/Shared/Player/Video Details/VideoDescription.swift +++ b/Shared/Player/Video Details/VideoDescription.swift @@ -133,7 +133,7 @@ struct VideoDescription: View { if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) { components.scheme = "yattee" if let yatteeURL = components.url { - let parser = URLParser(url: urlToOpen) + let parser = URLParser(url: urlToOpen, allowFileURLs: false) let destination = parser.destination if destination == .video, parser.videoID == player.currentVideo?.videoID, diff --git a/Shared/URLParser.swift b/Shared/URLParser.swift index 8e790a14..8180ef4a 100644 --- a/Shared/URLParser.swift +++ b/Shared/URLParser.swift @@ -15,13 +15,17 @@ struct URLParser { } var url: URL + var allowFileURLs = true - init(url: URL) { + init(url: URL, allowFileURLs: Bool = true) { self.url = url + self.allowFileURLs = allowFileURLs let urlString = url.absoluteString let scheme = urlComponents?.scheme if scheme == nil, - urlString.contains("youtube.com"), + urlString.contains("youtube.com") || + urlString.contains("youtu.be") || + urlString.contains("youtube-nocookie.com"), let url = URL(string: "https://\(urlString)" ) { @@ -48,7 +52,7 @@ struct URLParser { return .channel } - return .fileURL + return allowFileURLs ? .fileURL : nil } return .video @@ -56,8 +60,22 @@ struct URLParser { var isYoutubeHost: Bool { guard let urlComponents else { return false } + let hostComponents = (urlComponents.host ?? "").components(separatedBy: ".").prefix(2) - return urlComponents.host == "youtube.com" || urlComponents.host == "www.youtube.com" + if hostComponents.contains("youtube") || hostComponents.contains("youtube-nocookie") { + return true + } + + let host = hostComponents.joined(separator: ".") + .replacingFirstOccurrence(of: "www.", with: "") + + return host == "youtu.be" + } + + var isYoutube: Bool { + guard let urlComponents else { return false } + + return urlComponents.host == "youtube.com" || urlComponents.host == "www.youtube.com" || urlComponents.host == "youtu.be" } var isShortsPath: Bool { @@ -65,7 +83,7 @@ struct URLParser { } var fileURL: URL? { - guard destination == .fileURL else { return nil } + guard allowFileURLs, destination == .fileURL else { return nil } return url }