2021-06-17 22:43:29 +00:00
|
|
|
import Alamofire
|
|
|
|
import Foundation
|
|
|
|
import SwiftyJSON
|
|
|
|
|
2021-06-28 10:43:07 +00:00
|
|
|
final class SponsorBlockAPI: ObservableObject {
|
2021-06-19 20:10:14 +00:00
|
|
|
static let categories = ["sponsor", "selfpromo", "outro", "intro", "music_offtopic", "interaction"]
|
2021-06-17 22:43:29 +00:00
|
|
|
|
2021-06-28 15:27:53 +00:00
|
|
|
var id: String
|
2021-06-17 22:43:29 +00:00
|
|
|
|
|
|
|
@Published var segments = [Segment]()
|
|
|
|
|
|
|
|
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,
|
2021-06-28 10:43:07 +00:00
|
|
|
"categories": JSON(SponsorBlockAPI.categories).rawString(String.Encoding.utf8)!
|
2021-06-17 22:43:29 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|