djay-connect
v2.0.1
Published
Library to read djay Pro's MediaLibrary.db and emit track change events
Readme
djay-connect
Library to read djay Pro's MediaLibrary.db and emit track change events.
Supports djay Pro on macOS and Windows.
Installation
npm install djay-connectUsage
import { DjayConnect } from 'djay-connect';
const djay = new DjayConnect({
pollIntervalMs: 2000,
});
djay.on('ready', (info) => {
console.log(`Watching: ${info.databasePath}`);
});
djay.on('track', (payload) => {
const { track } = payload;
console.log(`Now playing: ${track.artist} - ${track.title} [deck ${track.deckNumber}]`);
if (track.filePath) console.log(`File: ${track.filePath}`);
if (track.originSourceID) console.log(`Source: ${track.originSourceID}`);
});
djay.on('error', (err) => {
console.error('Error:', err);
});
djay.start();
// Later...
djay.stop();API
new DjayConnect(options?)
pollIntervalMs— Polling interval in milliseconds (minimum 2000, default 2000)databasePath— Custom path toMediaLibrary.db. If omitted, uses the default per-platform path.logger— Logger instance implementing{ trace, debug, info, warn, error }
Track fields
Every track event carries a DjayNowPlayingTrack with:
title,artist,duration,deckNumber,startTimeuuid,sessionUUID— history entry and session identifierstitleID— 32-hex id joining the track to location and analysis tablesoriginSourceID— where the track came from (explorer,music,beatport,soundcloud,spotify,tidal,beatsource,applemusic)isrc— International Standard Recording Code (streaming tracks)filePath— absolute path for local files, decoded from djay's URL-encodedfile://URIssourceURIs— raw source URIs; may contain multiple entries when a track is available on more than one streaming service
Events
ready— Emitted when monitoring startspoll— Emitted on each poll cycletrack— Emitted when a new track is detectederror— Emitted on errors
Detection utilities
getDefaultDjayInstallPath()— Returns the default djay Pro data foldergetDefaultDatabasePath()— Returns the defaultMediaLibrary.dbpath for the current platformgetDefaultDatabasePaths()— Returns all candidate paths for the current platformdetectDjayInstallation()— Checks whether djay Pro is installed
Source helpers
DJAY_SOURCES— Catalog of every knownoriginSourceIDwithkind,label, and URI scheme prefixisStreamingSource(id)— True if the given source is a streaming servicetoNowPlayingStreamingSource(id)— Maps a djay Pro source to the nowplaying streaming enum
TSAF parser (advanced)
parseHistorySessionItem(blob)— Parse a rawhistorySessionItemsBLOBextractTitleID(blob)— Extract the nestedADCMediaItemTitleIDextractSourceURIs(blob)— Extract all source URIs from a location blobextractString,extractDouble,extractDate— Low-level field readers
See docs/FORMAT.md for the full on-disk format reference.
License
MIT
