mirror of
				https://github.com/yattee/yattee.git
				synced 2025-10-31 04:31:54 +00:00 
			
		
		
		
	Add support for Invidious Saved Playlists (fix #259)
This commit is contained in:
		| @@ -32,7 +32,7 @@ struct AppSidebarPlaylists: View { | ||||
|     @ViewBuilder func playlistLabel(_ playlist: Playlist) -> some View { | ||||
|         let label = Label(playlist.title, systemImage: RecentsModel.symbolSystemImage(playlist.title)) | ||||
|  | ||||
|         if player.accounts.app.userPlaylistsEndpointIncludesVideos { | ||||
|         if player.accounts.app.userPlaylistsEndpointIncludesVideos, !playlist.videos.isEmpty { | ||||
|             label | ||||
|                 .backport | ||||
|                 .badge(Text("\(playlist.videos.count)")) | ||||
|   | ||||
| @@ -11,7 +11,8 @@ struct PlaylistsView: View { | ||||
|     @State private var showingEditPlaylist = false | ||||
|     @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<PlayerModel> private var player | ||||
| @@ -23,7 +24,8 @@ struct PlaylistsView: View { | ||||
|         var videos = currentPlaylist?.videos ?? [] | ||||
|  | ||||
|         if videos.isEmpty { | ||||
|             videos = store.item?.videos ?? [] | ||||
|             videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? [] | ||||
|  | ||||
|             if !player.accounts.app.userPlaylistsEndpointIncludesVideos { | ||||
|                 var i = 0 | ||||
|  | ||||
| @@ -40,14 +42,15 @@ struct PlaylistsView: View { | ||||
|     } | ||||
|  | ||||
|     private var resource: Resource? { | ||||
|         guard !player.accounts.app.userPlaylistsEndpointIncludesVideos, | ||||
|               let playlist = currentPlaylist | ||||
|         else { | ||||
|             return nil | ||||
|         } | ||||
|         guard let playlist = currentPlaylist else { return nil } | ||||
|  | ||||
|         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 | ||||
|     } | ||||
| @@ -118,8 +121,9 @@ struct PlaylistsView: View { | ||||
|         } | ||||
|         .onChange(of: accounts.current) { _ in | ||||
|             model.load(force: true) | ||||
|             resource?.load() | ||||
|         } | ||||
|         .onChange(of: selectedPlaylistID) { _ in | ||||
|         .onChange(of: currentPlaylist) { _ in | ||||
|             resource?.load() | ||||
|         } | ||||
|         .onChange(of: model.reloadPlaylists) { _ in | ||||
|   | ||||
| @@ -7,13 +7,14 @@ struct PlaylistVideosView: View { | ||||
|     @EnvironmentObject<PlayerModel> private var player | ||||
|     @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 videos = playlist.videos | ||||
|  | ||||
|         if videos.isEmpty { | ||||
|             videos = store.item?.videos ?? [] | ||||
|             videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? [] | ||||
|             if !player.accounts.app.userPlaylistsEndpointIncludesVideos { | ||||
|                 var i = 0 | ||||
|  | ||||
| @@ -31,7 +32,12 @@ struct PlaylistVideosView: View { | ||||
|  | ||||
|     private var resource: Resource? { | ||||
|         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 | ||||
|     } | ||||
| @@ -48,9 +54,8 @@ struct PlaylistVideosView: View { | ||||
|         BrowserPlayerControls { | ||||
|             VerticalCells(items: contentItems) | ||||
|                 .onAppear { | ||||
|                     if !player.accounts.app.userPlaylistsEndpointIncludesVideos { | ||||
|                         resource?.load() | ||||
|                     } | ||||
|                     guard contentItems.isEmpty else { return } | ||||
|                     resource?.load() | ||||
|                 } | ||||
|                 .onChange(of: model.reloadPlaylists) { _ in | ||||
|                     resource?.load() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Arkadiusz Fal
					Arkadiusz Fal