Allow to add videos only to user created playlists

This commit is contained in:
Arkadiusz Fal 2022-09-12 17:23:20 +02:00
parent 8c2ffa1b99
commit d01b0f8275
3 changed files with 8 additions and 4 deletions

View File

@ -634,10 +634,12 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
} }
private func extractPlaylist(from content: JSON) -> Playlist { private func extractPlaylist(from content: JSON) -> Playlist {
.init( let id = content["playlistId"].stringValue
id: content["playlistId"].stringValue, return Playlist(
id: id,
title: content["title"].stringValue, title: content["title"].stringValue,
visibility: content["isListed"].boolValue ? .public : .private, visibility: content["isListed"].boolValue ? .public : .private,
editable: id.starts(with: "IV"),
updated: content["updated"].doubleValue, updated: content["updated"].doubleValue,
videos: content["videos"].arrayValue.map { extractVideo(from: $0) } videos: content["videos"].arrayValue.map { extractVideo(from: $0) }
) )

View File

@ -17,15 +17,17 @@ struct Playlist: Identifiable, Equatable, Hashable {
let id: String let id: String
var title: String var title: String
var visibility: Visibility var visibility: Visibility
var editable = true
var updated: TimeInterval? var updated: TimeInterval?
var videos = [Video]() var videos = [Video]()
init(id: String, title: String, visibility: Visibility, updated: TimeInterval? = nil, videos: [Video] = []) { init(id: String, title: String, visibility: Visibility, editable: Bool = true, updated: TimeInterval? = nil, videos: [Video] = []) {
self.id = id self.id = id
self.title = title self.title = title
self.visibility = visibility self.visibility = visibility
self.editable = editable
self.updated = updated self.updated = updated
self.videos = videos self.videos = videos
} }

View File

@ -94,7 +94,7 @@ struct AddToPlaylistView: View {
selectPlaylistButton selectPlaylistButton
#else #else
Picker("Playlist", selection: $selectedPlaylistID) { Picker("Playlist", selection: $selectedPlaylistID) {
ForEach(model.all) { playlist in ForEach(model.all.filter(\.editable)) { playlist in
Text(playlist.title).tag(playlist.id) Text(playlist.title).tag(playlist.id)
} }
} }