98 lines
3.1 KiB
Swift
98 lines
3.1 KiB
Swift
//
|
|
// BRVideoAPI.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 湖南秦九 on 2025/6/30.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRVideoAPI {
|
|
///获取视频详情
|
|
static func requestVideoDetail(shortPlayId: String, activityId: String? = nil, revolution: BRShortModel.VideoRevolution? = nil, completer: ((_ model: BRVideoDetailModel?) -> Void)?) {
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId,
|
|
"video_id" : "0"
|
|
]
|
|
|
|
if let activityId = activityId {
|
|
parameters["activity_id"] = activityId
|
|
}
|
|
|
|
if let revolution = revolution?.rawValue {
|
|
parameters["revolution"] = revolution
|
|
}
|
|
|
|
var param = BRNetworkParameters(path: "/getVideoDetails")
|
|
param.method = .get
|
|
param.parameters = parameters
|
|
|
|
BRNetwork.request(parameters: param) { (response: BRNetworkResponse<BRVideoDetailModel>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
|
|
///收藏
|
|
static func requestFavorite(isFavorite: Bool, shortPlayId: String, videoId: String?, isLoding: Bool = true, success: (() -> Void)?, failure: (() -> Void)? = nil) {
|
|
let path: String
|
|
if isFavorite {
|
|
path = "/collect"
|
|
} else {
|
|
path = "/cancelCollect"
|
|
}
|
|
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId,
|
|
]
|
|
|
|
if let videoId = videoId {
|
|
parameters["video_id"] = videoId
|
|
}
|
|
|
|
var param = BRNetworkParameters(path: path)
|
|
param.isLoding = isLoding
|
|
param.parameters = parameters
|
|
|
|
BRNetwork.request(parameters: param) { (response: BRNetworkResponse<String>) in
|
|
if response.code == BRNetworkCodeSucceed {
|
|
success?()
|
|
NotificationCenter.default.post(name: BRVideoAPI.updateShortFavoriteStateNotification, object: nil, userInfo: [
|
|
"state" : isFavorite,
|
|
"id" : shortPlayId,
|
|
])
|
|
} else {
|
|
failure?()
|
|
}
|
|
}
|
|
}
|
|
|
|
///推荐短剧
|
|
static func requestExploreVideo(page: Int, revolution: BRShortModel.VideoRevolution? = nil, completer: ((_ listModel: BRListModel<BRShortModel>?) -> Void)?) {
|
|
|
|
var parameters: [String : Any] = [
|
|
"page_size" : 20,
|
|
"current_page" : page
|
|
]
|
|
|
|
if let revolution = revolution?.rawValue {
|
|
parameters["revolution"] = revolution
|
|
}
|
|
|
|
var param = BRNetworkParameters(path: "/getRecommands")
|
|
param.method = .get
|
|
param.parameters = parameters
|
|
|
|
|
|
BRNetwork.request(parameters: param) { (response: BRNetworkResponse<BRListModel<BRShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
extension BRVideoAPI {
|
|
///更新短剧关注状态 [ "state" : isFavorite, "id" : shortPlayId,]
|
|
@objc static let updateShortFavoriteStateNotification = NSNotification.Name(rawValue: "BRVideoAPI.updateShortFavoriteStateNotification")
|
|
}
|