@soga/mediainfo 0.0.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.
- package/README.md +5 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +1 -0
- package/dist/mediainfo.d.ts +6 -0
- package/dist/mediainfo.js +1 -0
- package/dist/mediainfo.types.d.ts +52 -0
- package/dist/mediainfo.types.js +1 -0
- package/package.json +49 -0
package/README.md
ADDED
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./mediainfo"),exports),__exportStar(require("./mediainfo.types"),exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TracksMap } from './mediainfo.types';
|
|
2
|
+
export declare function parseMediaRaw(media_path: string): Promise<any>;
|
|
3
|
+
export declare function parseMediaInfo(media_path: string): Promise<TracksMap>;
|
|
4
|
+
export declare const isSupportVideo: (format: string) => boolean;
|
|
5
|
+
export declare const isAdaptAudio: (codec: string) => boolean;
|
|
6
|
+
export declare const isHighAudio: (codec: string) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isHighAudio=exports.isAdaptAudio=exports.isSupportVideo=void 0,exports.parseMediaRaw=parseMediaRaw,exports.parseMediaInfo=parseMediaInfo;const fs_1=require("fs"),promises_1=require("fs/promises"),mediainfo_js_1=__importDefault(require("mediainfo.js"));async function parseMediaRaw(e){const t=await(0,mediainfo_js_1.default)({format:"JSON"}),a="string"==typeof e?[e]:e;let r=0;const i=[];for await(const[e,t]of a.entries()){const a=(await(0,promises_1.stat)(t)).size;i.push({index:e,start:r,end:r+a-1,size:a,file_path:t}),r+=a}const o=await t.analyzeData((()=>r),(async(e,t)=>{if(!e)return new Uint8Array(0);const a=t,r=t+e-1,o=i.find((e=>e.start<=a&&e.end>=a)),s=i.find((e=>e.start<=r&&e.end>=r));if(!o||!s)return new Uint8Array(0);const n=[];if(o.index===s.index)n.push({index:o.index,file_path:o.file_path,from:a-o.start,to:r-o.start});else{n.push({index:o.index,file_path:o.file_path,from:a-o.start,to:o.end});for(let e=o.index+1;e<s.index;e++){const t=i[e];n.push({index:t.index,file_path:t.file_path,from:0,to:t.size-1})}n.push({index:s.index,file_path:s.file_path,from:0,to:r-s.start})}const u=[];for await(const e of n){const{file_path:t,from:a,to:r}=e,i=(0,fs_1.createReadStream)(t,{start:a,end:r});for await(const e of i)u.push(e);i.close()}return Buffer.concat(u)}));try{return JSON.parse(o)}catch(e){const t=o.replace('"Menu","":{}]}]}','"Menu","":{}}]}');return JSON.parse(t)}}async function parseMediaInfo(e){const t=(await parseMediaRaw(e)).media.track,a={audio:[],video:[],text:[],general:{}};let r=0,i=0,o=0;return t.forEach((e=>{const t=e["@type"];"Audio"===t?a.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?a.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?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)):void 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}const isSupportVideo=e=>["avc","h264","avc1","hevc","h265"].includes(e);exports.isSupportVideo=isSupportVideo;const isAdaptAudio=e=>["aac","mp3"].includes(e);exports.isAdaptAudio=isAdaptAudio;const isHighAudio=e=>["flac"].includes(e);exports.isHighAudio=isHighAudio;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type GeneralInfo = {
|
|
2
|
+
audioCount: number;
|
|
3
|
+
videoCount: number;
|
|
4
|
+
textCount: number;
|
|
5
|
+
fileSize: number;
|
|
6
|
+
codec: string;
|
|
7
|
+
title: string;
|
|
8
|
+
duration: number;
|
|
9
|
+
extra?: {
|
|
10
|
+
duration: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type AudioTrackInfo = {
|
|
14
|
+
is_default: boolean;
|
|
15
|
+
order: number;
|
|
16
|
+
codec: string;
|
|
17
|
+
bitrate: number;
|
|
18
|
+
framerate: number;
|
|
19
|
+
sample_rate: number;
|
|
20
|
+
channels: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
lossless: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type VideoTrackInfo = {
|
|
25
|
+
is_default: boolean;
|
|
26
|
+
order: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
codec: string;
|
|
30
|
+
profile: string;
|
|
31
|
+
framerate: number;
|
|
32
|
+
bitrate: number;
|
|
33
|
+
duration: number;
|
|
34
|
+
bitdepth: number;
|
|
35
|
+
format_profile: string;
|
|
36
|
+
format_tier: string;
|
|
37
|
+
};
|
|
38
|
+
export type TextTrackInfo = {
|
|
39
|
+
is_default: boolean;
|
|
40
|
+
codec: string;
|
|
41
|
+
order: number;
|
|
42
|
+
duration: number;
|
|
43
|
+
language?: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
is_vtt?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type TracksMap = {
|
|
48
|
+
general?: GeneralInfo;
|
|
49
|
+
audio?: AudioTrackInfo[];
|
|
50
|
+
video?: VideoTrackInfo[];
|
|
51
|
+
text?: TextTrackInfo[];
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soga/mediainfo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "dist/main.js",
|
|
9
|
+
"types": "dist/main.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rimraf dist && tsc && ts-node ./scripts/minify",
|
|
15
|
+
"minify": "ts-node ./scripts/minify",
|
|
16
|
+
"demo": "ts-node ./demo/demo.ts",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"dev": "ts-node ./src/main.ts",
|
|
19
|
+
"lint": "eslint . --ext .ts",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/fs-extra": "^11.0.4",
|
|
24
|
+
"@types/glob": "^8.1.0",
|
|
25
|
+
"@types/jest": "^29.5.4",
|
|
26
|
+
"@types/node": "^20.8.7",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
28
|
+
"@typescript-eslint/parser": "^6.4.1",
|
|
29
|
+
"eslint": "^8.47.0",
|
|
30
|
+
"eslint-config-prettier": "^9.0.0",
|
|
31
|
+
"eslint-plugin-jest": "^27.2.3",
|
|
32
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
33
|
+
"glob": "^10.3.3",
|
|
34
|
+
"jest": "^29.6.3",
|
|
35
|
+
"prettier": "^3.0.2",
|
|
36
|
+
"terser": "^5.19.2",
|
|
37
|
+
"ts-jest": "^29.1.1",
|
|
38
|
+
"ts-node": "^10.9.1",
|
|
39
|
+
"typeorm": "^0.3.20",
|
|
40
|
+
"typescript": "^5.1.6"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [],
|
|
43
|
+
"author": "",
|
|
44
|
+
"license": "ISC",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"fs-extra": "^11.2.0",
|
|
47
|
+
"mediainfo.js": "^0.3.4"
|
|
48
|
+
}
|
|
49
|
+
}
|