Fix Invidious channel videos

This commit is contained in:
Arkadiusz Fal 2023-01-27 21:02:02 +01:00
parent 2b238c9b7b
commit cfd85a018e
2 changed files with 10 additions and 3 deletions

View File

@ -114,7 +114,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
}
configureTransformer(pathPattern("channels/*/latest"), requestMethods: [.get]) { (content: Entity<JSON>) -> [Video] in
content.json.arrayValue.map(self.extractVideo)
content.json.dictionaryValue["videos"]?.arrayValue.map(self.extractVideo) ?? []
}
configureTransformer(pathPattern("channels/*/playlists"), requestMethods: [.get]) { (content: Entity<JSON>) -> [ContentItem] in

View File

@ -72,14 +72,21 @@ struct FavoriteItemView: View {
}
}
case let .channel(_, id, name):
let channel = Channel(app: .invidious, id: id, name: name)
if let cache = ChannelsCacheModel.shared.retrieve(channel.cacheKey) {
var channel = Channel(app: .invidious, id: id, name: name)
if let cache = ChannelsCacheModel.shared.retrieve(channel.cacheKey),
!cache.videos.isEmpty
{
contentItems = ContentItem.array(of: cache.videos)
}
onSuccess = { response in
if let channel: Channel = response.typedContent() {
ChannelsCacheModel.shared.store(channel)
store.contentItems = ContentItem.array(of: channel.videos)
} else if let videos: [Video] = response.typedContent() {
channel.videos = videos
ChannelsCacheModel.shared.store(channel)
store.contentItems = ContentItem.array(of: videos)
}
}
case let .channelPlaylist(_, id, title):