Improve URL handling

This commit is contained in:
Arkadiusz Fal
2022-06-25 00:48:57 +02:00
parent 321c265a11
commit f3f8466a95
26 changed files with 616 additions and 216 deletions

View File

@@ -211,6 +211,10 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
resource(baseURL: account.url, path: basePathAppending("channels/\(id)"))
}
func channelByName(_: String) -> Resource? {
nil
}
func channelVideos(_ id: String) -> Resource {
resource(baseURL: account.url, path: basePathAppending("channels/\(id)/latest"))
}

View File

@@ -40,6 +40,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
self.extractChannel(from: content.json)
}
configureTransformer(pathPattern("c/*")) { (content: Entity<JSON>) -> Channel? in
self.extractChannel(from: content.json)
}
configureTransformer(pathPattern("playlists/*")) { (content: Entity<JSON>) -> ChannelPlaylist? in
self.extractChannelPlaylist(from: content.json)
}
@@ -125,6 +129,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
resource(baseURL: account.url, path: "channel/\(id)")
}
func channelByName(_ name: String) -> Resource? {
resource(baseURL: account.url, path: "c/\(name)")
}
func channelVideos(_ id: String) -> Resource {
channel(id)
}
@@ -362,14 +370,12 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
func extractChannelPlaylist(from json: JSON) -> ChannelPlaylist? {
let details = json.dictionaryValue
let id = details["url"]?.string?.components(separatedBy: "?list=").last ?? UUID().uuidString
let thumbnailURL = details["thumbnail"]?.url ?? details["thumbnailUrl"]?.url
var videos = [Video]()
if let relatedStreams = details["relatedStreams"] {
videos = extractVideos(from: relatedStreams)
}
return ChannelPlaylist(
id: id,
title: details["name"]?.string ?? "",
thumbnailURL: thumbnailURL,
channel: extractChannel(from: json),

View File

@@ -7,6 +7,7 @@ protocol VideosAPI {
var signedIn: Bool { get }
func channel(_ id: String) -> Resource
func channelByName(_ name: String) -> Resource?
func channelVideos(_ id: String) -> Resource
func trending(country: Country, category: TrendingCategory?) -> Resource
func search(_ query: SearchQuery, page: String?) -> Resource

View File

@@ -58,4 +58,8 @@ enum VideosApp: String, CaseIterable {
var searchUsesIndexedPages: Bool {
self == .invidious
}
var supportsOpeningChannelsByName: Bool {
self == .piped
}
}