1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/Model/Applications/VideosAPI.swift

75 lines
2.2 KiB
Swift
Raw Normal View History

2021-10-21 03:51:50 +05:30
import Foundation
import Siesta
protocol VideosAPI {
2021-10-27 04:29:59 +05:30
var account: Account! { get }
2021-10-21 03:51:50 +05:30
var signedIn: Bool { get }
func channel(_ id: String) -> Resource
2021-11-02 03:26:18 +05:30
func channelVideos(_ id: String) -> Resource
2021-10-21 03:51:50 +05:30
func trending(country: Country, category: TrendingCategory?) -> Resource
func search(_ query: SearchQuery) -> Resource
func searchSuggestions(query: String) -> Resource
func video(_ id: Video.ID) -> Resource
var subscriptions: Resource? { get }
var feed: Resource? { get }
var home: Resource? { get }
var popular: Resource? { get }
var playlists: Resource? { get }
func channelSubscription(_ id: String) -> Resource?
2021-11-02 03:26:18 +05:30
func playlist(_ id: String) -> Resource?
2021-10-21 03:51:50 +05:30
func playlistVideo(_ playlistID: String, _ videoID: String) -> Resource?
func playlistVideos(_ id: String) -> Resource?
2021-10-23 04:34:03 +05:30
func channelPlaylist(_ id: String) -> Resource?
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void)
2021-10-28 22:44:55 +05:30
func shareURL(_ item: ContentItem) -> URL?
}
extension VideosAPI {
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void = { _ in }) {
guard (item.video?.streams ?? []).isEmpty else {
completionHandler(item)
return
}
video(item.videoID).load().onSuccess { response in
guard let video: Video = response.typedContent() else {
return
}
var newItem = item
newItem.video = video
completionHandler(newItem)
}
}
2021-10-27 04:29:59 +05:30
2021-10-28 22:44:55 +05:30
func shareURL(_ item: ContentItem) -> URL? {
guard let frontendHost = account.instance.frontendHost else {
return nil
}
2021-10-27 04:29:59 +05:30
var urlComponents = account.instance.urlComponents
2021-10-28 22:44:55 +05:30
urlComponents.host = frontendHost
2021-10-28 02:41:38 +05:30
2021-10-27 04:29:59 +05:30
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!
}
2021-10-21 03:51:50 +05:30
}