PQUploadViewModel.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // PQUploadViewModel.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/8/4.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import UIKit
  9. public class PQUploadViewModel: NSObject {
  10. /// 发布视频
  11. /// - Parameters:
  12. /// - projectId 项目ID-发布创作的视频时必传,会在进入创作工具页时生成,以app_no_projectdata为前缀
  13. /// - fileExtensions 视频封装格式 -必传
  14. /// - title: 标题
  15. /// - videoPath: 视频地址
  16. /// - coverImgPath: 封面地址
  17. /// - descr: 描述
  18. /// - videoFromScene 视频来源场景 1:普通上传 2:创作工具,3:普通上传转创作工具,4:后台转换加工,5:卡点视频制作
  19. /// - Returns: <#description#>
  20. class public func publishVideo(projectId: String?, fileExtensions: String?, title: String, videoPath: String, coverImgPath: String?, descr: String, videoFromScene: videoFromScene, reCreateData: PQReCreateModel?, eventTrackData: PQVideoMakeEventTrackModel?, completeHander: @escaping (_ videoData: PQVideoListModel?, _ jsonDict: [String: Any]?, _ msg: String?) -> Void) {
  21. BFLog(message: "AKAKAAKprojectId is\(String(describing: projectId)) videoFromScene is \(videoFromScene)")
  22. var params : Dictionary<String,Any> = ["title": title, "fileExtensions": fileExtensions ?? "application/octet-stream", "videoPath": videoPath, "descr": descr, "viewStatus": 1, "produceProjectId": (projectId ?? "") as String, "videoFromScene": videoFromScene.rawValue]
  23. if coverImgPath != nil && (coverImgPath?.count ?? 0) > 0 {
  24. params["coverImgPath"] = coverImgPath
  25. }
  26. SWNetRequest.postRequestData(url: PQENVUtil.shared.longvideoapi + videoSendUrl, parames: params) { response, _, error, _ in
  27. if error != nil {
  28. completeHander(nil, nil, error?.msg)
  29. return
  30. }
  31. var jsonDict = (response as! [String: Any])
  32. jsonDict["title"] = title
  33. jsonDict["auditStatus"] = 1
  34. jsonDict["uid"] = BFLoginUserInfo.shared.uid
  35. let tempModel = PQVideoListModel(jsonDict: jsonDict)
  36. tempModel.uid = Int(BFLoginUserInfo.shared.uid) ?? 0
  37. tempModel.auditStatus = 1
  38. completeHander(tempModel, jsonDict, nil)
  39. // 发布成功
  40. var extParams: [String: Any] = ["source": (projectId != nil && (projectId?.count ?? 0) > 0) ? "videoCompose" : "videoUpload", "projectId": projectId ?? ""]
  41. if reCreateData != nil {
  42. extParams["projectId"] = reCreateData?.projectId ?? ""
  43. extParams["parentVideoId"] = reCreateData?.videoId ?? ""
  44. extParams["parentProjectId"] = reCreateData?.parentProjectId ?? ""
  45. extParams["rootProjectId"] = reCreateData?.rootProjectId ?? ""
  46. }
  47. PQEventTrackViewModel.baseReportUpload(businessType: .bt_up_process, objectType: .ot_up_publishSuccess, pageSource: nil, extParams: extParams, remindmsg: "上传相关")
  48. if projectId != nil {
  49. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  50. if !isSuccess {
  51. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  52. if !isSuccess {
  53. PQBaseViewModel.reportSendVideo(projectId!, tempModel.uniqueId ?? "",videoFromScene: videoFromScene) { isSuccess, _ in
  54. if !isSuccess {}
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. if eventTrackData != nil {
  62. eventTrackData?.title = title
  63. eventTrackData?.videoDes = descr
  64. eventTrackData?.videoId = tempModel.uniqueId
  65. eventTrackData?.coverUrl = coverImgPath
  66. PQEventTrackViewModel.baseReportUpload(logType: .st_log_type_videoProduction, businessType: nil, objectType: nil, pageSource: nil, eventData: eventTrackData?.toParams(), remindmsg: "创作工具埋点上报")
  67. }
  68. }
  69. }
  70. /// 修改视频
  71. /// - Parameters:
  72. /// - title: 标题
  73. /// - videoId: 视频id
  74. /// - coverImgPath: 图片地址
  75. /// - descr: 描述
  76. /// - completeHander: <#completeHander description#>
  77. /// - Returns: <#description#>
  78. public class func updateVideo(title: String, videoId: String, coverImgPath: String, descr: String, completeHander: @escaping (_ videoData: PQVideoListModel?, _ msg: String?) -> Void) {
  79. SWNetRequest.postRequestData(url: PQENVUtil.shared.longvideoapi + updateVideoUrl, parames: ["title": title, "videoId": videoId, "coverImgPath": coverImgPath, "descr": descr, "viewStatus": 1, "barrageSwitch": 1]) { response, _, error, _ in
  80. if error != nil {
  81. completeHander(nil, error?.msg)
  82. return
  83. }
  84. // 1015
  85. let tempModel = PQVideoListModel(jsonDict: response as! [String: Any])
  86. tempModel.auditStatus = 1
  87. completeHander(tempModel, nil)
  88. }
  89. }
  90. /// 获取视频封面
  91. /// - Parameters:
  92. /// - videoId: 视频ID
  93. /// - videoPath: 视频地址
  94. /// - totalTime: 总时长
  95. /// - completeHander: <#completeHander description#>
  96. /// - Returns: <#description#>
  97. class public func vodeoCoverImageList(videoId: String, videoPath: String, totalTime: Int, videoHeight: CGFloat, videoWidth: CGFloat, completeHander: @escaping (_ coverImages: [PQUploadModel]?, _ msg: String?) -> Void) {
  98. SWNetRequest.postRequestData(url: PQENVUtil.shared.longvideoapi + vodeoCoverImageUrl, parames: ["id": videoId, "videoPath": videoPath, "totalTime": totalTime]) { response, _, error, _ in
  99. if error != nil {
  100. completeHander(nil, error?.msg)
  101. return
  102. }
  103. var coverImages: [PQUploadModel] = Array<PQUploadModel>.init()
  104. let data: [String: Any]? = response as? [String: Any]
  105. if data != nil, data?.keys.contains("videoCoverImages") ?? false {
  106. let videoCoverImages: [String]? = data?["videoCoverImages"] as? [String]
  107. if videoCoverImages != nil, (videoCoverImages?.count ?? 0) > 0 {
  108. for item in videoCoverImages! {
  109. let tempItem = PQUploadModel()
  110. tempItem.contentMode = .scaleAspectFit
  111. tempItem.videoHeight = videoHeight
  112. tempItem.videoWidth = videoWidth
  113. tempItem.imageUrl = item
  114. coverImages.append(tempItem)
  115. }
  116. }
  117. }
  118. completeHander(coverImages, nil)
  119. }
  120. }
  121. }