@takeoffmedia/react-native-penthera 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -175,6 +175,7 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
175
175
  val dataMap = mutableMapOf<String, Any>()
176
176
  var eap = ""
177
177
  var ead = ""
178
+ var creationTime = ""
178
179
  for (columnName in columnNames) {
179
180
  val columnIndex = cursor.getColumnIndex(columnName)
180
181
  if (columnIndex >= 0) {
@@ -214,6 +215,9 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
214
215
  if (columnName == "eap") {
215
216
  eap = value
216
217
  }
218
+ if (columnName == "creationTime") {
219
+ creationTime = value
220
+ }
217
221
  if (columnName == "activePercentOfDownloads") {
218
222
  val percentage = value.toDouble() * 100
219
223
  val isComplete = percentage == 100.0
@@ -221,6 +225,7 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
221
225
  }
222
226
  if (columnName == "firstPlayTime") {
223
227
  (dataMap["data"] as? MutableMap<String, Any> ?: mutableMapOf()).apply {
228
+ put("creationTime", if (value == "0") creationTime else value)
224
229
  put("effectiveExpiryDate", if (value == "0") ead else eap);
225
230
  put("isReproduced", value != "0");
226
231
  }.also { dataMap["data"] = it }
@@ -268,7 +273,7 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
268
273
  "Asset is null"
269
274
  )
270
275
  return
271
- }
276
+ }
272
277
  val body: String
273
278
  val status = asset.downloadStatus
