193 lines
6.3 KiB
Swift
193 lines
6.3 KiB
Swift
//
|
|
// VPVideoAPI.swift
|
|
// Veloria
|
|
//
|
|
// Created by Veloria on 2025/5/22.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class VPVideoAPI: NSObject {
|
|
|
|
///获取视频详情
|
|
static func requestVideoDetail(shortPlayId: String, activityId: String? = nil, completer: ((_ model: VPVideoDetailModel?) -> Void)?) {
|
|
var parameters: [String : Any] = [
|
|
"short_play_id" : shortPlayId,
|
|
"video_id" : "0"
|
|
]
|
|
|
|
if let activityId = activityId {
|
|
parameters["activity_id"] = activityId
|
|
}
|
|
|
|
var param = VPNetworkParameters(path: "/getVideoDetails")
|
|
param.method = .get
|
|
param.parameters = parameters
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPVideoDetailModel>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
|
|
///获取分类短剧
|
|
static func requestCategoryVideoList(id: String, page: Int, completer: ((_ listModel: VPListModel<VPShortModel>?) -> Void)?) {
|
|
|
|
var param = VPNetworkParameters(path: "/videoList")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"category_id" : id,
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPListModel<VPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///推荐短剧
|
|
static func requestRecommandsVideo(page: Int, completer: ((_ listModel: VPListModel<VPShortModel>?) -> Void)?) {
|
|
|
|
var param = VPNetworkParameters(path: "/getRecommands")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"page_size" : 20,
|
|
"current_page" : page
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPListModel<VPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///收藏短剧
|
|
static func requestCollectShort(isCollect: Bool, shortPlayId: String, videoId: String?, isLoding: Bool = true, 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 = VPNetworkParameters(path: path)
|
|
param.isLoding = isLoding
|
|
param.parameters = parameters
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<String>) in
|
|
if response.code == VPNetworkCodeSucceed {
|
|
success?()
|
|
NotificationCenter.default.post(name: VPVideoAPI.updateShortCollectStateNotification, object: nil, userInfo: [
|
|
"state" : isCollect,
|
|
"id" : shortPlayId,
|
|
])
|
|
} else {
|
|
failure?()
|
|
}
|
|
}
|
|
}
|
|
|
|
///收藏列表
|
|
static func requestCollectList(page: Int, completer: ((_ listModel: VPListModel<VPShortModel>?) -> Void)?) {
|
|
var param = VPNetworkParameters(path: "/myCollections")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : 20
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPListModel<VPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///创建播放记录
|
|
static func requestCreatePlayHistory(videoId: String?, shortPlayId: String?) {
|
|
guard let shortPlayId = shortPlayId else { return }
|
|
|
|
var param = VPNetworkParameters(path: "/createHistory")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"video_id" : videoId ?? "0",
|
|
"short_play_id" : shortPlayId
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///历史记录列表
|
|
static func requestPlayHistoryList(page: Int, pageSize: Int = 20, completer: ((_ listModel: VPListModel<VPShortModel>?) -> Void)?) {
|
|
var param = VPNetworkParameters(path: "/myHistorys")
|
|
param.method = .get
|
|
param.parameters = [
|
|
"current_page" : page,
|
|
"page_size" : pageSize
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPListModel<VPShortModel>>) in
|
|
completer?(response.data)
|
|
}
|
|
}
|
|
|
|
///视频推荐
|
|
static func requestDetailsRecommand(completer: ((_ list: [VPShortModel]?) -> Void)?) {
|
|
|
|
var param = VPNetworkParameters(path: "/getDetailsRecommand")
|
|
param.method = .get
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPListModel<VPShortModel>>) in
|
|
completer?(response.data?.list)
|
|
}
|
|
}
|
|
|
|
///视频观看结束
|
|
static func requestViewingFinish(shortPlayId: String, videoId: String, activityId: String) {
|
|
var param = VPNetworkParameters(path: "/activeAfterWatchingVideo")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"short_play_video_id" : videoId,
|
|
"short_play_id" : shortPlayId,
|
|
"activity_id" : activityId
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
|
|
///上报播放时长
|
|
static func requestUploadPlayProgress(shortPlayId: String, videoId: String, seconds: Int) {
|
|
|
|
var param = VPNetworkParameters(path: "/uploadHistorySeconds")
|
|
param.isLoding = false
|
|
param.isToast = false
|
|
param.parameters = [
|
|
"video_id" : videoId,
|
|
"short_play_id" : shortPlayId,
|
|
"play_seconds" : seconds
|
|
]
|
|
|
|
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<String>) in
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
extension VPVideoAPI {
|
|
///更新短剧关注状态 [ "state" : isCollect, "id" : shortPlayId,]
|
|
@objc static let updateShortCollectStateNotification = NSNotification.Name(rawValue: "VPVideoAPI.updateShortCollectStateNotification")
|
|
|
|
}
|