A simple Node.js (TypeScript) library to parse metadata from Shairport Sync.
This library reads the XML-like metadata stream from standard input, parses it, and emits structured data objects as an RxJS Observable. It is designed to be used in a pipeline with shairport-sync.
This program was originally created by the Gemini CLI, with reference to the C implementation of shairport-sync-metadata-reader.
- Parses
shairport-syncmetadata from a standard input stream. - Handles multi-line XML items and Base64 encoded data.
- Provides a clean, easy-to-use RxJS
Observableinterface. - Lightweight and has only one dependency (
rxjs).
Once published to npm:
npm install @minoruta/parse-shairportFor now, install directly from GitHub:
npm install git+https://github.com/minoruta/parse-shairport.gitCreate a script (e.g., my-player.js) to import and use the parser.
// my-player.ts
import { parseMetadata, Metadata } from '@minoruta/parse-shairport';
console.log('Metadata parser is running, waiting for data from stdin...');
parseMetadata().subscribe({
next: (metadata: Metadata) => {
// Now you can use the structured metadata object
console.log(metadata);
// Example: Display track information
if (metadata.type === 'artist') {
console.log(`--> Artist: ${metadata.payload}`);
}
if (metadata.type === 'title') {
console.log(`--> Title: ${metadata.payload}`);
}
},
error: (err) => {
// Errors can occur due to:
// - Invalid XML format in the metadata stream
// - Unexpected data encoding issues
// - stdin stream interruption
console.error('A critical error occurred in the metadata stream:', err);
},
complete: () => {
console.log('The metadata stream has ended.');
},
});To make this work with shairport-sync, you need to configure shairport-sync to output its metadata to standard output and then pipe it to your Node.js script.
ts-node my-player.ts < /tmp/shairport-sync-metadataor
shairport-sync --metadata-pipename=/dev/stdout | ts-node my-player.tsThis is the main function of the library. It takes no arguments.
- Returns: An
Observablethat emitsMetadataobjects.- It emits a
nextnotification for each piece of metadata parsed fromprocess.stdin. - It emits an
errornotification if there is an error reading the stream. - It emits a
completenotification when thestdinstream is closed.
- It emits a
The Metadata object emitted by the Observable has the following structure:
interface Metadata {
type: MetadataType;
payload: string;
}
// Currently supported metadata types
// Note: Additional types may be added in future versions
type MetadataType = 'album' | 'title' | 'artist' | 'session-begin' | 'session-end';type: The type of the metadata.payload: The string content of the metadata. Forsession-beginandsession-end, this will be an empty string.
To work on this project locally:
-
Clone the repository:
git clone https://github.com/minoruta/parse-shairport.git cd parse-shairport -
Install dependencies:
npm install
-
Run example: You can also run the example script directly to see how it works:
npm run example