@soga/mediainfo 0.5.0 → 1.0.0
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 -200
- package/dist/index.mjs +1 -164
- package/package.json +11 -8
package/dist/index.js
CHANGED
|
@@ -1,200 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
parseMediaInfo: () => parseMediaInfo,
|
|
34
|
-
parseMediaRaw: () => parseMediaRaw
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
var import_fs_extra = require("fs-extra");
|
|
38
|
-
var import_promises = require("fs/promises");
|
|
39
|
-
var import_mediainfo = __toESM(require("mediainfo.js"));
|
|
40
|
-
async function parseMediaRaw(media_path) {
|
|
41
|
-
const mediainfo = await (0, import_mediainfo.default)({
|
|
42
|
-
format: "JSON"
|
|
43
|
-
});
|
|
44
|
-
const fileList = typeof media_path === "string" ? [media_path] : media_path;
|
|
45
|
-
let total = 0;
|
|
46
|
-
const arr = [];
|
|
47
|
-
for await (const [index, file_path] of fileList.entries()) {
|
|
48
|
-
const { size } = await (0, import_promises.stat)(file_path);
|
|
49
|
-
arr.push({
|
|
50
|
-
index,
|
|
51
|
-
start: total,
|
|
52
|
-
end: total + size - 1,
|
|
53
|
-
size,
|
|
54
|
-
file_path
|
|
55
|
-
});
|
|
56
|
-
total += size;
|
|
57
|
-
}
|
|
58
|
-
const getBuffer = async (size, offset) => {
|
|
59
|
-
if (!size) {
|
|
60
|
-
return new Uint8Array(0);
|
|
61
|
-
}
|
|
62
|
-
const start = offset;
|
|
63
|
-
const end = offset + size - 1;
|
|
64
|
-
const first = arr.find((item) => item.start <= start && item.end >= start);
|
|
65
|
-
const last = arr.find((item) => item.start <= end && item.end >= end);
|
|
66
|
-
if (!first || !last) {
|
|
67
|
-
return new Uint8Array(0);
|
|
68
|
-
}
|
|
69
|
-
const list = [];
|
|
70
|
-
if (first.index === last.index) {
|
|
71
|
-
list.push({
|
|
72
|
-
index: first.index,
|
|
73
|
-
file_path: first.file_path,
|
|
74
|
-
from: start - first.start,
|
|
75
|
-
to: end - first.start
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
list.push({
|
|
79
|
-
index: first.index,
|
|
80
|
-
file_path: first.file_path,
|
|
81
|
-
from: start - first.start,
|
|
82
|
-
to: first.end
|
|
83
|
-
});
|
|
84
|
-
for (let i = first.index + 1; i < last.index; i++) {
|
|
85
|
-
const item = arr[i];
|
|
86
|
-
if (item) {
|
|
87
|
-
list.push({
|
|
88
|
-
index: item.index,
|
|
89
|
-
file_path: item.file_path,
|
|
90
|
-
from: 0,
|
|
91
|
-
to: item.size - 1
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
list.push({
|
|
96
|
-
index: last.index,
|
|
97
|
-
file_path: last.file_path,
|
|
98
|
-
from: 0,
|
|
99
|
-
to: end - last.start
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const buffers = [];
|
|
103
|
-
for await (const item of list) {
|
|
104
|
-
const { file_path, from, to } = item;
|
|
105
|
-
const stream = (0, import_fs_extra.createReadStream)(file_path, { start: from, end: to });
|
|
106
|
-
for await (const data2 of stream) {
|
|
107
|
-
buffers.push(data2);
|
|
108
|
-
}
|
|
109
|
-
stream.close();
|
|
110
|
-
}
|
|
111
|
-
const buffer = Buffer.concat(buffers);
|
|
112
|
-
return buffer;
|
|
113
|
-
};
|
|
114
|
-
const data = await mediainfo.analyzeData(() => total, getBuffer);
|
|
115
|
-
try {
|
|
116
|
-
const rawJson = JSON.parse(data);
|
|
117
|
-
return rawJson;
|
|
118
|
-
} catch (err) {
|
|
119
|
-
const text = data.replace(',"":{}]}]}', ',"":{}}]}');
|
|
120
|
-
const rawJson = JSON.parse(text);
|
|
121
|
-
return rawJson;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function parseMediaInfo(media_path) {
|
|
125
|
-
const raw = await parseMediaRaw(media_path);
|
|
126
|
-
const rawMediainfo = raw.media;
|
|
127
|
-
const list = rawMediainfo.track;
|
|
128
|
-
const info = {
|
|
129
|
-
audio: [],
|
|
130
|
-
video: [],
|
|
131
|
-
text: [],
|
|
132
|
-
general: {}
|
|
133
|
-
};
|
|
134
|
-
let audioOrder = 0;
|
|
135
|
-
let videoOrder = 0;
|
|
136
|
-
let textOrder = 0;
|
|
137
|
-
list.forEach((item) => {
|
|
138
|
-
const type = item["@type"];
|
|
139
|
-
if (type === "Audio") {
|
|
140
|
-
info.audio.push({
|
|
141
|
-
is_default: item.Default === "Yes",
|
|
142
|
-
codec: item.Format.toLowerCase(),
|
|
143
|
-
// order: Number(item.StreamOrder),
|
|
144
|
-
order: audioOrder++,
|
|
145
|
-
// size: Number(item.StreamSize),
|
|
146
|
-
bitrate: Number(item.BitRate),
|
|
147
|
-
framerate: Number(item.FrameRate),
|
|
148
|
-
sample_rate: Number(item.SamplingRate),
|
|
149
|
-
duration: Number(item.Duration),
|
|
150
|
-
channels: Number(item.Channels),
|
|
151
|
-
lossless: item.Compression_Mode === "Lossless"
|
|
152
|
-
});
|
|
153
|
-
} else if (type === "Text") {
|
|
154
|
-
info.text.push({
|
|
155
|
-
is_default: item.Default === "Yes",
|
|
156
|
-
codec: item.Format.toLowerCase(),
|
|
157
|
-
// order: Number(item.StreamOrder),
|
|
158
|
-
order: textOrder++,
|
|
159
|
-
duration: Number(item.Duration),
|
|
160
|
-
title: item.Title || item.Language,
|
|
161
|
-
language: item.Language
|
|
162
|
-
});
|
|
163
|
-
} else if (type === "Video") {
|
|
164
|
-
info.video.push({
|
|
165
|
-
is_default: item.Default === "Yes",
|
|
166
|
-
codec: item.Format.toLowerCase(),
|
|
167
|
-
order: videoOrder++,
|
|
168
|
-
width: Number(item.Width),
|
|
169
|
-
height: Number(item.Height),
|
|
170
|
-
profile: item.Format_Profile,
|
|
171
|
-
bitrate: Number(item.BitRate),
|
|
172
|
-
framerate: Number(item.FrameRate) ? Math.round(Number(item.FrameRate)) : 0,
|
|
173
|
-
// sample_rate: Number(item.SamplingRate),
|
|
174
|
-
duration: Number(item.Duration),
|
|
175
|
-
bitdepth: Number(item.BitDepth),
|
|
176
|
-
format_profile: item.Format_Profile,
|
|
177
|
-
format_tier: item.Format_Tier
|
|
178
|
-
});
|
|
179
|
-
} else if (type === "General") {
|
|
180
|
-
info.general = {
|
|
181
|
-
audioCount: Number(item.AudioCount),
|
|
182
|
-
textCount: Number(item.TextCount) || 0,
|
|
183
|
-
videoCount: Number(item.VideoCount),
|
|
184
|
-
fileSize: Number(item.FileSize),
|
|
185
|
-
title: item.Title || "",
|
|
186
|
-
duration: Number(item.Duration),
|
|
187
|
-
codec: item.Format
|
|
188
|
-
};
|
|
189
|
-
if (!info.general.duration && item.extra?.duration) {
|
|
190
|
-
info.general.duration = Number(item.extra.duration);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return info;
|
|
195
|
-
}
|
|
196
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
197
|
-
0 && (module.exports = {
|
|
198
|
-
parseMediaInfo,
|
|
199
|
-
parseMediaRaw
|
|
200
|
-
});
|
|
1
|
+
"use strict";var e,t=Object.create,r=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,s=(e,t,i,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let u of o(t))n.call(e,u)||u===i||r(e,u,{get:()=>t[u],enumerable:!(s=a(t,u))||s.enumerable});return e},u={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(u,{parseMediaInfo:()=>m,parseMediaRaw:()=>c}),module.exports=(e=u,s(r({},"__esModule",{value:!0}),e));var d=require("fs-extra"),l=((e,a,o)=>(o=null!=e?t(i(e)):{},s(!a&&e&&e.__esModule?o:r(o,"default",{value:e,enumerable:!0}),e)))(require("mediainfo.js")),f=require("@soga/error");async function c(e){try{const t=await(0,l.default)({format:"JSON"}),r="string"==typeof e?[e]:e;let a=0;const o=[];for await(const[e,t]of r.entries()){const{size:r}=await(0,d.stat)(t);o.push({index:e,start:a,end:a+r-1,size:r,file_path:t}),a+=r}const i=async(e,t)=>{if(!e)return new Uint8Array(0);const r=t,a=t+e-1,i=o.find(e=>e.start<=r&&e.end>=r),n=o.find(e=>e.start<=a&&e.end>=a);if(!i||!n)return new Uint8Array(0);const s=[];if(i.index===n.index)s.push({index:i.index,file_path:i.file_path,from:r-i.start,to:a-i.start});else{s.push({index:i.index,file_path:i.file_path,from:r-i.start,to:i.end});for(let e=i.index+1;e<n.index;e++){const t=o[e];t&&s.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}s.push({index:n.index,file_path:n.file_path,from:0,to:a-n.start})}const u=[];for await(const e of s){const{file_path:t,from:r,to:a}=e,o=(0,d.createReadStream)(t,{start:r,end:a});for await(const e of o)u.push(e);o.close()}return Buffer.concat(u)},n=await t.analyzeData(()=>a,i);try{return JSON.parse(n)}catch(e){const t=n.replace(',"":{}]}]}',',"":{}}]}');return JSON.parse(t)}}catch(t){throw console.log("statck:"),console.log(t.stack),(0,f.buildDError)(t,{message:"Failed to parse raw mediainfo",detail:`Failed to parse raw mediainfo: ${e}`})}}async function m(e){try{const t=await c(e),r=t.media.track,a={audio:[],video:[],text:[],general:{}};let o=0,i=0,n=0;return r.forEach(e=>{const t=e["@type"];"Audio"===t?a.audio.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:o++,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?a.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?a.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&&(a.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},!a.general.duration&&e.extra?.duration&&(a.general.duration=Number(e.extra.duration)))}),a}catch(t){throw(0,f.buildDError)(t,{message:"Failed to parse mediainfo",detail:`Failed to parse mediainfo: ${e}`})}}
|
package/dist/index.mjs
CHANGED
|
@@ -1,164 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createReadStream } from "fs-extra";
|
|
3
|
-
import { stat } from "fs/promises";
|
|
4
|
-
import getMediainfo from "mediainfo.js";
|
|
5
|
-
async function parseMediaRaw(media_path) {
|
|
6
|
-
const mediainfo = await getMediainfo({
|
|
7
|
-
format: "JSON"
|
|
8
|
-
});
|
|
9
|
-
const fileList = typeof media_path === "string" ? [media_path] : media_path;
|
|
10
|
-
let total = 0;
|
|
11
|
-
const arr = [];
|
|
12
|
-
for await (const [index, file_path] of fileList.entries()) {
|
|
13
|
-
const { size } = await stat(file_path);
|
|
14
|
-
arr.push({
|
|
15
|
-
index,
|
|
16
|
-
start: total,
|
|
17
|
-
end: total + size - 1,
|
|
18
|
-
size,
|
|
19
|
-
file_path
|
|
20
|
-
});
|
|
21
|
-
total += size;
|
|
22
|
-
}
|
|
23
|
-
const getBuffer = async (size, offset) => {
|
|
24
|
-
if (!size) {
|
|
25
|
-
return new Uint8Array(0);
|
|
26
|
-
}
|
|
27
|
-
const start = offset;
|
|
28
|
-
const end = offset + size - 1;
|
|
29
|
-
const first = arr.find((item) => item.start <= start && item.end >= start);
|
|
30
|
-
const last = arr.find((item) => item.start <= end && item.end >= end);
|
|
31
|
-
if (!first || !last) {
|
|
32
|
-
return new Uint8Array(0);
|
|
33
|
-
}
|
|
34
|
-
const list = [];
|
|
35
|
-
if (first.index === last.index) {
|
|
36
|
-
list.push({
|
|
37
|
-
index: first.index,
|
|
38
|
-
file_path: first.file_path,
|
|
39
|
-
from: start - first.start,
|
|
40
|
-
to: end - first.start
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
list.push({
|
|
44
|
-
index: first.index,
|
|
45
|
-
file_path: first.file_path,
|
|
46
|
-
from: start - first.start,
|
|
47
|
-
to: first.end
|
|
48
|
-
});
|
|
49
|
-
for (let i = first.index + 1; i < last.index; i++) {
|
|
50
|
-
const item = arr[i];
|
|
51
|
-
if (item) {
|
|
52
|
-
list.push({
|
|
53
|
-
index: item.index,
|
|
54
|
-
file_path: item.file_path,
|
|
55
|
-
from: 0,
|
|
56
|
-
to: item.size - 1
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
list.push({
|
|
61
|
-
index: last.index,
|
|
62
|
-
file_path: last.file_path,
|
|
63
|
-
from: 0,
|
|
64
|
-
to: end - last.start
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const buffers = [];
|
|
68
|
-
for await (const item of list) {
|
|
69
|
-
const { file_path, from, to } = item;
|
|
70
|
-
const stream = createReadStream(file_path, { start: from, end: to });
|
|
71
|
-
for await (const data2 of stream) {
|
|
72
|
-
buffers.push(data2);
|
|
73
|
-
}
|
|
74
|
-
stream.close();
|
|
75
|
-
}
|
|
76
|
-
const buffer = Buffer.concat(buffers);
|
|
77
|
-
return buffer;
|
|
78
|
-
};
|
|
79
|
-
const data = await mediainfo.analyzeData(() => total, getBuffer);
|
|
80
|
-
try {
|
|
81
|
-
const rawJson = JSON.parse(data);
|
|
82
|
-
return rawJson;
|
|
83
|
-
} catch (err) {
|
|
84
|
-
const text = data.replace(',"":{}]}]}', ',"":{}}]}');
|
|
85
|
-
const rawJson = JSON.parse(text);
|
|
86
|
-
return rawJson;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async function parseMediaInfo(media_path) {
|
|
90
|
-
const raw = await parseMediaRaw(media_path);
|
|
91
|
-
const rawMediainfo = raw.media;
|
|
92
|
-
const list = rawMediainfo.track;
|
|
93
|
-
const info = {
|
|
94
|
-
audio: [],
|
|
95
|
-
video: [],
|
|
96
|
-
text: [],
|
|
97
|
-
general: {}
|
|
98
|
-
};
|
|
99
|
-
let audioOrder = 0;
|
|
100
|
-
let videoOrder = 0;
|
|
101
|
-
let textOrder = 0;
|
|
102
|
-
list.forEach((item) => {
|
|
103
|
-
const type = item["@type"];
|
|
104
|
-
if (type === "Audio") {
|
|
105
|
-
info.audio.push({
|
|
106
|
-
is_default: item.Default === "Yes",
|
|
107
|
-
codec: item.Format.toLowerCase(),
|
|
108
|
-
// order: Number(item.StreamOrder),
|
|
109
|
-
order: audioOrder++,
|
|
110
|
-
// size: Number(item.StreamSize),
|
|
111
|
-
bitrate: Number(item.BitRate),
|
|
112
|
-
framerate: Number(item.FrameRate),
|
|
113
|
-
sample_rate: Number(item.SamplingRate),
|
|
114
|
-
duration: Number(item.Duration),
|
|
115
|
-
channels: Number(item.Channels),
|
|
116
|
-
lossless: item.Compression_Mode === "Lossless"
|
|
117
|
-
});
|
|
118
|
-
} else if (type === "Text") {
|
|
119
|
-
info.text.push({
|
|
120
|
-
is_default: item.Default === "Yes",
|
|
121
|
-
codec: item.Format.toLowerCase(),
|
|
122
|
-
// order: Number(item.StreamOrder),
|
|
123
|
-
order: textOrder++,
|
|
124
|
-
duration: Number(item.Duration),
|
|
125
|
-
title: item.Title || item.Language,
|
|
126
|
-
language: item.Language
|
|
127
|
-
});
|
|
128
|
-
} else if (type === "Video") {
|
|
129
|
-
info.video.push({
|
|
130
|
-
is_default: item.Default === "Yes",
|
|
131
|
-
codec: item.Format.toLowerCase(),
|
|
132
|
-
order: videoOrder++,
|
|
133
|
-
width: Number(item.Width),
|
|
134
|
-
height: Number(item.Height),
|
|
135
|
-
profile: item.Format_Profile,
|
|
136
|
-
bitrate: Number(item.BitRate),
|
|
137
|
-
framerate: Number(item.FrameRate) ? Math.round(Number(item.FrameRate)) : 0,
|
|
138
|
-
// sample_rate: Number(item.SamplingRate),
|
|
139
|
-
duration: Number(item.Duration),
|
|
140
|
-
bitdepth: Number(item.BitDepth),
|
|
141
|
-
format_profile: item.Format_Profile,
|
|
142
|
-
format_tier: item.Format_Tier
|
|
143
|
-
});
|
|
144
|
-
} else if (type === "General") {
|
|
145
|
-
info.general = {
|
|
146
|
-
audioCount: Number(item.AudioCount),
|
|
147
|
-
textCount: Number(item.TextCount) || 0,
|
|
148
|
-
videoCount: Number(item.VideoCount),
|
|
149
|
-
fileSize: Number(item.FileSize),
|
|
150
|
-
title: item.Title || "",
|
|
151
|
-
duration: Number(item.Duration),
|
|
152
|
-
codec: item.Format
|
|
153
|
-
};
|
|
154
|
-
if (!info.general.duration && item.extra?.duration) {
|
|
155
|
-
info.general.duration = Number(item.extra.duration);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return info;
|
|
160
|
-
}
|
|
161
|
-
export {
|
|
162
|
-
parseMediaInfo,
|
|
163
|
-
parseMediaRaw
|
|
164
|
-
};
|
|
1
|
+
import{createReadStream as e,stat as t}from"fs-extra";import a from"mediainfo.js";import{buildDError as r}from"@soga/error";async function o(o){try{const r=await a({format:"JSON"}),i="string"==typeof o?[o]:o;let n=0;const s=[];for await(const[e,a]of i.entries()){const{size:r}=await t(a);s.push({index:e,start:n,end:n+r-1,size:r,file_path:a}),n+=r}const u=async(t,a)=>{if(!t)return new Uint8Array(0);const r=a,o=a+t-1,i=s.find(e=>e.start<=r&&e.end>=r),n=s.find(e=>e.start<=o&&e.end>=o);if(!i||!n)return new Uint8Array(0);const u=[];if(i.index===n.index)u.push({index:i.index,file_path:i.file_path,from:r-i.start,to:o-i.start});else{u.push({index:i.index,file_path:i.file_path,from:r-i.start,to:i.end});for(let e=i.index+1;e<n.index;e++){const t=s[e];t&&u.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}u.push({index:n.index,file_path:n.file_path,from:0,to:o-n.start})}const d=[];for await(const t of u){const{file_path:a,from:r,to:o}=t,i=e(a,{start:r,end:o});for await(const e of i)d.push(e);i.close()}return Buffer.concat(d)},d=await r.analyzeData(()=>n,u);try{return JSON.parse(d)}catch(e){const t=d.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: ${o}`})}}async function i(e){try{const t=await o(e),a=t.media.track,r={audio:[],video:[],text:[],general:{}};let i=0,n=0,s=0;return a.forEach(e=>{const t=e["@type"];"Audio"===t?r.audio.push({is_default:"Yes"===e.Default,codec:e.Format.toLowerCase(),order:i++,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:s++,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:n++,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 r(t,{message:"Failed to parse mediainfo",detail:`Failed to parse mediainfo: ${e}`})}}export{i as parseMediaInfo,o as parseMediaRaw};
|
package/package.json
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.0",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
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"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
@@ -19,13 +20,15 @@
|
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"description": "",
|
|
21
22
|
"dependencies": {
|
|
23
|
+
"@soga/error": "^1.0.6",
|
|
22
24
|
"fs-extra": "^11.3.0",
|
|
23
|
-
"mediainfo.js": "^0.3.5"
|
|
24
|
-
"tsup": "^8.5.0"
|
|
25
|
+
"mediainfo.js": "^0.3.5"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@types/fs-extra": "^11.0.4",
|
|
28
|
-
"rimraf": "^6.0.1"
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
"rimraf": "^6.0.1",
|
|
30
|
+
"terser": "^5.43.1",
|
|
31
|
+
"tsup": "^8.5.0",
|
|
32
|
+
"tsx": "^4.20.3"
|
|
33
|
+
}
|
|
31
34
|
}
|