274
279
  body = when (status) {
@@ -20,13 +20,6 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
20
20
  var assetError: String = ""
21
21
  var vcHttpServer: VirtuosoClientHTTPServer? = nil
22
22
 
23
- func getAssetId(asset: VirtuosoAsset) -> String {
24
- if let mediaId = asset.userInfo?["mediaId"] as? String {
25
- return mediaId
26
- } else {
27
- return asset.assetID
28
- }
29
- }
30
23
 
31
24
  func updateStatusInfo() {
32
25
  DispatchQueue.global().async {
@@ -146,16 +139,7 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
146
139
  }
147
140
  }
148
141
 
149
- func timeIntervalToString(_ timeInterval: TimeInterval?) -> String {
150
- let formatter = DateComponentsFormatter()
151
- formatter.allowedUnits = [.hour, .minute, .second]
152
- formatter.unitsStyle = .positional
153
- formatter.zeroFormattingBehavior = .pad
154
- guard let interval = timeInterval else {
155
- return "00:00:00"
156
- }
157
- return formatter.string(from: interval) ?? "00:00:00"
158
- }
142
+
159
143
 
160
144
  func dateToString (_ date: Date?) -> String? {
161
145
  let dateFormatter = DateFormatter()
@@ -414,69 +398,9 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
414
398
 
415
399
  var offlineCatalogs: [OfflineCatalog] = []
416
400
 
417
- // Process completed and pending assets using a shared function
418
- func processAsset(_ va: VirtuosoAsset) {
419
- let thumbnail = va.findAllAncillaries(withTag: "thumbnail").first
420
- let show = va.findAllAncillaries(withTag: "show").first
421
- let thumbnails = Thumbnails(
422
- thumbnail: thumbnail?.fileDownloadURL ?? "",
423
- show: show?.fileDownloadURL ?? ""
424
- )
425
-
426
- let expiryDate = va.expiryDate
427
- let effectiveExpiryDate = va.effectiveExpiryDate
428
- let isReproduced = va.firstPlayDateTime
429
- let creationDate = va.creationDateTime.toSeconds()
430
-
431
- var dataItem = DataItem(
432
- title: va.userInfo?["title"] as? String,
433
- seasonId: va.userInfo?["seasonId"] as? String,
434
- seasonTitle: va.userInfo?["seasonTitle"] as? String,
435
- duration: va.duration,
436
- estimatedSize: Int(va.estimatedSize),
437
- dataOffers: parseDataOffersInObject(anyElement: va.userInfo?["dataOffers"] as Any),
438
- expiryAfterPlay: timeIntervalToString(va.expiryAfterPlay),
439
- expiryAfterDownload: timeIntervalToString(va.expiryAfterDownload),
440
- isExpired: va.isExpired,
441
- inForcedExpire: va.inForcedExpire,
442
- isReproduced: isReproduced != nil,
443
- mediaId: va.userInfo?["mediaId"] as? String,
444
- vpid: va.userInfo?["vpid"] as? String
445
- )
446
-
447
- if let effectiveExpiryDate = effectiveExpiryDate {
448
- dataItem.effectiveExpiryDate = isReproduced != nil ? va.expiryAfterPlay : va.expiryAfterDownload
449
- }
450
-
451
- if let expiryDate = expiryDate {
452
- dataItem.expiryDate = va.expiryDate
453
- }
454
-
455
- if va.isExpired {
456
- va.delete()
457
- } else {
458
- let catalog = OfflineCatalog(
459
- id: getAssetId(asset: va), // Change vpid to assetId
460
- title: va.description,
461
- data: dataItem,
462
- thumbnails: thumbnails,
463
- isCompleted: va.downloadCompleteDateTime != nil ? true : false,
464
- isPaused: va.isPaused,
465
- percentage: Float(va.fractionComplete),
466
- creationTime: creationDate
467
- )
468
- offlineCatalogs.append(catalog)
469
- }
470
- }
471
-
472
- // Process completed assets
473
- for case let va as VirtuosoAsset in completedAssets {
474
- processAsset(va)
475
- }
476
-
477
- // Process pending assets
478
- for case let va as VirtuosoAsset in pendingAssets {
479
- processAsset(va)
401
+ let allAssets = completedAssets + pendingAssets
402
+ for case let va as VirtuosoAsset in allAssets {
403
+ offlineCatalogs.append(processAsset(va))
480
404
  }
481
405
 
482
406
  let encoder = JSONEncoder()
package/ios/Util.swift CHANGED
@@ -1,5 +1,5 @@
1
1
  import Foundation
2
-
2
+ import VirtuosoClientDownloadEngine
3
3
 
4
4
  extension String {
5
5
  func getDictionary() -> [String:AnyObject]? {
@@ -147,3 +147,79 @@ func extractInteger(from string: String) -> Int {
147
147
  return 0
148
148
  }
149
149
 
150
+ // Process completed and pending assets using a shared function
151
+ func processAsset(_ va: VirtuosoAsset) -> OfflineCatalog {
152
+ var catalog = OfflineCatalog(id: "", isCompleted: false, isPaused: false, creationTime: "")
153
+ let thumbnail = va.findAllAncillaries(withTag: "thumbnail").first
154
+ let show = va.findAllAncillaries(withTag: "show").first
155
+ let thumbnails = Thumbnails(
156
+ thumbnail: thumbnail?.fileDownloadURL ?? "",
157
+ show: show?.fileDownloadURL ?? ""
158
+ )
159
+
160
+ let expiryDate = va.expiryDate
161
+ let effectiveExpiryDate = va.effectiveExpiryDate
162
+ let isReproduced = va.firstPlayDateTime
163
+ let creationDate = va.creationDateTime.toSeconds()
164
+ let firstPlayDate = va.firstPlayDateTime?.toSeconds()
165
+
166
+ var dataItem = DataItem(
167
+ title: va.userInfo?["title"] as? String,
168
+ seasonId: va.userInfo?["seasonId"] as? String,
169
+ seasonTitle: va.userInfo?["seasonTitle"] as? String,
170
+ duration: va.duration,
171
+ estimatedSize: Int(va.estimatedSize),
172
+ dataOffers: parseDataOffersInObject(anyElement: va.userInfo?["dataOffers"] as Any),
173
+ expiryAfterPlay: timeIntervalToString(va.expiryAfterPlay),
174
+ expiryAfterDownload: timeIntervalToString(va.expiryAfterDownload),
175
+ isExpired: va.isExpired,
176
+ inForcedExpire: va.inForcedExpire,
177
+ isReproduced: isReproduced != nil,
178
+ mediaId: va.userInfo?["mediaId"] as? String,
179
+ vpid: va.userInfo?["vpid"] as? String
180
+ )
181
+
182
+ if effectiveExpiryDate != nil {
183
+ dataItem.effectiveExpiryDate = isReproduced != nil ? va.expiryAfterPlay : va.expiryAfterDownload
184
+ }
185
+
186
+ if expiryDate != nil {
187
+ dataItem.expiryDate = va.expiryDate
188
+ }
189
+
190
+ if va.isExpired {
191
+ va.delete()
192
+ } else {
193
+ catalog = OfflineCatalog(
194
+ id: getAssetId(asset: va), // Change vpid to assetId
195
+ title: va.description,
196
+ data: dataItem,
197
+ thumbnails: thumbnails,
198
+ isCompleted: va.downloadCompleteDateTime != nil ? true : false,
199
+ isPaused: va.isPaused,
200
+ percentage: Float(va.fractionComplete),
201
+ creationTime: isReproduced != nil ? firstPlayDate : creationDate
202
+ )
203
+ }
204
+ return catalog
205
+ }
206
+
207
+ func timeIntervalToString(_ timeInterval: TimeInterval?) -> String {
208
+ let formatter = DateComponentsFormatter()
209
+ formatter.allowedUnits = [.hour, .minute, .second]
210
+ formatter.unitsStyle = .positional
211
+ formatter.zeroFormattingBehavior = .pad
212
+ guard let interval = timeInterval else {
213
+ return "00:00:00"
214
+ }
215
+ return formatter.string(from: interval) ?? "00:00:00"
216
+ }
217
+
218
+ func getAssetId(asset: VirtuosoAsset) -> String {
219
+ if let mediaId = asset.userInfo?["mediaId"] as? String {
220
+ return mediaId
221
+ } else {
222
+ return asset.assetID
223
+ }
224
+ }
225
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeoffmedia/react-native-penthera",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -165,4 +165,4 @@
165
165
  "dependencies": {
166
166
  "zustand": "^4.4.0"
167
167
  }
168
- }
168
+ }