mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Add share extension, rework bookmarks model
This commit is contained in:
@@ -27,14 +27,15 @@ struct OpenURLHandler {
|
||||
}
|
||||
#endif
|
||||
|
||||
if url.isFileURL {
|
||||
OpenVideosModel.shared.open(url)
|
||||
guard var url = urlByReplacingYatteeProtocol(url) else {
|
||||
return
|
||||
}
|
||||
|
||||
let parser = URLParser(url: urlByReplacingYatteeProtocol(url))
|
||||
let parser = URLParser(url: url)
|
||||
|
||||
switch parser.destination {
|
||||
case .fileURL:
|
||||
handleFileURLOpen(parser)
|
||||
case .video:
|
||||
handleVideoUrlOpen(parser)
|
||||
case .playlist:
|
||||
@@ -93,16 +94,29 @@ struct OpenURLHandler {
|
||||
}
|
||||
|
||||
urlAbsoluteString = String(urlAbsoluteString.dropFirst(Self.yatteeProtocol.count))
|
||||
if url.absoluteString.contains("://") {
|
||||
return URL(string: urlAbsoluteString)
|
||||
}
|
||||
|
||||
return URL(string: "\(urlProtocol)://\(urlAbsoluteString)")
|
||||
}
|
||||
|
||||
private func handleFileURLOpen(_ parser: URLParser) {
|
||||
guard let url = parser.fileURL else { return }
|
||||
|
||||
OpenVideosModel.shared.openURLs([url], removeQueueItems: false, playbackMode: .playNow)
|
||||
}
|
||||
|
||||
private func handleVideoUrlOpen(_ parser: URLParser) {
|
||||
guard let id = parser.videoID, id != player.currentVideo?.id else {
|
||||
guard let id = parser.videoID else {
|
||||
navigation.presentAlert(title: "Could not open video", message: "Could not extract video ID")
|
||||
return
|
||||
}
|
||||
|
||||
guard id != player.currentVideo?.id else {
|
||||
return
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
Windows.main.open()
|
||||
#endif
|
||||
|
@@ -10,7 +10,7 @@ struct URLParser {
|
||||
]
|
||||
|
||||
enum Destination {
|
||||
case video, playlist, channel, search
|
||||
case fileURL, video, playlist, channel, search
|
||||
case favorites, subscriptions, popular, trending
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ struct URLParser {
|
||||
return .channel
|
||||
}
|
||||
|
||||
return nil
|
||||
return .fileURL
|
||||
}
|
||||
|
||||
return .video
|
||||
@@ -64,6 +64,11 @@ struct URLParser {
|
||||
path.hasPrefix(Self.shortsPrefix)
|
||||
}
|
||||
|
||||
var fileURL: URL? {
|
||||
guard destination == .fileURL else { return nil }
|
||||
return url
|
||||
}
|
||||
|
||||
var videoID: String? {
|
||||
if host == "youtu.be", !path.isEmpty {
|
||||
return String(path.suffix(from: path.index(path.startIndex, offsetBy: 1)))
|
||||
|
Reference in New Issue
Block a user