react-native-compressor 1.4.0 → 1.5.2

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.
package/README.md CHANGED
@@ -1,9 +1,17 @@
1
1
  ### Would you like to support me?
2
2
 
3
+ <div align="center">
4
+ <a href="https://github.com/nomi9995?tab=followers">
5
+ <img src="https://img.shields.io/github/followers/nomi9995?label=Follow%20%40nomi9995&style=social" />
6
+ </a>
7
+ </br>
3
8
  <a href="https://www.buymeacoffee.com/numan.dev" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
9
+ </div>
4
10
 
5
11
  ---
6
12
 
13
+
14
+
7
15
  # react-native-compressor
8
16
 
9
17
  <!-- Title -->
@@ -26,6 +34,34 @@
26
34
 
27
35
  **If you find this package useful hit the star** 🌟
28
36
 
37
+ # Table of Contents
38
+ <details>
39
+ <summary>Open Table of Contents</summary>
40
+
41
+ * [Installation](#installation)
42
+ + [For React Native](#react-native)
43
+ - [For React Native<0.65](#for-react-native065)
44
+ - [For React Native 0.65 or greater](#for-react-native-065-or-greater)
45
+ + [Managed Expo](#managed-expo)
46
+ * [Usage](#usage)
47
+ + [Image](#image)
48
+ * [Automatic Image Compression Like Whatsapp](#automatic-image-compression-like-whatsapp)
49
+ * [Manual Image Compression](#manual-image-compression)
50
+ * [ImageCompressor API Docs](#imagecompressor)
51
+ + [Video](#video)
52
+ * [Automatic Video Compression Like Whatsapp](#automatic-video-compression-like-whatsapp)
53
+ * [Manual Video Compression](#manual-video-compression)
54
+ * [Cancel Video Compression](#cancel-video-compression)
55
+ * [Video Api Docs](#video-1)
56
+ + [Audio](#audio)
57
+ + [Background Upload](#background-upload)
58
+ - [Other Utilities](#api)
59
+ * [Background Upload](#background-upload-1)
60
+ * [Get Metadata Of Video](#get-metadata-of-video)
61
+ * [Get Real Path](#get-real-path)
62
+ * [Get Temp file Path](#get-temp-file-path)
63
+ </details>
64
+
29
65
  ## Installation
30
66
 
31
67
  ### React Native
@@ -33,7 +69,7 @@
33
69
  #### For React Native<0.65
34
70
 
35
71
  ```sh
36
- yarn add react-native-compressor@0.5.15
72
+ yarn add react-native-compressor@rnlessthan65
37
73
  ```
38
74
 
39
75
  #### For React Native 0.65 or greater
@@ -111,7 +147,7 @@ react-native link react-native-compressor
111
147
 
112
148
  ### Image
113
149
 
114
- ##### For Like Whatsapp Image Compression
150
+ ##### Automatic Image Compression Like Whatsapp
115
151
 
116
152
  ```js
117
153
  import { Image } from 'react-native-compressor';
@@ -123,7 +159,7 @@ const result = await Image.compress('file://path_of_file/image.jpg', {
123
159
 
124
160
  [Here is this package comparison of images compression with WhatsApp](https://docs.google.com/spreadsheets/d/13TsnC1c7NOC9aCjzN6wkKurJQPeGRNwDhWsQOkXQskU/edit?usp=sharing)
125
161
 
126
- ##### For manual Compression
162
+ ##### Manual Image Compression
127
163
 
128
164
  ```js
129
165
  import { Image } from 'react-native-compressor';
@@ -136,7 +172,7 @@ const result = await Image.compress('file://path_of_file/image.jpg', {
136
172
 
137
173
  ### Video
138
174
 
139
- ##### For Like Whatsapp Video Compression
175
+ ##### Automatic Video Compression Like Whatsapp
140
176
 
141
177
  ```js
142
178
  import { Video } from 'react-native-compressor';
@@ -158,7 +194,7 @@ const result = await Video.compress(
158
194
 
159
195
  [Here is this package comparison of video compression with WhatsApp](https://docs.google.com/spreadsheets/d/13TsnC1c7NOC9aCjzN6wkKurJQPeGRNwDhWsQOkXQskU/edit#gid=1055406534)
160
196
 
161
- ##### For manual Compression
197
+ ##### Manual Video Compression
162
198
 
163
199
  ```js
164
200
  import { Video } from 'react-native-compressor';
@@ -334,29 +370,57 @@ type FileSystemUploadOptions = (
334
370
  };
335
371
  ```
336
372
 
337
- # Get Real Path
338
- if you want to convert
373
+ ### Get Metadata Of Video
374
+
375
+ if you want to get metadata of video than you can use this function
376
+
377
+ ```js
378
+ import { getVideoMetaData } from 'react-native-compressor';
379
+
380
+ const metaData = await getVideoMetaData(filePath);
381
+ ```
382
+
383
+ ```
384
+ {
385
+ "duration": "6",
386
+ "extension": "mp4",
387
+ "height": "1080",
388
+ "size": "16940.0",
389
+ "width": "1920"
390
+ }
391
+ ```
392
+
393
+ - ###### `getVideoMetaData(path: string)`
394
+
395
+ ### Get Real Path
396
+
397
+ if you want to convert
339
398
 
340
399
  - `content://` to `file:///` for android
341
400
  - `ph://` to `file:///` for IOS
342
401
 
343
402
  the you can you `getRealPath` function like this
403
+
344
404
  ```js
345
405
  import { getRealPath } from 'react-native-compressor';
346
406
 
347
- const realPath = await getRealPath(fileUri, 'video'); // file://file_path.extension
407
+ const realPath = await getRealPath(fileUri, 'video'); // file://file_path.extension
348
408
  ```
409
+
349
410
  - ###### `getRealPath(path: string, type: string = 'video'|'image')`
350
411
 
351
- # Get Temp file Path
412
+ ### Get Temp file Path
413
+
352
414
  if you wanna make random file path in cache folder then you can use this method like this
353
415
 
354
416
  ```js
355
- import { getRealPath } from 'react-native-compressor';
417
+ import { generateFilePath } from 'react-native-compressor';
356
418
 
357
- const realPath = await generateFilePath(fileUri, 'video'); // file://file_path.extension
419
+ const randomFilePathForSaveFile = await generateFilePath('mp4'); // file://file_path.mp4
358
420
  ```
359
421
 
422
+ - ##### `generateFilePath(fileextension: string)`
423
+
360
424
  ## Contributing
361
425
 
362
426
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
@@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
9
9
  import androidx.annotation.Nullable;
10
10
  import androidx.annotation.RequiresApi;
11
11
 
12
+ import com.facebook.react.bridge.Arguments;
12
13
  import com.facebook.react.bridge.Promise;
13
14
  import com.facebook.react.bridge.ReactApplicationContext;
14
15
  import com.facebook.react.bridge.ReactContext;
@@ -23,9 +24,12 @@ import com.reactnativecompressor.Image.utils.ImageCompressorOptions;
23
24
  import com.reactnativecompressor.Utils.Utils;
24
25
  import com.reactnativecompressor.Video.VideoCompressorHelper;
25
26
  import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
27
+ import static com.reactnativecompressor.Utils.Utils.getRealPath;
26
28
 
27
29
  import com.reactnativecompressor.Audio.AudioCompressor;
28
30
 
31
+ import java.io.File;
32
+
29
33
  @ReactModule(name = CompressorModule.NAME)
30
34
  public class CompressorModule extends ReactContextBaseJavaModule {
31
35
  public static final String NAME = "Compressor";
@@ -119,4 +123,32 @@ public class CompressorModule extends ReactContextBaseJavaModule {
119
123
  promise.reject(e);
120
124
  }
121
125
  }
126
+
127
+ @ReactMethod
128
+ public void getVideoMetaData(String filePath, Promise promise) {
129
+ try {
130
+ filePath=Utils.getRealPath(filePath,reactContext);
131
+ Uri uri= Uri.parse(filePath);
132
+ String srcPath = uri.getPath();
133
+ MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
134
+ metaRetriever.setDataSource(srcPath);
135
+ File file=new File(srcPath);
136
+ float sizeInKBs = file.length()/1024;
137
+ int actualHeight =Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
138
+ int actualWidth = Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
139
+ long duration = Long.parseLong(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
140
+ String extension = filePath.substring(filePath.lastIndexOf(".")+1);
141
+
142
+ WritableMap params = Arguments.createMap();
143
+ params.putString("size", String.valueOf(sizeInKBs));
144
+ params.putString("width", String.valueOf(actualWidth));
145
+ params.putString("height", String.valueOf(actualHeight));
146
+ params.putString("duration", String.valueOf(duration/1000));
147
+ params.putString("extension", extension);
148
+
149
+ promise.resolve(params);
150
+ } catch (Exception e) {
151
+ promise.reject(e);
152
+ }
153
+ }
122
154
  }
package/ios/Compressor.m CHANGED
@@ -9,6 +9,30 @@
9
9
  #define AlAsset_Library_Scheme @"assets-library"
10
10
  @implementation Compressor
11
11
  AVAssetWriter *assetWriter=nil;
12
+ static NSArray *metadatas;
13
+
14
+ - (NSArray *)metadatas
15
+ {
16
+ if (!metadatas) {
17
+ metadatas = @[
18
+ @"albumName",
19
+ @"artist",
20
+ @"comment",
21
+ @"copyrights",
22
+ @"creationDate",
23
+ @"date",
24
+ @"encodedby",
25
+ @"genre",
26
+ @"language",
27
+ @"location",
28
+ @"lastModifiedDate",
29
+ @"performer",
30
+ @"publisher",
31
+ @"title"
32
+ ];
33
+ }
34
+ return metadatas;
35
+ }
12
36
 
13
37
  RCT_EXPORT_MODULE()
14
38
 
@@ -242,6 +266,63 @@ RCT_EXPORT_METHOD(
242
266
  }
243
267
  }
244
268
 
269
+
270
+ RCT_EXPORT_METHOD(
271
+ getVideoMetaData: (NSString*) filePath
272
+ resolver: (RCTPromiseResolveBlock) resolve
273
+ rejecter: (RCTPromiseRejectBlock) reject) {
274
+ @try {
275
+ [ImageCompressor getAbsoluteVideoPath:filePath completionHandler:^(NSString *absoluteImagePath) {
276
+ if([absoluteImagePath containsString:@"file://"])
277
+ {
278
+ absoluteImagePath=[absoluteImagePath stringByReplacingOccurrencesOfString:@"file://"
279
+ withString:@""];
280
+ }
281
+ NSFileManager *fileManager = [NSFileManager defaultManager];
282
+
283
+ BOOL isDir;
284
+ if (![fileManager fileExistsAtPath:absoluteImagePath isDirectory:&isDir] || isDir){
285
+ NSError *err = [NSError errorWithDomain:@"file not found" code:-15 userInfo:nil];
286
+ reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
287
+ return;
288
+ }
289
+ NSDictionary *attrs = [fileManager attributesOfItemAtPath: absoluteImagePath error: NULL];
290
+ UInt32 fileSize = [attrs fileSize];
291
+ NSString *fileSizeString = [@(fileSize) stringValue];
292
+
293
+ NSMutableDictionary *result = [NSMutableDictionary new];
294
+ NSDictionary *assetOptions = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
295
+ AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:absoluteImagePath] options:assetOptions];\
296
+ AVAssetTrack *avAsset = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
297
+ CGSize size = [avAsset naturalSize];
298
+ NSString *extension = [[absoluteImagePath lastPathComponent] pathExtension];
299
+ CMTime time = [asset duration];
300
+ int seconds = ceil(time.value/time.timescale);
301
+ [result setObject:[NSString stringWithFormat: @"%.2f", size.width] forKey:@"width"];
302
+ [result setObject:[NSString stringWithFormat: @"%.2f", size.height] forKey:@"height"];
303
+ [result setObject:extension forKey:@"extension"];
304
+ [result setObject:fileSizeString forKey:@"size"];
305
+ [result setObject:[@(seconds) stringValue] forKey:@"duration"];
306
+ NSArray *keys = [NSArray arrayWithObjects:@"commonMetadata", nil];
307
+ [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
308
+ // string keys
309
+ for (NSString *key in [self metadatas]) {
310
+ NSArray *items = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata
311
+ withKey:key
312
+ keySpace:AVMetadataKeySpaceCommon];
313
+ for (AVMetadataItem *item in items) {
314
+ [result setObject:item.value forKey:key];
315
+ }
316
+ }
317
+ resolve(result);
318
+ }];
319
+ }];
320
+ }
321
+ @catch (NSException *exception) {
322
+ reject(exception.name, exception.reason, nil);
323
+ }
324
+ }
325
+
245
326
  @end
246
327
 
247
328
 
@@ -362,10 +362,11 @@
362
362
  return path;
363
363
  }
364
364
 
365
- /// for vide
365
+ /// for video
366
366
 
367
367
  +(void)getAbsoluteVideoPath:(NSString *)videoPath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
368
368
  {
369
+
369
370
  if (![videoPath containsString:@"ph://"]) {
370
371
  completionHandler(videoPath);
371
372
  return;
@@ -400,17 +400,8 @@ func makeValidUri(filePath: String) -> String {
400
400
  }
401
401
 
402
402
  func getVideoTrack(asset: AVAsset) -> AVAssetTrack {
403
- var videoTrackIndex: Int = 0;
404
- let trackLength = asset.tracks.count;
405
- if(trackLength==2)
406
- {
407
- if(asset.tracks[0].mediaType.rawValue=="soun")
408
- {
409
- videoTrackIndex=1;
410
- }
411
- }
412
- let track = asset.tracks[videoTrackIndex];
413
- return track;
403
+ let tracks = asset.tracks(withMediaType: AVMediaType.video)
404
+ return tracks[0];
414
405
  }
415
406
 
416
407
  }
@@ -57,6 +57,12 @@ Object.defineProperty(exports, "getRealPath", {
57
57
  return _utils.getRealPath;
58
58
  }
59
59
  });
60
+ Object.defineProperty(exports, "getVideoMetaData", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _utils.getVideoMetaData;
64
+ }
65
+ });
60
66
  exports.default = void 0;
61
67
 
62
68
  var _Video = _interopRequireWildcard(require("./Video"));
@@ -81,7 +87,8 @@ var _default = {
81
87
  getDetails: _utils.getDetails,
82
88
  uuidv4: _utils.uuidv4,
83
89
  generateFilePath: _utils.generateFilePath,
84
- getRealPath: _utils.getRealPath
90
+ getRealPath: _utils.getRealPath,
91
+ getVideoMetaData: _utils.getVideoMetaData
85
92
  };
86
93
  exports.default = _default;
87
94
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails","uuidv4","generateFilePath","getRealPath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAce;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA,iBALa;AAMbC,EAAAA,MAAM,EAANA,aANa;AAObC,EAAAA,gBAAgB,EAAhBA,uBAPa;AAQbC,EAAAA,WAAW,EAAXA;AARa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails","uuidv4","generateFilePath","getRealPath","getVideoMetaData"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAqBe;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA,iBALa;AAMbC,EAAAA,MAAM,EAANA,aANa;AAObC,EAAAA,gBAAgB,EAAhBA,uBAPa;AAQbC,EAAAA,WAAW,EAAXA,kBARa;AASbC,EAAAA,gBAAgB,EAAhBA;AATa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport {\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n} from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.uuidv4 = exports.checkUrlAndOptions = exports.getDetails = exports.getRealPath = exports.generateFilePath = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
6
+ exports.uuidv4 = exports.checkUrlAndOptions = exports.getDetails = exports.getVideoMetaData = exports.getRealPath = exports.generateFilePath = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
7
7
 
8
8
  var _reactNative = require("react-native");
9
9
 
@@ -31,12 +31,18 @@ const generateFilePath = extension => {
31
31
 
32
32
  exports.generateFilePath = generateFilePath;
33
33
 
34
- const getRealPath = (path, type = '') => {
34
+ const getRealPath = (path, type = 'video') => {
35
35
  return Compressor.getRealPath(path, type);
36
36
  };
37
37
 
38
38
  exports.getRealPath = getRealPath;
39
39
 
40
+ const getVideoMetaData = path => {
41
+ return Compressor.getVideoMetaData(path);
42
+ };
43
+
44
+ exports.getVideoMetaData = getVideoMetaData;
45
+
40
46
  const isValidUrl = url => /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
41
47
 
42
48
  const getFullFilename = path => {
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Compressor","NativeModules","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":";;;;;;;AACA;;AADA;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX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CAAC9C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,gBAAgB,CAAC,KAAD,CAAvC;AACA6C,MAAAA,aAAa,CAAC9C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,cAAc,KAAKiD,SAAnB,IAAgCjD,cAAc,KAAK,IAAvD,EAA6D;AAC3D8C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAO+C,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOkD,aAAP;AACD;AACF,CAzCM;;;;AA2CA,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (path: string, type: string = '') => {\n return Compressor.getRealPath(path, type);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Compressor","NativeModules","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","getVideoMetaData","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":";;;;;;;AACA;;AADA;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC,EAAAA,cA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,QAAIA,cAAc,KAAKkD,SAAnB,IAAgClD,cAAc,KAAK,IAAvD,EAA6D;AAC3D+C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC9C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAOgD,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC9C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOmD,aAAP;AACD;AACF,CAzCM;;;;AA2CA,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (\n path: string,\n type: 'video' | 'imaage' = 'video'\n) => {\n return Compressor.getRealPath(path, type);\n};\n\nexport const getVideoMetaData: any = (path: string) => {\n return Compressor.getVideoMetaData(path);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
@@ -1,9 +1,9 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
4
+ import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData } from './utils';
5
5
  export { Video, Audio, Image, backgroundUpload //type
6
- , VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath };
6
+ , VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData };
7
7
  export default {
8
8
  Video,
9
9
  Audio,
@@ -12,6 +12,7 @@ export default {
12
12
  getDetails,
13
13
  uuidv4,
14
14
  generateFilePath,
15
- getRealPath
15
+ getRealPath,
16
+ getVideoMetaData
16
17
  };
17
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails","uuidv4","generateFilePath","getRealPath"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,EAAqBC,MAArB,EAA6BC,gBAA7B,EAA+CC,WAA/C,QAAkE,SAAlE;AAEA,SACER,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF,EAQEC,MARF,EASEC,gBATF,EAUEC,WAVF;AAYA,eAAe;AACbR,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA,UALa;AAMbC,EAAAA,MANa;AAObC,EAAAA,gBAPa;AAQbC,EAAAA;AARa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails","uuidv4","generateFilePath","getRealPath","getVideoMetaData"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SACEC,UADF,EAEEC,MAFF,EAGEC,gBAHF,EAIEC,WAJF,EAKEC,gBALF,QAMO,SANP;AAQA,SACET,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF,EAQEC,MARF,EASEC,gBATF,EAUEC,WAVF,EAWEC,gBAXF;AAaA,eAAe;AACbT,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA,UALa;AAMbC,EAAAA,MANa;AAObC,EAAAA,gBAPa;AAQbC,EAAAA,WARa;AASbC,EAAAA;AATa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport {\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n} from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\n"]}
@@ -17,9 +17,12 @@ export const generateFilePath = extension => {
17
17
  Compressor.generateFilePath(extension).then(result => resolve('file://' + result)).catch(error => reject(error));
18
18
  });
19
19
  };
20
- export const getRealPath = (path, type = '') => {
20
+ export const getRealPath = (path, type = 'video') => {
21
21
  return Compressor.getRealPath(path, type);
22
22
  };
23
+ export const getVideoMetaData = path => {
24
+ return Compressor.getVideoMetaData(path);
25
+ };
23
26
 
24
27
  const isValidUrl = url => /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
25
28
 
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":"AAAA;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAh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Aa,CAAC9C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,gBAAgB,CAAC,KAAD,CAAvC;AACA6C,MAAAA,aAAa,CAAC9C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,cAAc,KAAKiD,SAAnB,IAAgCjD,cAAc,KAAK,IAAvD,EAA6D;AAC3D8C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAO+C,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOkD,aAAP;AACD;AACF,CAzCM;AA2CP,OAAO,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (path: string, type: string = '') => {\n return Compressor.getRealPath(path, type);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","getVideoMetaData","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":"AAAA;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcA,OAAO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO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,aAAa,CAAC/C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,cAAc,KAAKkD,SAAnB,IAAgClD,cAAc,KAAK,IAAvD,EAA6D;AAC3D+C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC9C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAOgD,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC9C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOmD,aAAP;AACD;AACF,CAzCM;AA2CP,OAAO,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (\n path: string,\n type: 'video' | 'imaage' = 'video'\n) => {\n return Compressor.getRealPath(path, type);\n};\n\nexport const getVideoMetaData: any = (path: string) => {\n return Compressor.getVideoMetaData(path);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
@@ -1,8 +1,8 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
5
- export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, };
4
+ import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData } from './utils';
5
+ export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, };
6
6
  declare const _default: {
7
7
  Video: VideoCompressorType;
8
8
  Audio: import("./utils").AudioType;
@@ -14,5 +14,6 @@ declare const _default: {
14
14
  uuidv4: () => string;
15
15
  generateFilePath: any;
16
16
  getRealPath: any;
17
+ getVideoMetaData: any;
17
18
  };
18
19
  export default _default;
@@ -16,6 +16,7 @@ export declare type AudioType = {
16
16
  };
17
17
  export declare const generateFilePath: any;
18
18
  export declare const getRealPath: any;
19
+ export declare const getVideoMetaData: any;
19
20
  export declare const getDetails: (mediaFullPath: string, extesnion?: 'mp3' | 'mp4') => Promise<any | null>;
20
21
  export declare const checkUrlAndOptions: (url: string, options: audioCompresssionType) => Promise<defaultResultType>;
21
22
  export declare const uuidv4: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "1.4.0",
3
+ "version": "1.5.2",
4
4
  "description": "This library compress image, video and audio",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.tsx CHANGED
@@ -1,7 +1,13 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
4
+ import {
5
+ getDetails,
6
+ uuidv4,
7
+ generateFilePath,
8
+ getRealPath,
9
+ getVideoMetaData,
10
+ } from './utils';
5
11
 
6
12
  export {
7
13
  Video,
@@ -14,6 +20,7 @@ export {
14
20
  uuidv4,
15
21
  generateFilePath,
16
22
  getRealPath,
23
+ getVideoMetaData,
17
24
  };
18
25
  export default {
19
26
  Video,
@@ -24,4 +31,5 @@ export default {
24
31
  uuidv4,
25
32
  generateFilePath,
26
33
  getRealPath,
34
+ getVideoMetaData,
27
35
  };
@@ -38,10 +38,17 @@ export const generateFilePath: any = (extension: string) => {
38
38
  });
39
39
  };
40
40
 
41
- export const getRealPath: any = (path: string, type: string = '') => {
41
+ export const getRealPath: any = (
42
+ path: string,
43
+ type: 'video' | 'imaage' = 'video'
44
+ ) => {
42
45
  return Compressor.getRealPath(path, type);
43
46
  };
44
47
 
48
+ export const getVideoMetaData: any = (path: string) => {
49
+ return Compressor.getVideoMetaData(path);
50
+ };
51
+
45
52
  const isValidUrl = (url: string) =>
46
53
  /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
47
54
 
File without changes