mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Playlists support
This commit is contained in:
25
Model/Playlist.swift
Normal file
25
Model/Playlist.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
final class Playlist: Identifiable, ObservableObject, Equatable, Hashable {
|
||||
let id: String
|
||||
var title: String
|
||||
var description: String
|
||||
|
||||
var videos = [Video]()
|
||||
|
||||
init(_ json: JSON) {
|
||||
id = json["playlistId"].stringValue
|
||||
title = json["title"].stringValue
|
||||
description = json["description"].stringValue
|
||||
videos = json["videos"].arrayValue.map { Video($0) }
|
||||
}
|
||||
|
||||
static func == (lhs: Playlist, rhs: Playlist) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
}
|
22
Model/PlaylistsProvider.swift
Normal file
22
Model/PlaylistsProvider.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
import Alamofire
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
final class PlaylistsProvider: DataProvider {
|
||||
@Published var playlists = [Playlist]()
|
||||
|
||||
let profile = Profile()
|
||||
|
||||
func load(successHandler: @escaping ([Playlist]) -> Void = { _ in }) {
|
||||
let headers = HTTPHeaders([HTTPHeader(name: "Cookie", value: "SID=\(profile.sid)")])
|
||||
DataProvider.request("auth/playlists", headers: headers).responseJSON { response in
|
||||
switch response.result {
|
||||
case let .success(value):
|
||||
self.playlists = JSON(value).arrayValue.map { Playlist($0) }
|
||||
successHandler(self.playlists)
|
||||
case let .failure(error):
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
final class TrendingState: ObservableObject {
|
||||
@Published var category: TrendingCategory = .default
|
||||
@Published var country: Country = .pl
|
||||
}
|
Reference in New Issue
Block a user