2021-06-18 04:13:29 +05:30
|
|
|
import Alamofire
|
|
|
|
import Foundation
|
|
|
|
import SwiftyJSON
|
|
|
|
|
|
|
|
final class SponsorBlockSegmentsProvider: ObservableObject {
|
2021-06-20 01:40:14 +05:30
|
|
|
static let categories = ["sponsor", "selfpromo", "outro", "intro", "music_offtopic", "interaction"]
|
2021-06-18 04:13:29 +05:30
|
|
|
|
|
|
|
@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,
|
2021-06-20 01:47:48 +05:30
|
|
|
"categories": JSON(SponsorBlockSegmentsProvider.categories).rawString(String.Encoding.utf8)!
|
2021-06-18 04:13:29 +05:30
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|