Giter VIP home page Giter VIP logo

mp3-parser's Introduction

mp3-parser Build

A library for parsing headers of mp3 files, including MPEG header frame data and any Xing/Lame tags.

Features

  • Runs on Clojure and ClojureScript
  • Parse and report existence of an ID3V2 header
  • Skip any ID3V2 tag, if it exists
  • Parse and report MPEG header frame data
  • Parse and report existence of a Xing tag in the header frame
  • Parse and report Xing tag data, if it exists
  • Parse and report existence of a Lame tag in the header frame
  • Parse and report Lame tag data, if it exists
  • Calculate the CRC-16 of the Lame tag data, compare it with the stored CRC-16, and report if it is valid or not

Status

Alpha

Dependencies

Tested with Clojure 1.10.1, ClojureScript 1.10.520

Usage

Clojure deps.edn with Git

Add the following to :deps in the deps.edn file for the project:

digital-dj-tools/mp3-parser {:git/url "https://github.com/digital-dj-tools/mp3-parser.git"
                             :sha "515c4838dc0b1eadebe64ec5f0a9ed827cfed54c"}

Clojure deps.edn with Clojars

TODO

Sync API Example

Go to the project directory and start a REPL:

clj

Enter the following code:

(require
 '[mp3-parser.app :as app])

(def mp3-file
  "test-resources/lame-mp3-cbr-stereo-44100khz-192kbps-id3v2.mp3")

(app/parse mp3-file)

The following result should be printed:

{:id3v2-offset 42005
 :mpeg-valid? true
 :mpeg {:mp3-parser.mpeg/bit-rate 192000
        :mp3-parser.mpeg/frame-length 626.0
        :mp3-parser.mpeg/has-padding? false
        :mp3-parser.mpeg/header [-1 -5 -80 100]
        :mp3-parser.mpeg/layer 3
        :mp3-parser.mpeg/num-channels 2
        :mp3-parser.mpeg/num-samples 1152
        :mp3-parser.mpeg/sample-rate 44100
        :mp3-parser.mpeg/version 1}
 :xing-tag? true
 :xing {:mp3-parser.xing/keyword "Info", 
        :mp3-parser.xing/offset 36}
 :lame-tag? true
 :lame {:mp3-parser.lame/crc-valid? true 
        :mp3-parser.lame/encoder "LAME3.99r", 
        :mp3-parser.lame/revision 0}}

Async API Example

TODO

API Docs

TODO

Developers

Running the Tests

clj -Adev:test
clj -Adev:test-cljs

Starting a CIDER-compatible NREPL Server

clj -Adev:nrepl-server

License

Copyright © 2018 Digital DJ Tools

Released under the MIT license.

mp3-parser's People

Contributors

alza-bitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mindsocket

mp3-parser's Issues

How to use natively as import in JS/TS NodeJS?

Hi! Can somebody please provide guidance on how to use main parse function from app.cljc in order to get result as regular JS object?

Something like this (expected result):

{
 "id3v2-offset": 0,
 "mpeg": {
  "version": 1,
  "has-padding?": false,
  "sample-rate": 48000,
  "num-channels": 2,
  "bit-rate": 320000,
  "frame-length": 960,
  "num-samples": 1152,
  "header": [
   -1,
   -5,
   -28,
   68
  ],
  "layer": 3
 },
 "mpeg-valid?": true,
 "xing-tag?": false
}

So far I used this code in order to build for NodeJS, but then I cannot really import & use the parse function within my codebase:
clj -M -m cljs.main --target node --output-to main.js -c mp3-parser.app

Or, to be specific, I did manage to import the function, but then it provides very convoluted result.
How I imported:

var path = require('path');
try {
	require('source-map-support').install();
} catch (err) {}
require('../goog/bootstrap/nodejs');
require('../cljs_deps');
goog.global.CLOSURE_UNCOMPILED_DEFINES = { 'cljs.core._STAR_target_STAR_': 'nodejs' };
goog.require('cljs.nodejscli');
goog.require('cljs.core');
goog.require('mp3_parser.app');

How I used the import:
const result = mp3_parser.app.parse(mp3FilePath);

Result that I got:

{
	tree: {
		key: {
			ns: null,
			name: 'mpeg',
			fqn: 'mpeg',
			_hash: -1021588107,
			cljs$lang$protocol_mask$partition0$: 2153775105,
			cljs$lang$protocol_mask$partition1$: 4096,
		},
		val: {
			meta: null,
			cnt: 9,
			root: {
				edit: null,
				bitmap: 436559874,
				arr: [
					{
						ns: 'mp3-parser.mpeg',
						name: 'version',
						fqn: 'mp3-parser.mpeg/version',
						_hash: 81018049,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					1,
					null,
					{
						edit: {},
						bitmap: 1048704,
						arr: [
							{
								ns: 'mp3-parser.mpeg',
								name: 'has-padding?',
								fqn: 'mp3-parser.mpeg/has-padding?',
								_hash: -367653651,
								cljs$lang$protocol_mask$partition0$: 2153775105,
								cljs$lang$protocol_mask$partition1$: 4096,
							},
							false,
							{
								ns: 'mp3-parser.mpeg',
								name: 'sample-rate',
								fqn: 'mp3-parser.mpeg/sample-rate',
								_hash: -978390387,
								cljs$lang$protocol_mask$partition0$: 2153775105,
								cljs$lang$protocol_mask$partition1$: 4096,
							},
							48000,
							null,
							null,
							null,
							null,
						],
						cljs$lang$protocol_mask$partition1$: 131072,
						cljs$lang$protocol_mask$partition0$: 0,
					},
					{
						ns: 'mp3-parser.mpeg',
						name: 'num-channels',
						fqn: 'mp3-parser.mpeg/num-channels',
						_hash: -1961528722,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					2,
					{
						ns: 'mp3-parser.mpeg',
						name: 'bit-rate',
						fqn: 'mp3-parser.mpeg/bit-rate',
						_hash: 561072816,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					320000,
					{
						ns: 'mp3-parser.mpeg',
						name: 'frame-length',
						fqn: 'mp3-parser.mpeg/frame-length',
						_hash: 407983954,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					960,
					{
						ns: 'mp3-parser.mpeg',
						name: 'num-samples',
						fqn: 'mp3-parser.mpeg/num-samples',
						_hash: -345617735,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					1152,
					{
						ns: 'mp3-parser.mpeg',
						name: 'header',
						fqn: 'mp3-parser.mpeg/header',
						_hash: 214035803,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					{
						meta: null,
						cnt: 4,
						shift: 5,
						root: {
							edit: null,
							arr: [
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
								null,
							],
						},
						tail: [-1, -5, -28, 68],
						__hash: null,
						cljs$lang$protocol_mask$partition0$: 167666463,
						cljs$lang$protocol_mask$partition1$: 139268,
					},
					{
						ns: 'mp3-parser.mpeg',
						name: 'layer',
						fqn: 'mp3-parser.mpeg/layer',
						_hash: -1558617700,
						cljs$lang$protocol_mask$partition0$: 2153775105,
						cljs$lang$protocol_mask$partition1$: 4096,
					},
					3,
				],
				cljs$lang$protocol_mask$partition1$: 131072,
				cljs$lang$protocol_mask$partition0$: 0,
			},
			has_nil_QMARK_: false,
			nil_val: null,
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 16123663,
			cljs$lang$protocol_mask$partition1$: 139268,
		},
		left: {
			key: {
				ns: null,
				name: 'id3v2-offset',
				fqn: 'id3v2-offset',
				_hash: -44725623,
				cljs$lang$protocol_mask$partition0$: 2153775105,
				cljs$lang$protocol_mask$partition1$: 4096,
			},
			val: 0,
			left: null,
			right: null,
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 166619935,
			cljs$lang$protocol_mask$partition1$: 0,
		},
		right: {
			key: {
				ns: null,
				name: 'mpeg-valid?',
				fqn: 'mpeg-valid?',
				_hash: -328426969,
				cljs$lang$protocol_mask$partition0$: 2153775105,
				cljs$lang$protocol_mask$partition1$: 4096,
			},
			val: true,
			left: null,
			right: {
				key: {
					ns: null,
					name: 'xing-tag?',
					fqn: 'xing-tag?',
					_hash: -1695319398,
					cljs$lang$protocol_mask$partition0$: 2153775105,
					cljs$lang$protocol_mask$partition1$: 4096,
				},
				val: false,
				left: null,
				right: null,
				__hash: null,
				cljs$lang$protocol_mask$partition0$: 166619935,
				cljs$lang$protocol_mask$partition1$: 0,
			},
			__hash: null,
			cljs$lang$protocol_mask$partition0$: 166619935,
			cljs$lang$protocol_mask$partition1$: 0,
		},
		__hash: null,
		cljs$lang$protocol_mask$partition0$: 166619935,
		cljs$lang$protocol_mask$partition1$: 0,
	},
	cnt: 4,
	meta: null,
	__hash: null,
	cljs$lang$protocol_mask$partition0$: 418776847,
	cljs$lang$protocol_mask$partition1$: 8192,
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.