mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Share button
This commit is contained in:
@@ -74,6 +74,15 @@ struct Instance: Defaults.Serializable, Hashable, Identifiable {
|
||||
Account(instanceID: id, name: "Anonymous", url: url, anonymous: true)
|
||||
}
|
||||
|
||||
var urlComponents: URLComponents {
|
||||
URLComponents(string: url)!
|
||||
}
|
||||
|
||||
var frontendHost: String {
|
||||
// TODO: piped frontend link
|
||||
urlComponents.host!.replacingOccurrences(of: "api", with: "")
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(url)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ import Foundation
|
||||
import Siesta
|
||||
|
||||
protocol VideosAPI {
|
||||
var account: Account! { get }
|
||||
var signedIn: Bool { get }
|
||||
|
||||
func channel(_ id: String) -> Resource
|
||||
@@ -25,6 +26,7 @@ protocol VideosAPI {
|
||||
func channelPlaylist(_ id: String) -> Resource?
|
||||
|
||||
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void)
|
||||
func shareURL(_ item: ContentItem) -> URL
|
||||
}
|
||||
|
||||
extension VideosAPI {
|
||||
@@ -45,4 +47,21 @@ extension VideosAPI {
|
||||
completionHandler(newItem)
|
||||
}
|
||||
}
|
||||
|
||||
func shareURL(_ item: ContentItem) -> URL {
|
||||
var urlComponents = account.instance.urlComponents
|
||||
urlComponents.host = account.instance.frontendHost
|
||||
switch item.contentType {
|
||||
case .video:
|
||||
urlComponents.path = "/watch"
|
||||
urlComponents.query = "v=\(item.video.videoID)"
|
||||
case .channel:
|
||||
urlComponents.path = "/channel/\(item.channel.id)"
|
||||
case .playlist:
|
||||
urlComponents.path = "/playlist"
|
||||
urlComponents.query = "list=\(item.playlist.id)"
|
||||
}
|
||||
|
||||
return urlComponents.url!
|
||||
}
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
@discardableResult func remove(_ item: PlayerQueueItem) -> PlayerQueueItem? {
|
||||
if let index = queue.firstIndex(where: { $0 == item }) {
|
||||
if let index = queue.firstIndex(where: { $0.videoID == item.videoID }) {
|
||||
return queue.remove(at: index)
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
func addItemToHistory(_ item: PlayerQueueItem) {
|
||||
if let index = history.firstIndex(where: { $0.video.videoID == item.video?.videoID }) {
|
||||
if let index = history.firstIndex(where: { $0.video?.videoID == item.video?.videoID }) {
|
||||
history.remove(at: index)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user