mirror of
https://github.com/yattee/yattee.git
synced 2025-12-22 12:40:23 +00:00
Use Siesta framework
This commit is contained in:
35
Model/SponsorBlockAPI.swift
Normal file
35
Model/SponsorBlockAPI.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
import Alamofire
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
final class SponsorBlockAPI: ObservableObject {
|
||||
static let categories = ["sponsor", "selfpromo", "outro", "intro", "music_offtopic", "interaction"]
|
||||
|
||||
@Published var video: Video?
|
||||
|
||||
@Published var segments = [Segment]()
|
||||
|
||||
var id: String
|
||||
|
||||
init(_ id: String) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
func load() {
|
||||
AF.request("https://sponsor.ajay.app/api/skipSegments", parameters: parameters).responseJSON { response in
|
||||
switch response.result {
|
||||
case let .success(value):
|
||||
self.segments = JSON(value).arrayValue.map { SponsorBlockSegment($0) }
|
||||
case let .failure(error):
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var parameters: [String: String] {
|
||||
[
|
||||
"videoID": id,
|
||||
"categories": JSON(SponsorBlockAPI.categories).rawString(String.Encoding.utf8)!
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user