mikebrady / shairport-sync-metadata-reader

Sample Shairport Sync Metadata Player
MIT License
126 stars 33 forks source link

cat fifo file #2

Closed ktruckenmiller closed 9 years ago

ktruckenmiller commented 9 years ago

Hey Mike,

I'm trying to figure out how to read the meta data. So far, I made a fifo file in shairport-sync-metadata-reader/tmp/shairport-sync-metadata

I have shairport-sync running in the background with ./shairport-sync -a "My Airplay"

Then I run shairport-sync-metadata-reader < /tmp/shairport-sync-metadata

and I cat the fifo file that I've made with cat tmp/shairport-sync-metadata

and I'm not getting any output from the pipe. Any ideas?

mikebrady commented 9 years ago

Hi Kevin. Excuse me if I go through the obvious steps – you may have done them already.

First, you have to make sure that the version of Shairport Sync you're using has support for metadata. You can check for this by running $shairport-sync -V. If the identification string includes the word metadata then it's supported; otherwise you'll have to recompile and include metadata support.

Second, with a version of Shairport Sync that supports metadata, you also have to enable it at runtime to look for metadata and to pass it on to the pipe. The best way to do this is using the "metadata" settings in the configuration file.

If you manually created the metadata pipe file, I suggest you delete it – Shairport Sync will create it automatically itself at /tmp/shairport-sync-metadata by default.

Okay, so all the metadata Shairport Sync gets or generates is written to this pipe. You can attach exactly one reader to it. If it's got no reader, then the stuff that's written to it is lost, which is okay.

So, to check that it's working, read the pipe using cat:

$cat /tmp/shairport-sync-metadata

As metadata is put in by Shairport Sync, it will appear on the output from this command.

What shairport-sync-metadata-reader is is an alternative reader of the pipe. The command you used:

shairport-sync-metadata-reader < /tmp/shairport-sync-metadata

connects the output of the pipe to the standard input of shairport-sync-metadata-reader so that it can read and parse it. It parses the contents of the pipe and emits some formatted output. It's really just a sample to show how to do stuff.

You can't have two programs reading from the one pipe – the pipe will only feed one at a time, so I suggest you use cat first to make sure there's something there. (BTW, if you want two programs to process the metadata simultaneously, use the unix tee command to duplicate the stream of output from the pipe.)

ktruckenmiller commented 9 years ago

Cool - so I'm able to get a stream in Node for displaying on a website. But I'm having trouble parsing the metadata.

Any way you can get shairport-sync-metadata-reader to push to a new stream file when it gets new song info? or a terminal command on how to do that? I tried to figure it out with tee but I like that you've already written a parser.

mikebrady commented 9 years ago

Hi there. I think I'll leave that to yourself, if you don't mind. You could use the existing reader as a starting point, and when it sees a new song it could close the current file and start a new one... I'm going to close this – feel free to reopen if there are developments.

ktruckenmiller commented 9 years ago

Thanks for the help Mike. I think I figured it out for the node portion.

I made a temporary string that just adds on fifo reads until it has something that it can parse. Once it has complete song/title information - it resets the string and waits for the next one.

Code is here for anyone interested.

https://github.com/ktruckenmiller/node-shairport-metaparser

mikebrady commented 9 years ago

Very useful, thanks, Kevin.