npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@freik/media-utils

v0.19.4

Published

Utilities for dealing with media files in NodeJS/Electron

Downloads

215

Readme

media-utils

My general media utilities for audio encoding, decoding, and music metadata manipulation.

There are 3 top level components in this module: Encode, Decode, and Metadata. There are also aliases for those components, but I'm not going to worry about those.

Types

There are a number of Flow types exported by the modules. They're all exported directly from media-utils:

// This is a helper type used in a few places
type attributes = { [key: string]: string };

// This is the most simplistic strongly typed metadata you'll find
type SimpleMetadata = {
  artist: string;
  album: string;
  year?: string;
  track: string;
  title: string;
  compilation?: 'va' | 'ost';
};

// This is a more robust metadata type, meant to be used in,
// among other scenarios, situations where you're moving files around
type FullMetadata = {
  OriginalPath: string;
  Artist: string;
  Album: string;
  Year?: number;
  Track: number;
  Title: string;
  VAType?: 'va' | 'ost';
  MoreArtists?: Array<string>;
  Mix?: Array<string>;
  Disk?: number;
  DiskOf?: number;
};

// This is a general mechanism for describing how to extract
// various metadata components out of a file path
type regexPattern = {
  // This can be something like "soundtrack"
  // or "true/false" to simply indicate that it's
  // a compilation of works by various artists
  compilation?: string | boolean;
  // This is the regular expression to match
  rgx: RegExp;
  // These are the names of the metadata fields
  // and their corresponding RegExp capture numbers
  metadata: { [key: string]: number };
};

// A function type for metadata acquisition
type mdAcquire = (pathname: string) => ?SimpleMetadata;

// Same thing, but async...
type mdAcquireAsync = (pathname: string) => Promise<?SimpleMetadata>;

// A function type for decoding audio
type decoder = (inputFile: string, outputFile: string) => boolean;

// Ditto, async
type decoderAsync = (inputFile: string, outputFile: string) => Promise<boolean>;

// A function type for encoding audio
type encoder = (
  wavFile: string,
  outputFilename: string,
  options: ?attributes,
  attrs: ?attributes,
) => boolean;

// Ditto, async
type encoderAsync = (
  wavFile: string,
  outputFilename: string,
  options: ?attributes,
  attrs: ?attributes,
) => Promise<boolean>;

Metadata

Decode

Encode

These are functions that will encode an input audio file to the given format.

function m4a(wavFile, outputFilename, options, attrs): encoder;
function m4aAsync(wavFile, outputFilename, options, attrs): encoderAsync;

Wrappers around the faac encoder for encoding to m4a/aac audio. They only take wav audio files as input. Other input types will result in failure.

function flac(wavFile, outputFilename, options, attrs): encoder;
function flacAsync(wavFile, outputFilename, options, attrs): encoderAsync;

Wrappers around the flac command line encoder, with the same constraint as the faac encoder: inputs much be wav files.

function ffmpeg(inputFile, outputFilename, options, attrs): encoder;
function ffmpegAsync(inputFile, outputFilename, options, attrs): encoderAsync;

Wrappers around ffmpeg. Given that it's wrapping such a flexible tool, you could use this to do video transcoding as well, but I don't really encourage that right now. These are the most flexible encoders, as FFmpeg does an excellent job of metadata translation between types. There's no constrain (generally) on the input audio type. FFmpeg will just do it's transcoding magic.