mikebrady / shairport-sync-metadata-reader

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

calling shairport-sync-metadata-reader as a child process #11

Closed darrenelmslie closed 8 years ago

darrenelmslie commented 8 years ago

less of an issue, more of a question. I'm very new to coding but desperately trying to incorporate Shairport Metadata reader into a MagicMirror module.

I'm trying to call the compiled code (which runs great on it's own!), using a child process from javascript:

const exec = require('child_process').exec;
const child = exec('~/shairport-sync-metadata-reader/shairport-sync-metadata-reader < /tmp/shairport-sync-metadata',
(error, stdout, stderr) => {
    console.log(`stdout: ${stdout}`);
    console.log(`stderr: ${stderr}`);
    if (error !== null) {
        console.log(`exec error: ${error}`);
    }
   });

The javascript is running without error but I'm getting nothing back at all in the console. Have I made any obvious mistakes?

Thanks for any assistance you can give

mikebrady commented 8 years ago

Just a wild guess – does exec() know how to interpret the ~ ?

darrenelmslie commented 8 years ago

Thanks for the quick response Mike. I wondered that after I posted, so tried substituting the full path but no luck.

I've also tried a fifo-js javascript package reads the shairport-sync-metadata file if I echo into it manually without shairport running. As soon as I'm running the service, nothing.

I tried changing tack and edited the shairport-sync-metadata.c file - I needed to filter which metadata was reported anyway. While I was in their I tried adding a fprintf command to output certain metadata fields to a 'NowPlaying.txt';

    // printf("Got it decoded. Length of decoded string is %u bytes.\n",outputlength);
    payload[outputlength]=0;

FILE *fp; fp=fopen("/home/pi/NowPlaying.txt", "w"); if (fp == NULL) { printf("Error opening NowPlaying!\n"); exit(1); }

    // this has more information about tags, which might be relevant:
    // https://code.google.com/p/ytrack/wiki/DMAP
    switch (code) {
   //          case 'asal':
   //            printf("Album Name: \"%s\".\n",payload);
   //            break;
      case 'asar':

fprintf(fp, "Artist: \"%s\".\n",payload); fflush(fp); fclose(fp);

        printf("Artist: \"%s\".\n",payload);
        break;

But I'm not seeing anything in the NowPlaying file either :(

darrenelmslie commented 8 years ago

sorted it - I needed to perform my fopen with append, rather than write :)

mikebrady commented 8 years ago

Thanks – I wouldn't have figured that out...

NickSutton commented 7 years ago

Hey Darren, would you mind sharing your work on this? Looking to do exactly the same!

roblan commented 7 years ago

@NickSutton - You can try using https://github.com/roblan/shairport-sync-reader It's still work in progress, but should work ;)