mirror of
https://github.com/yattee/yattee.git
synced 2025-04-26 00:26:33 +00:00
Add support for Invidious Saved Playlists (fix #259)
This commit is contained in:
parent
a51de0d084
commit
59632e8330
@ -39,6 +39,10 @@ enum VideosApp: String, CaseIterable {
|
|||||||
self == .invidious
|
self == .invidious
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userPlaylistsUseChannelPlaylistEndpoint: Bool {
|
||||||
|
self == .piped
|
||||||
|
}
|
||||||
|
|
||||||
var userPlaylistsHaveVisibility: Bool {
|
var userPlaylistsHaveVisibility: Bool {
|
||||||
self == .invidious
|
self == .invidious
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ struct AppSidebarPlaylists: View {
|
|||||||
@ViewBuilder func playlistLabel(_ playlist: Playlist) -> some View {
|
@ViewBuilder func playlistLabel(_ playlist: Playlist) -> some View {
|
||||||
let label = Label(playlist.title, systemImage: RecentsModel.symbolSystemImage(playlist.title))
|
let label = Label(playlist.title, systemImage: RecentsModel.symbolSystemImage(playlist.title))
|
||||||
|
|
||||||
if player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
if player.accounts.app.userPlaylistsEndpointIncludesVideos, !playlist.videos.isEmpty {
|
||||||
label
|
label
|
||||||
.backport
|
.backport
|
||||||
.badge(Text("\(playlist.videos.count)"))
|
.badge(Text("\(playlist.videos.count)"))
|
||||||
|
@ -11,7 +11,8 @@ struct PlaylistsView: View {
|
|||||||
@State private var showingEditPlaylist = false
|
@State private var showingEditPlaylist = false
|
||||||
@State private var editedPlaylist: Playlist?
|
@State private var editedPlaylist: Playlist?
|
||||||
|
|
||||||
@StateObject private var store = Store<ChannelPlaylist>()
|
@StateObject private var channelPlaylist = Store<ChannelPlaylist>()
|
||||||
|
@StateObject private var userPlaylist = Store<Playlist>()
|
||||||
|
|
||||||
@EnvironmentObject<AccountsModel> private var accounts
|
@EnvironmentObject<AccountsModel> private var accounts
|
||||||
@EnvironmentObject<PlayerModel> private var player
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
@ -23,7 +24,8 @@ struct PlaylistsView: View {
|
|||||||
var videos = currentPlaylist?.videos ?? []
|
var videos = currentPlaylist?.videos ?? []
|
||||||
|
|
||||||
if videos.isEmpty {
|
if videos.isEmpty {
|
||||||
videos = store.item?.videos ?? []
|
videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? []
|
||||||
|
|
||||||
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
@ -40,14 +42,15 @@ struct PlaylistsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var resource: Resource? {
|
private var resource: Resource? {
|
||||||
guard !player.accounts.app.userPlaylistsEndpointIncludesVideos,
|
guard let playlist = currentPlaylist else { return nil }
|
||||||
let playlist = currentPlaylist
|
|
||||||
else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let resource = player.accounts.api.playlist(playlist.id)
|
let resource = player.accounts.api.playlist(playlist.id)
|
||||||
resource?.addObserver(store)
|
|
||||||
|
if player.accounts.app.userPlaylistsUseChannelPlaylistEndpoint {
|
||||||
|
resource?.addObserver(channelPlaylist)
|
||||||
|
} else {
|
||||||
|
resource?.addObserver(userPlaylist)
|
||||||
|
}
|
||||||
|
|
||||||
return resource
|
return resource
|
||||||
}
|
}
|
||||||
@ -118,8 +121,9 @@ struct PlaylistsView: View {
|
|||||||
}
|
}
|
||||||
.onChange(of: accounts.current) { _ in
|
.onChange(of: accounts.current) { _ in
|
||||||
model.load(force: true)
|
model.load(force: true)
|
||||||
|
resource?.load()
|
||||||
}
|
}
|
||||||
.onChange(of: selectedPlaylistID) { _ in
|
.onChange(of: currentPlaylist) { _ in
|
||||||
resource?.load()
|
resource?.load()
|
||||||
}
|
}
|
||||||
.onChange(of: model.reloadPlaylists) { _ in
|
.onChange(of: model.reloadPlaylists) { _ in
|
||||||
|
@ -7,13 +7,14 @@ struct PlaylistVideosView: View {
|
|||||||
@EnvironmentObject<PlayerModel> private var player
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
@EnvironmentObject<PlaylistsModel> private var model
|
@EnvironmentObject<PlaylistsModel> private var model
|
||||||
|
|
||||||
@StateObject private var store = Store<ChannelPlaylist>()
|
@StateObject private var channelPlaylist = Store<ChannelPlaylist>()
|
||||||
|
@StateObject private var userPlaylist = Store<Playlist>()
|
||||||
|
|
||||||
var contentItems: [ContentItem] {
|
var contentItems: [ContentItem] {
|
||||||
var videos = playlist.videos
|
var videos = playlist.videos
|
||||||
|
|
||||||
if videos.isEmpty {
|
if videos.isEmpty {
|
||||||
videos = store.item?.videos ?? []
|
videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? []
|
||||||
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
@ -31,7 +32,12 @@ struct PlaylistVideosView: View {
|
|||||||
|
|
||||||
private var resource: Resource? {
|
private var resource: Resource? {
|
||||||
let resource = player.accounts.api.playlist(playlist.id)
|
let resource = player.accounts.api.playlist(playlist.id)
|
||||||
resource?.addObserver(store)
|
|
||||||
|
if player.accounts.app.userPlaylistsUseChannelPlaylistEndpoint {
|
||||||
|
resource?.addObserver(channelPlaylist)
|
||||||
|
} else {
|
||||||
|
resource?.addObserver(userPlaylist)
|
||||||
|
}
|
||||||
|
|
||||||
return resource
|
return resource
|
||||||
}
|
}
|
||||||
@ -48,9 +54,8 @@ struct PlaylistVideosView: View {
|
|||||||
BrowserPlayerControls {
|
BrowserPlayerControls {
|
||||||
VerticalCells(items: contentItems)
|
VerticalCells(items: contentItems)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
guard contentItems.isEmpty else { return }
|
||||||
resource?.load()
|
resource?.load()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onChange(of: model.reloadPlaylists) { _ in
|
.onChange(of: model.reloadPlaylists) { _ in
|
||||||
resource?.load()
|
resource?.load()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user