mi-parser
v0.1.1
Published
A CLI tool to parse MediaInfo output
Maintainers
Readme
MediaInfo Parser
A TypeScript library and CLI tool to parse MediaInfo output from text files and display the information in various formats.
Features
- Parse MediaInfo text output into structured data
- Multiple output formats: formatted text, YAML, or summary view
- Support for all MediaInfo tracks: General, Video, Audio, Text/Subtitles, and Chapters
- YAML output option for structured data
- Human-readable formatting for file sizes, durations, and bitrates
- Standalone library - use the parser in your own projects
Library Usage
Installation
# npm
npm install mi-parser
# pnpm
pnpm add mi-parser
# yarn
yarn add mi-parserBasic Usage
import { parseMediaInfo } from 'mi-parser';
const mediaInfoText = `
General
Complete name : /path/to/video.mp4
Format : MPEG-4
File size : 1.50 GiB
Duration : 1 h 45 min 30 s
Video
Format : AVC
Width : 1 920 pixels
Height : 1 080 pixels
Frame rate : 23.976 FPS
`;
const result = parseMediaInfo(mediaInfoText);
console.log(result.general.completeName); // "/path/to/video.mp4"
console.log(result.general.fileSize); // 1610612736 (bytes)
console.log(result.video[0].width); // 1920
console.log(result.video[0].height); // 1080TypeScript Interfaces
import { MediaInfo, GeneralTrack, VideoTrack, AudioTrack, TextTrack, Chapter } from 'mi-parser';
// All interfaces are fully typed for excellent IDE support
const mediaInfo: MediaInfo = parseMediaInfo(text);Available Types
MediaInfo- Main interface containing all tracksGeneralTrack- File metadata and general informationVideoTrack- Video stream informationAudioTrack- Audio stream informationTextTrack- Subtitle/text stream informationChapter- Chapter/menu information
CLI Usage
Installation
- Install dependencies:
pnpm install- Build the project:
pnpm run buildBasic usage:
pnpm start <mediainfo-file.txt>Using development mode (no build required):
pnpm run dev <mediainfo-file.txt>Command line options:
--yamlor-y: Output as YAML--output <file>or-o <file>: Output to file (only works with --yaml)--summaryor-s: Show only summary information--help: Show help information
Examples:
# Display formatted output
pnpm start sample.txt
# Show summary only
pnpm start sample.txt --summary
# Output as YAML to console
pnpm start sample.txt --yaml
# Output as YAML to file
pnpm start sample.txt --yaml --output mediainfo.yamlSample MediaInfo Output
To test the parser, create a text file with MediaInfo output like this:
General
Unique ID : 12345
Complete name : /path/to/video.mp4
Format : MPEG-4
File size : 1.50 GiB
Duration : 1 h 45 min 30 s
Video
ID : 1
Format : AVC
Width : 1 920 pixels
Height : 1 080 pixels
Frame rate : 23.976 FPS
Audio
ID : 2
Format : AAC
Channel(s) : 2 channels
Sampling rate : 48.0 kHzDevelopment
pnpm run dev <file>: Run CLI in development mode with tsxpnpm run build: Compile TypeScript to JavaScriptpnpm run test: Build and run the compiled version
Publishing
This project uses GitHub Actions for automated releases:
Setup
- Add
NPM_TOKENto your GitHub repository secrets:- Go to npmjs.com → Account → Access Tokens
- Create an "Automation" token
- Add it as
NPM_TOKENin your GitHub repo settings → Secrets
Release Process
- Update
CHANGELOG.mdwith new version details - Commit changes:
git commit -am "Release v1.x.x" - Create and push a version tag:
git tag v1.x.x && git push origin v1.x.x - GitHub Actions will automatically:
- Run tests on multiple Node.js versions
- Build the project
- Create a GitHub release with changelog notes
- Publish to npm registry
- Publish to GitHub Package Registry
Manual Publishing
pnpm run build
pnpm publish --access publicProject Structure
mediainfo.ts: Core parser library - use this in your projectsmain.ts: CLI interface and formatting logicpackage.json: Project configuration and dependenciestsconfig.json: TypeScript compilation settings
Parsed Data Format
The parser converts MediaInfo text into structured objects with proper TypeScript typing:
- File sizes are converted to bytes (number)
- Durations are converted to milliseconds (number)
- Bit rates are converted to bits per second (number)
- Sampling rates are converted to Hz (number)
- Dates are converted to Date objects
- Boolean flags (Default/Forced) are converted to boolean values
