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

@@ -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),