175 lines
5.7 KiB
Swift
175 lines
5.7 KiB
Swift
//
|
|
// SPVideoAPI.swift
|
|
// MoviaBox
|
|
//
|
|
// Created by 曾觉新 on 2025/4/10.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPVideoAPI: NSObject {
|
|
|
|
///获取视频详情
|
|
static func requestVideoDetail(videoId: String?, shortPlayId: String, activityId: String? = nil, completer: ((_ model: SPVideoDetailModel?) -> Void)?) {
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId
|
|
]
|
|
|
|
// if let videoId = videoId {
|
|
// }
|
|
parameters["video_id"] = "0"
|
|
if let activityId = activityId {
|
|
parameters["activity_id"] = activityId
|
|
}
|
|
|
|
var param = SPNetworkParameters(path: "/getVideoDetails")
|
|
param.method = .get
|
|
param.parameters = parameters
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPVideoDetailModel>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///创建播放记录
|
|
static func requestCreateVideoPlayHistory(videoId: String, shortPlayId: String) {
|
|
var param = SPNetworkParameters(path: "/createHistory")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"video_id" : videoId,
|
|
"short_play_id" : shortPlayId
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///视频观看结束
|
|
static func requestViewingFinish(shortPlayId: String, videoId: String, activityId: String) {
|
|
var param = SPNetworkParameters(path: "/activeAfterWatchingVideo")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"short_play_video_id" : videoId,
|
|
"short_play_id" : shortPlayId,
|
|
"activity_id" : activityId
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///上报播放时长
|
|
static func requestUploadPlayTime(shortPlayId: String, videoId: String, seconds: Int) {
|
|
|
|
var param = SPNetworkParameters(path: "/uploadHistorySeconds")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"video_id" : videoId,
|
|
"short_play_id" : shortPlayId,
|
|
"play_seconds" : seconds
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///收藏短剧
|
|
static func requestCollectShort(isCollect: Bool, shortPlayId: String, videoId: String?, success: (() -> Void)?, failure: (() -> Void)? = nil) {
|
|
let path: String
|
|
if isCollect {
|
|
path = "/collect"
|
|
} else {
|
|
path = "/cancelCollect"
|
|
}
|
|
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId,
|
|
]
|
|
|
|
if let videoId = videoId {
|
|
parameters["video_id"] = videoId
|
|
}
|
|
|
|
var param = SPNetworkParameters(path: path)
|
|
param.isLoding = true
|
|
param.parameters = parameters
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<String>) in
|
|
if response.code == SPNetworkCodeSucceed {
|
|
success?()
|
|
NotificationCenter.default.post(name: SPVideoAPI.updateShortCollectStateNotification, object: nil, userInfo: [
|
|
"state" : isCollect,
|
|
"id" : shortPlayId,
|
|
])
|
|
} else {
|
|
failure?()
|
|
}
|
|
}
|
|
}
|
|
|
|
///收藏列表
|
|
static func requestCollectList(page: Int, completer: ((_ listModel: SPListModel<SPShortModel>?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/myCollections")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///历史记录列表
|
|
static func requestPlayHistoryList(page: Int, pageSize: Int = 20, completer: ((_ listModel: SPListModel<SPShortModel>?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/myHistorys")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : pageSize
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///获取视频分类
|
|
static func requestShortCategoryList(completer: ((_ list: [SPCategoryModel]?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/getCategories")
|
|
param.method = .get
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPCategoryModel>>) in
|
|
completer?(response.data?.list)
|
|
}
|
|
}
|
|
|
|
///获取分类短剧
|
|
static func requestCategoryShortList(page: Int, id: String, completer: ((_ listModel: SPListModel<SPShortModel>?) -> Void)?) {
|
|
var param = SPNetworkParameters(path: "/videoList")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"category_id" : id,
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
SPNetwork.request(parameters: param) { (response: SPNetworkResponse<SPListModel<SPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SPVideoAPI {
|
|
///更新短剧关注状态 [ "state" : isCollect, "id" : shortPlayId,]
|
|
@objc static let updateShortCollectStateNotification = NSNotification.Name(rawValue: "SPVideoAPI.updateShortCollectStateNotification")
|
|
|
|
}
|