123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- import Foundation
- import Kingfisher
- import KingfisherWebP
- import Photos
- import ObjectMapper
- import RealmSwift
- import BFCommonKit
- public class PQEditVisionTrackMaterialsModel: PQEditBaseModel {
- @objc dynamic public var width: Float = 0
- @objc dynamic public var height: Float = 0
- @objc public var itemWidth: Float = 0
- @objc public var itemHeight: Float = 0
-
- @objc dynamic public var sourceType: Int = 0
- @objc dynamic public var type: String = ""
- @objc dynamic public var canvasFillType: String = ""
- @objc dynamic public var materialType: String = ""
-
- @objc dynamic public var duration: Float64 = 0
-
- @objc public var aptDuration: Float64 = 0
- @objc dynamic public var id: Int64 = 0
- @objc dynamic public var materialLayer: PQEditMaterialLayerModel?
- @objc dynamic public var materialEffect: PQEditMaterialEffectModel?
-
-
- @objc dynamic public var timelineIn: Float64 = 0
- @objc dynamic public var timelineOut: Float64 = 0
-
- @objc dynamic public var model_in: Float64 = 0
- @objc dynamic public var out: Float64 = 0
-
-
-
-
- @objc dynamic public var speedRate: Float = 1
-
- @objc dynamic public var volumeGain: Float64 = 0
- @objc dynamic public var subtitleInfo: PQEditSubtitleInfoModel?
- @objc dynamic public var materialDurationFit: PQEditmaterialDurationFitModel?
- @objc dynamic public var materialSizeClip: PQEditMaterialSizeClipModel?
- @objc dynamic public var materialPosition: PQEditMaterialPositionModel?
-
-
- @objc dynamic public var materialUrl: String = ""
-
- public var netResUrl: String = ""
- public var netResCoverImageURL: String?
-
- @objc dynamic public var locationPath: String = "" {
- didSet {
- BFLog(message: "如果是全路径就有问题XXXX 设置了新值为:locationPath\(locationPath)")
- }
- }
-
-
-
- public var isNetworkMaterial: Bool = false
- public var isSelected: Bool = false
-
- public var asset: PHAsset?
- public var PHImageRequestID : Int32?
- public var selectedIndex: Int = 1
-
- public var originalData: Data?
-
- public var coverImageUI: UIImage?
- public var downloadState: downloadState = .downloading
- public var localSearchId: String?
- public var sliceId: String?
- public var searchId: String?
- public var searchResourceId: String?
- public var outSideChannel: String = ""
- public var outSideVideoId: String = ""
- public var status: inputStatus = .recordSuccess
- public required init() {
- super.init()
- materialDurationFit = PQEditmaterialDurationFitModel()
- materialSizeClip = PQEditMaterialSizeClipModel()
- materialPosition = PQEditMaterialPositionModel()
- }
- required convenience public init?(map _: Map) {
- self.init()
- }
- public override func mapping(map: Map) {
- width <- map["width"]
- height <- map["height"]
- sourceType <- map["sourceType"]
- type <- map["type"]
- canvasFillType <- map["canvasFillType"]
- materialUrl <- map["materialUrl"]
- materialType <- map["materialType"]
- duration <- (map["duration"], timeTransform)
- id <- map["id"]
- materialLayer <- map["materialLayer"]
- materialEffect <- map["materialEffect"]
- timelineIn <- (map["timelineIn"], timeTransform)
- timelineOut <- (map["timelineOut"], timeTransform)
- model_in <- (map["in"], timeTransform)
- out <- (map["out"], timeTransform)
- volumeGain <- (map["volumeGain"], volumeGainTransform)
- subtitleInfo <- map["subtitleInfo"]
- materialDurationFit <- map["materialDurationFit"]
- materialSizeClip <- map["materialSizeClip"]
- materialPosition <- map["materialPosition"]
- locationPath <- map["locationPath"]
- aptDuration <- map["aptDuration"]
- outSideVideoId <- map["outSideVideoId"]
- outSideChannel <- map["outSideChannel"]
- }
-
- public func videoIsCrop() -> Bool {
- return (type == StickerType.VIDEO.rawValue && (model_in != 0 || out != 0))
- }
-
- public func generateDefaultValues() {
- if materialDurationFit?.fitType.count == 0 {
- materialDurationFit?.fitType = adapterMode.loopAuto.rawValue
- }
- if canvasFillType.count == 0 {
- canvasFillType = stickerContentMode.aspectFitStr.rawValue
- }
- }
-
-
- public convenience init(jsonDict: [String: Any]) {
- self.init()
- if jsonDict.keys.contains("width") {
- width = Float(CGFloat(Double("\(jsonDict["width"] ?? "")") ?? 0))
- }
- if jsonDict.keys.contains("height") {
- height = Float(CGFloat(Double("\(jsonDict["height"] ?? "")") ?? 0))
- }
- if jsonDict.keys.contains("imageUrl"), !(jsonDict["imageUrl"] is NSNull), "\(jsonDict["imageUrl"] ?? "")" != "<null>" {
- netResCoverImageURL = "\(jsonDict["imageUrl"] ?? "")"
- }
- if jsonDict.keys.contains("gifUrl"), !(jsonDict["gifUrl"] is NSNull), "\(jsonDict["gifUrl"] ?? "")" != "<null>" {
- netResCoverImageURL = "\(jsonDict["gifUrl"] ?? "")"
- }
- if jsonDict.keys.contains("coversImageUrl"), !(jsonDict["coversImageUrl"] is NSNull), "\(jsonDict["coversImageUrl"] ?? "")" != "<null>" {
- netResCoverImageURL = "\(jsonDict["coversImageUrl"] ?? "")"
- }
- if jsonDict.keys.contains("videoUrl") {
- netResUrl = "\(jsonDict["videoUrl"] ?? "")"
- }
- if jsonDict.keys.contains("duration") {
- duration = Double((Int("\(jsonDict["duration"] ?? "0")") ?? 0) / 1_000_000)
- out = duration
- }
- if jsonDict.keys.contains("id") {
- searchResourceId = "\(jsonDict["id"] ?? "")"
- }
- if jsonDict.keys.contains("searchId") {
- searchId = "\(jsonDict["searchId"] ?? "")"
- }
- if jsonDict.keys.contains("sliceId") {
- sliceId = "\(jsonDict["sliceId"] ?? "")"
- }
- if jsonDict.keys.contains("sourceType") {
- sourceType = Int("\(jsonDict["sourceType"] ?? "1")") ?? 0
- }
- if jsonDict.keys.contains("outSideVideoId"), "\(jsonDict["outSideVideoId"] ?? "")" != "<null>" {
- outSideVideoId = "\(jsonDict["outSideVideoId"] ?? "")"
- }
- if jsonDict.keys.contains("outSideChannel"), "\(jsonDict["outSideChannel"] ?? "")" != "<null>" {
- outSideChannel = "\(jsonDict["outSideChannel"] ?? "")"
- }
- itemHeight = itemWidth * (height / (width == 0 ? 1 : width))
- }
-
-
-
- public func isEqualMaterial(newMaterial: PQEditVisionTrackMaterialsModel?) -> Bool {
- if newMaterial == nil {
- BFLog(message: "素材对比为空:material = \(String(describing: newMaterial))")
- return false
- }
- if asset != nil && newMaterial?.asset != nil && asset == newMaterial?.asset {
- BFLog(message: "素材对比相等:asset = \(asset!)--\(String(describing: newMaterial?.asset))")
- return true
- }
- if (netResCoverImageURL != nil && (netResCoverImageURL?.count ?? 0) > 0) && (newMaterial?.netResCoverImageURL != nil && (newMaterial?.netResCoverImageURL?.count ?? 0) > 0) && netResCoverImageURL == newMaterial?.netResCoverImageURL {
- BFLog(message: "素材对比相等:netResCoverImageURL = \(netResCoverImageURL!)--\(String(describing: newMaterial?.netResCoverImageURL))")
- return true
- }
- if (materialUrl.count > 0) && ((newMaterial?.materialUrl.count ?? 0) > 0) && materialUrl == newMaterial?.materialUrl {
- BFLog(message: "素材对比相等:materialUrl = \(materialUrl)--\(String(describing: newMaterial?.materialUrl))")
- return true
- }
- BFLog(message: "素材对比不相等:asset = \(String(describing: asset))--\(String(describing: newMaterial?.asset)),netResCoverImageURL = \(String(describing: netResCoverImageURL))--\(String(describing: newMaterial?.netResCoverImageURL)),materialUrl = \(materialUrl)--\(String(describing: newMaterial?.materialUrl))")
- return false
- }
- public func getCoverImage() -> UIImage? {
- if coverImageUI != nil {
- BFLog(message: "已经有封面了")
- return coverImageUI
- }
- if locationPath.count == 0 {
- BFLog(message: "本地地址为空可能没有下载完成!!")
- return nil
- }
- BFLog(message: " locationPath is\(documensDirectory + locationPath)")
- if type != StickerType.VIDEO.rawValue {
- var coverImage = UIImage(contentsOfFile: documensDirectory + locationPath)
- if coverImage == nil {
-
- var fileData: Data?
- if fileIsExists(filePath: documensDirectory + locationPath) {
- fileData = try! Data(contentsOf: URL(fileURLWithPath: documensDirectory + locationPath))
- }
- if fileData != nil && (fileData?.count ?? 0) > 0 && fileData?.isWebPFormat ?? false {
- BFLog(message: "这个资源为web!")
- coverImage = WebPProcessor.default.process(item: ImageProcessItem.data(fileData!), options: KingfisherParsedOptionsInfo([.onlyLoadFirstFrame, .scaleFactor(1)]))
- }
- }
- return coverImage
- } else {
- if coverImageUI != nil {
- BFLog(message: "已经有封面了")
- return coverImageUI
- } else {
- return PQVideoSnapshotUtil.videoSnapshot(videoURL: URL(fileURLWithPath: documensDirectory + locationPath), time: 0)
- }
- }
- }
- }
|