Adding/removing videos to/from playlists

This commit is contained in:
Arkadiusz Fal
2021-07-09 16:53:53 +02:00
parent 31bd2f7fe6
commit f397b13720
12 changed files with 218 additions and 17 deletions

View File

@@ -112,6 +112,14 @@ final class InvidiousAPI: Service {
resource("/auth/playlists/\(id)")
}
func playlistVideos(_ id: String) -> Resource {
playlist(id).child("videos")
}
func playlistVideo(_ playlistID: String, _ videoID: String) -> Resource {
playlist(playlistID).child("videos").child(videoID)
}
func search(_ query: SearchQuery) -> Resource {
var resource = resource("/search")
.withParam("q", searchQuery(query.query))

View File

@@ -6,17 +6,20 @@ struct Playlist: Identifiable, Equatable, Hashable {
var title: String
var visibility: PlaylistVisibility
var updated: TimeInterval
var videos = [Video]()
init(_ json: JSON) {
id = json["playlistId"].stringValue
title = json["title"].stringValue
visibility = json["isListed"].boolValue ? .public : .private
updated = json["updated"].doubleValue
videos = json["videos"].arrayValue.map { Video($0) }
}
static func == (lhs: Playlist, rhs: Playlist) -> Bool {
lhs.id == rhs.id && lhs.title == rhs.title && lhs.visibility == rhs.visibility
lhs.id == rhs.id && lhs.updated == rhs.updated
}
func hash(into hasher: inout Hasher) {

View File

@@ -0,0 +1,8 @@
//
// PlaylistVideo.swift
// Pearvidious
//
// Created by Arkadiusz Fal on 09/07/2021.
//
import Foundation

View File

@@ -15,10 +15,21 @@ struct Video: Identifiable {
var description: String
var genre: String
let indexID: String?
var streams = [Stream]()
init(_ json: JSON) {
id = json["videoId"].stringValue
let videoID = json["videoId"].stringValue
if let id = json["indexId"].string {
indexID = id
self.id = videoID + id
} else {
indexID = nil
id = videoID
}
title = json["title"].stringValue
author = json["author"].stringValue
length = json["lengthSeconds"].doubleValue