@soga/mediainfo 1.0.2 → 1.3.6
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/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e,t=Object.create,a=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,i=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,n=(e,t,i,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let u of s(t))o.call(e,u)||u===i||a(e,u,{get:()=>t[u],enumerable:!(n=r(t,u))||n.enumerable});return e},u={};((e,t)=>{for(var r in t)a(e,r,{get:t[r],enumerable:!0})})(u,{parseMediaInfo:()=>h,parseMediaRaw:()=>f}),module.exports=(e=u,n(a({},"__esModule",{value:!0}),e));var c=require("fs-extra"),l=((e,r,s)=>(s=null!=e?t(i(e)):{},n(!r&&e&&e.__esModule?s:a(s,"default",{value:e,enumerable:!0}),e)))(require("mediainfo.js")),d=class extends Error{rewritable;message;stack;details;cause;constructor(e){super(e.message),this.rewritable=e.rewritable||!1,this.message=e.message||"",this.details=e.detail?[e.detail]:this.message?[this.message]:[],this.stack=e.stack,this.name="DError",this.cause=e.cause}toJson(){return{name:this.name,message:this.message,stack:this.stack,details:this.details,cause:this.cause}}toString(){const e=this.toJson();return JSON.stringify(e,null,2)}},m=(e,t={})=>{if(e instanceof d){if(!e.rewritable)return e;t.message&&(e.message=t.message);const a=t.detail||t.message;return a&&(e.details=e.details?[a,...e.details]:[a]),t.stack&&(e.stack=`${t.stack}\n${e.stack}`),t.cause?e.cause=t.cause:e.cause&&(e.cause=e.cause),e}{const a=new d({message:e.message,stack:e.stack});t.message&&(a.message=t.message);const r=t.detail||t.message;return r&&(a.details=a.details?[r,...a.details]:[r]),t.stack&&(a.stack=`${t.stack}\n${a.stack}`),t.cause?a.cause=t.cause:e.cause&&(a.cause=e.cause),void 0!==t.rewritable&&(a.rewritable=t.rewritable),a}};async function f(e){try{const t=await(0,l.default)({format:"JSON"}),a="string"==typeof e?[e]:e;let r=0;const s=[];for await(const[e,t]of a.entries()){const{size:a}=await(0,c.stat)(t);s.push({index:e,start:r,end:r+a-1,size:a,file_path:t}),r+=a}const i=async(e,t)=>{if(!e)return new Uint8Array(0);const a=t,r=t+e-1,i=s.find(e=>e.start<=a&&e.end>=a),o=s.find(e=>e.start<=r&&e.end>=r);if(!i||!o)return new Uint8Array(0);const n=[];if(i.index===o.index)n.push({index:i.index,file_path:i.file_path,from:a-i.start,to:r-i.start});else{n.push({index:i.index,file_path:i.file_path,from:a-i.start,to:i.end});for(let e=i.index+1;e<o.index;e++){const t=s[e];t&&n.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}n.push({index:o.index,file_path:o.file_path,from:0,to:r-o.start})}const u=[];for await(const e of n){const{file_path:t,from:a,to:r}=e,s=(0,c.createReadStream)(t,{start:a,end:r});for await(const e of s)u.push(e);s.close()}return Buffer.concat(u)},o=await t.analyzeData(()=>r,i);try{return JSON.parse(o)}catch(e){const t=o.replace(',"":{}]}]}',',"":{}}]}');return JSON.parse(t)}}catch(t){throw console.log("statck:"),console.log(t.stack),m(t,{message:"Failed to parse raw mediainfo",detail:`Failed to parse raw mediainfo: ${e}`})}}async function h(e){try{const t=await f(e),a=t.media.track,r={audio:[],video:[],text:[],general:{}};let s=0,i=0,o=0;return a.forEach(e=>{const t=e["@type"];"Audio"===t?r.audio.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:s++,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate),sample_rate:Number(e.SamplingRate),duration:Number(e.Duration),channels:Number(e.Channels),lossless:"Lossless"===e.Compression_Mode}):"Text"===t?r.text.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:o++,duration:Number(e.Duration),title:e.Title||e.Language,language:e.Language}):"Video"===t?r.video.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:i++,width:Number(e.Width),height:Number(e.Height),profile:e.Format_Profile,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate)?Math.round(Number(e.FrameRate)):0,duration:Number(e.Duration),bitdepth:Number(e.BitDepth),format_profile:e.Format_Profile,format_tier:e.Format_Tier}):"General"===t&&(r.general={audioCount:Number(e.AudioCount),textCount:Number(e.TextCount)||0,videoCount:Number(e.VideoCount),fileSize:Number(e.FileSize),title:e.Title||"",duration:Number(e.Duration),codec:e.Format},!r.general.duration&&e.extra?.duration&&(r.general.duration=Number(e.extra.duration)))}),r}catch(t){throw m(t,{message:"Failed to parse mediainfo",detail:`Failed to parse mediainfo: ${e}`})}}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createReadStream as e,stat as t}from"fs-extra";import a from"mediainfo.js";
|
|
1
|
+
import{createReadStream as e,stat as t}from"fs-extra";import a from"mediainfo.js";var s=class extends Error{rewritable;message;stack;details;cause;constructor(e){super(e.message),this.rewritable=e.rewritable||!1,this.message=e.message||"",this.details=e.detail?[e.detail]:this.message?[this.message]:[],this.stack=e.stack,this.name="DError",this.cause=e.cause}toJson(){return{name:this.name,message:this.message,stack:this.stack,details:this.details,cause:this.cause}}toString(){const e=this.toJson();return JSON.stringify(e,null,2)}},r=(e,t={})=>{if(e instanceof s){if(!e.rewritable)return e;t.message&&(e.message=t.message);const a=t.detail||t.message;return a&&(e.details=e.details?[a,...e.details]:[a]),t.stack&&(e.stack=`${t.stack}\n${e.stack}`),t.cause?e.cause=t.cause:e.cause&&(e.cause=e.cause),e}{const a=new s({message:e.message,stack:e.stack});t.message&&(a.message=t.message);const r=t.detail||t.message;return r&&(a.details=a.details?[r,...a.details]:[r]),t.stack&&(a.stack=`${t.stack}\n${a.stack}`),t.cause?a.cause=t.cause:e.cause&&(a.cause=e.cause),void 0!==t.rewritable&&(a.rewritable=t.rewritable),a}};async function i(s){try{const r=await a({format:"JSON"}),i="string"==typeof s?[s]:s;let o=0;const n=[];for await(const[e,a]of i.entries()){const{size:s}=await t(a);n.push({index:e,start:o,end:o+s-1,size:s,file_path:a}),o+=s}const u=async(t,a)=>{if(!t)return new Uint8Array(0);const s=a,r=a+t-1,i=n.find(e=>e.start<=s&&e.end>=s),o=n.find(e=>e.start<=r&&e.end>=r);if(!i||!o)return new Uint8Array(0);const u=[];if(i.index===o.index)u.push({index:i.index,file_path:i.file_path,from:s-i.start,to:r-i.start});else{u.push({index:i.index,file_path:i.file_path,from:s-i.start,to:i.end});for(let e=i.index+1;e<o.index;e++){const t=n[e];t&&u.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}u.push({index:o.index,file_path:o.file_path,from:0,to:r-o.start})}const c=[];for await(const t of u){const{file_path:a,from:s,to:r}=t,i=e(a,{start:s,end:r});for await(const e of i)c.push(e);i.close()}return Buffer.concat(c)},c=await r.analyzeData(()=>o,u);try{return JSON.parse(c)}catch(e){const t=c.replace(',"":{}]}]}',',"":{}}]}');return JSON.parse(t)}}catch(e){throw console.log("statck:"),console.log(e.stack),r(e,{message:"Failed to parse raw mediainfo",detail:`Failed to parse raw mediainfo: ${s}`})}}async function o(e){try{const t=await i(e),a=t.media.track,s={audio:[],video:[],text:[],general:{}};let r=0,o=0,n=0;return a.forEach(e=>{const t=e["@type"];"Audio"===t?s.audio.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:r++,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate),sample_rate:Number(e.SamplingRate),duration:Number(e.Duration),channels:Number(e.Channels),lossless:"Lossless"===e.Compression_Mode}):"Text"===t?s.text.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:n++,duration:Number(e.Duration),title:e.Title||e.Language,language:e.Language}):"Video"===t?s.video.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:o++,width:Number(e.Width),height:Number(e.Height),profile:e.Format_Profile,bitrate:Number(e.BitRate),framerate:Number(e.FrameRate)?Math.round(Number(e.FrameRate)):0,duration:Number(e.Duration),bitdepth:Number(e.BitDepth),format_profile:e.Format_Profile,format_tier:e.Format_Tier}):"General"===t&&(s.general={audioCount:Number(e.AudioCount),textCount:Number(e.TextCount)||0,videoCount:Number(e.VideoCount),fileSize:Number(e.FileSize),title:e.Title||"",duration:Number(e.Duration),codec:e.Format},!s.general.duration&&e.extra?.duration&&(s.general.duration=Number(e.extra.duration)))}),s}catch(t){throw r(t,{message:"Failed to parse mediainfo",detail:`Failed to parse mediainfo: ${e}`})}}export{o as parseMediaInfo,i as parseMediaRaw};
|
package/package.json
CHANGED
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.6",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"demo": "tsx ./demo/demo.ts",
|
|
12
|
-
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts --minify terser",
|
|
13
|
-
"prepublishOnly": "npm run build"
|
|
14
|
-
},
|
|
15
10
|
"files": [
|
|
16
11
|
"dist"
|
|
17
12
|
],
|
|
@@ -20,15 +15,20 @@
|
|
|
20
15
|
"license": "ISC",
|
|
21
16
|
"description": "",
|
|
22
17
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
18
|
+
"fs-extra": "^11.3.2",
|
|
19
|
+
"mediainfo.js": "^0.3.5",
|
|
20
|
+
"@soga/error": "^1.3.6"
|
|
26
21
|
},
|
|
27
22
|
"devDependencies": {
|
|
28
23
|
"@types/fs-extra": "^11.0.4",
|
|
29
24
|
"rimraf": "^6.0.1",
|
|
30
25
|
"terser": "^5.43.1",
|
|
31
26
|
"tsup": "^8.5.0",
|
|
32
|
-
"tsx": "^4.20.
|
|
27
|
+
"tsx": "^4.20.6",
|
|
28
|
+
"@soga/typescript-config": "^1.3.6"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"demo": "tsx ./demo/demo.ts",
|
|
32
|
+
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts --minify terser"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|