Page 1 of 1

Shairport Metadata

Posted: Sat Dec 13, 2014 5:08 pm
by certain-death
Hi,

Not sure if this is the correct place to post this or not.

I have a raspberry pi setup with Shairport and would like to pull the metadata info.

I can manually run the service using shairport -M command and have the now_playing file and album art save to a specified directory however I would like to run this service automatically at startup.

I can get shairport to start automatically with the init.d script supplied with shairport, I just can't get the metadata bit to work correctly.

I have tried googling but there seems to be little info on shairports metadata.

Any help would be most appreciated

Thanks

Ian

Re: Shairport Metadata

Posted: Mon Jan 19, 2015 8:41 pm
by Riverdog
I've been running into the same problem. What I eventually figured out (after much googling) is that there are guides out there for setting up shairport on the pi that reference old versions of shairport. The first thing to do is make sure the guide you're using actually installs the most up to date version of shairport. The quickest way to know is to look at the git command they provide. You want it to look like this: git clone https://github.com/abrasive/shairport.git. If it includes abrasive you're good to go. This is the guide I used which worked for me: http://drewlustro.com/hi-fi-audio-via-a ... pberry-pi/. After that I found that you need to create the meta folder ( I used /tmp/shairport_meta ). Then sudo chmod 755 [your folder]. Once done open up /etc/init.d/shairport. Here's how I modified my file:

# Configuration defaults
USER=shairport
GROUP=audio
LOGFILE=/var/log/$NAME.log
ERRFILE=/var/log/$NAME.err
PIDFILE=/var/run/$NAME.pid
MDIR=/tmp/meta
AP_NAME=$(hostname)
NICE=0

test -f /etc/default/shairport && . /etc/default/shairport

DAEMON_ARGS="--daemon --pidfile $PIDFILE --log $LOGFILE -M $MDIR"

notice the MDIR variable declaration and reference in DAEMON_ARGS? That's what worked for me.
Finally, while you're at it go to the abrasive git hub and download the default configuration file. It didn't get installed when I followed to above guide but it makes it easier to modify some of the default settings on shairport. Follow this link and download the 'default' script. https://github.com/abrasive/shairport/t ... an/default. Copy the contents and past them into a new file located at /etc/default/shairport. Don't forget to change the permissions of this file as well.

This file contains a couple of really useful features. The first, AP_NAME allows you to change the name of the new airport device. Uncomment it and add an original name (no spaces).

The next useful feature is at the end of the /etc/default/shairport file. Uncomment RUN_ONSTART and RUN_ONSTOP at the bottom and add your own custom script to be executed whenever airplay starts or stops. I'm using this to display the cover image out the hdmi port whenever a new song comes up in the que.

Anyway, that's what worked for me! You're right there isn't a lot of info on the metadata configuration so make sure to post what works for you when you get it working. Good luck!

-N

Re: Shairport Metadata

Posted: Tue Jan 20, 2015 12:43 am
by certain-death
Hi,

Thanks for your detailed reply. I had given up on my initial process as it was starting to look a little out of my depth.

I did however find a version of shairport that saved the metadata in a txt file along with the album art which I was able to deal with and satisfied my needs. I was really only interested in the song details as I wanted to display this information on a 16x2 LCD so stripping the details from a txt file was easy in this application.

I'll post up the details when I get access to my desktop again. My project is on hold at the moment but I would like to get back to my original thought process and satisfy my curiosty with the answer, I'm sure your post will help with this. I'm sure I'll have a few more questions so I will likely be in touch to pick your brains.

Again thank you for the response.

Ian

Re: Shairport Metadata

Posted: Tue Jan 20, 2015 6:53 am
by Riverdog
No worries. It looks like chmod 755 on the meta folder still prevents the now_playing fifo from being created / updated. I'm not sure of the exact permissions required. Can you link the version of shairport you're using? I've managed to create the now_playing fifo and get the cover art but I'm having a rough time extracting the info I need out of the fifo file. cat now_playing doesn't return the prompt until I cancel out. I'm not familiar with named pipes at all so if anybody knows how to proceed it would be much appreciated! At this point the text output would be easier for me although it's frustrating not to know how to do it with the pipe. Thanks!

-Nate

P.S.
I found this script which still just looses the prompt:
https://github.com/ironiridis/shairport ... e74ab2f199

It also looks (so far) like the only file you'd have to replace to change from a FIFO to a text output is metadata.c. If you nano that file can you post the contents? Thanks Ian!

Re: Shairport Metadata

Posted: Tue Jan 20, 2015 9:16 pm
by certain-death
Hi,

Looks as though your getting confused at the same point I was. I couldn't work out how to use the FIFO file either and in the end decided it was a bit beyond my current knowledge to try and learn how to use it.

Here's a link to the shairport version that I ended up using:

https://github.com/dangerjain/shairport

I then found an init.d startup script for shairport and made some changes to start the metadata logging along with shairport as follows:

Code: Select all

#! /bin/sh
# /etc/init.d/shairport
#
### BEGIN INIT INFO
# Provides:     shairport
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Put a short description of the service here
# Description:       Put a long description of the service here
### END INIT INFO


NAME="ClippAir"

case "$1" in
  start)
    /usr/local/bin/shairport -b 95 -d -a "$NAME"  -C /home/pi/airplay
    ;;
  stop)
    kill -9 `pidof shairport`
    ;;
  *)
    echo "Usage: /etc/init.d/shairport {start|stop}"
    exit 1
    ;;
esac

exit 0
#
this line: (/usr/local/bin/shairport -b 95 -d -a "$NAME" -C /home/pi/airplay) -C starts the metadata logging and then the /home/pi/airplay is the directory I decided to save the data to.

I was pleased with how this worked and it satisfied my needs as I could read the text file and pull out the lines I wanted with ease. From the testing that I performed it seemed to work faultlessly and the files are update as soon as the track is changed.

Thanks

Ian

Re: Shairport Metadata

Posted: Wed Jan 21, 2015 5:59 am
by Riverdog
Thanks! So you just poll the now_playing file every second or something? I'm still banging my head against the fifo file. I can redirect it to a file using cat now_playing > output, but can't get awk to work like some of the other examples. It's frustrating because I think the named pipe would make it so you didn't have to keep checking file status over and over. Back to google....

Update:

I found this script which seems to work for me:
https://github.com/ironiridis/shairport ... capture.sh

The way to test if the fifo style metadata pipe is working is to:
1. Set up your init.d/shairport file to include the -M /path argument
2. Restart the shairport deamon via sudo /etc/init.d/shairport restart
3. Navigate to your the folder you identified as path in step 1
4. cat now_playing

At this point the cursor will go away. This is called blocking and what is happening is that the cat command is waiting for the fifo file to be opened on the other end of the pipe. When this happens it will read the metadata and then wait again. So to test if the transfer is working, we need to wait for a song change.

5. Connect a source to shairplay and change songs a few times.
6. Check for metadata to be displayed in the shell.

Troubleshooting:
1. Make sure the permissions on both the metadata folder and the now_playing file itself are set correctly. They should have both read and write for the appropriate user / group.
2. Open /etc/init.d/shairport and double check that the -M argument is added and that the target path is correct.

Now create a new script:
1. nano getinfo.sh (you may have to adjust permissions here)
2. Paste the script linked above
3. Edit TARGET_SCRIPT="/home/user/shairport_now_playing.sh" and METADATA_DIR="/tmp/shairport" to reflect your paths
4. Save and exit.
5. nano shairport_now_playing.sh (you may have to adjust permissions here)
6. In this script arguments containing the metadata information can be accessed through the use of these variables:

$1: artist
$2: title
$3: album
$4: genre
$5: comment
$6: The full pathname to the artwork file

That means you can add something like the following to shairport_now_playing.sh:

#!/bin/bash
echo $1

This will just echo the artist but you can set it up to do whatever you want. fbi -T 2 "$6" displays the cover art out hdmi for example.

7. Save and exit.
8. Now run ./getinfo.sh &

The & at the end of the line causes getinfo.sh to run in the background. To stop it:

1. ps
2. Note down the job id
3. kill id

What happens is that getinfo.sh runs in the background and waits for incoming metadata. When it detects that the fifo is open for writing it automatically triggers whatever you have in shairport_now_playing.sh. That's as far as I've gotten. The only problem I've still got left to crack is that the above setup seems to echo all the metadata correctly but fbi always loads the previous cover image instead of the current one. I'm going to work on that tonight.

If anybody else wants to chip in and help us understand what we're doing right (or wrong) here it would be greatly appreciated!

-Nate

Re: Shairport Metadata

Posted: Thu Jan 22, 2015 9:12 pm
by certain-death
It looks as though you have nearly cracked it. Think I'll have to pull my project out of the drawer and try the FIFO method again. I think your probably right in that the FIFO method would save polling for the information every other second which is a nice clean way to work things. Having said that polling the text file is still seemless enough, certainly for my needs, and the update is no worse than the slight delay shairport gives between skipping to next track and the sound changing through the speakers.

I'll have another crack at this soon and see if I can get any further now that you have provided answers on the process. Hopefully between the two of us we can crack this to save me going insane.

Thanks

Ian

Re: Shairport Metadata

Posted: Fri Jan 23, 2015 12:25 am
by Riverdog
No more progress - I took a break to work on another project last night. My goal here is to show the cover art and metadata over hdmi so I can hook the pi up to my receiver. I've got LIRC up and running and plan on implementing bluetooth support next.

Here's what I'm planning on including in my shairport_now_playing.sh:

montage -background none -fill ivory2 -font Arial -pointsize 72 gravity: west label:'$1/n$2/n$3' +set label -shadow -background black -geometry +5+5 cover_text.jpg

convert $6 cover_text.jpg -gravity center +append annotated_cover.jpg

fbi -T 2 annotated_cover.jpg

I haven't tested this yet but it utilizes ImageMagick tools to first make a .jpg of the metadata text then append it to the right of the cover art and save the whole thing as a new file. The annotated file is then displayed via fbi on tty0.

Once this project is done I should be able to control the receiver and tv using my phone, stream music to the receiver via airplay (with metadata) or via bluetooth. I'm planning on using the RUN_ONSTART script to send an IR signal via LIRC to automatically change to the right input on the receiver then start shairport playback. I'm also going to use this startup script to disable bluetooth while airplay is going then enable it again when airplay stops. I might look into setting it up as a DLNA server as well - I'm not sure. You're outputting to an LCD right? What does your project look like?

Re: Shairport Metadata

Posted: Fri Jan 23, 2015 8:27 pm
by certain-death
Sounds like an interesting project. I like the idea of converting the metadata into a jpg image.

My project is to integrate modern necessities into my 1989 VW Golf convertabile whilst keeping it as original looking as possible.

The plan is to have 1 16x2 LCD fitted into a period cassette player to display airplay metadata and RDS info from the radio module when I get round to it.

There is then a second 8x2 lcd replacing the dash clock in the speedo cluster which I plan to use to display inside and outside temperature along with air intake temperature and gps information such as speed, altitude etc.

I had alot of the code written for the dash stuff and then decided to add the radio module and second lcd for displaying metadata. Still currently at the bench stage but I hope to have it all ready for installing when the weather gets better.

Thanks

Ian

Re: Shairport Metadata

Posted: Thu Jan 29, 2015 8:12 am
by Riverdog
That's a cool project! Are you going to post photos somewhere when you're done?

Nate

Re: Shairport Metadata

Posted: Sat Apr 04, 2015 5:32 pm
by allenbower
I have been working on this for a couple of weeks but I'm still having a couple of problems.

This is my getinfo.sh that runs on startup:

Code: Select all

#!/bin/bash

# Calls $TARGET_SCRIPT with the following parameters...
# $1: artist
# $2: title
# $3: album
# $4: genre
# $5: comment
# $6: The full pathname to the artwork file

TARGET_SCRIPT="/home/pi/airplay/nowplaying.sh"
METADATA_DIR="/tmp"

test -p $METADATA_DIR/now_playing || mkfifo $METADATA_DIR/now_playing

while exec 3<$METADATA_DIR/now_playing
do
declare -A METADATA
IFS="="
while read -u3 mK mV; do
  if test "x$mK" = "x"; then break; fi
  METADATA["$mK"]="$mV"
done
exec 3<&-
$TARGET_SCRIPT "${METADATA["artist"]}" "${METADATA["title"]}" "${METADATA["album"]}" \
  "${METADATA["genre"]}" "${METADATA["comment"]}" "$METADATA_DIR/${METADATA["artwork"]}"

unset METADATA
done
And this is my nowplaying.sh referenced in getinfo.sh:

Code: Select all

#!/bin/bash
convert $6 -resize 175x200 /tmp/album_art.jpg
convert -size 320x240 canvas:'#404b51' \
-pointsize 30 -fill white -draw 'text 0,30 "Track: $2" ' \
-pointsize 30 -fill white -draw 'text 0,80 "Artist:" ' \
-pointsize 30 -fill white -draw 'text 0,130 "$1" ' \
-pointsize 30 -fill white -draw 'text 0,180 "Album:" ' \
-pointsize 30 -fill white -draw 'text 0,230 "$3" ' \
/tmp/text.jpg
composite -geometry +135+55 /tmp/album_art.jpg /tmp/text.jpg /tmp/composite.jpg
fbi -noverbose -T 1 /tmp/composite.jpg
However, I'm getting this as the result:
Image

Any ideas as to why I'm not getting the track information but getting the correct album art?

Re: Shairport Metadata

Posted: Sun Apr 12, 2015 1:44 am
by allenbower
I finally figured it out!

I had my double-quotes and single-quotes swapped. I switched them and all is good.

Code: Select all

#!/bin/bash
convert $6 -resize 175x200 /tmp/album_art.jpg
convert -size 320x240 canvas:'#404b51' \
-pointsize 30 -fill white -draw "text 0,30 'Track:' " \
-pointsize 25 -fill white -draw "text 85,30 '$2' " \
-pointsize 30 -fill white -draw "text 0,80 'Artist:' " \
-pointsize 20 -fill white -draw "text 0,130 '$1' " \
-pointsize 30 -fill white -draw "text 0,180 'Album:' " \
-pointsize 20 -fill white -draw "text 0,230 '$3' " \
/tmp/text.jpg
composite -geometry +135+40 /tmp/album_art.jpg /tmp/text.jpg /tmp/composite.jpg
fbi -noverbose -T 1 /tmp/composite.jpg
It's not perfect, but I'm one step closer.

Image

Re: Shairport Metadata

Posted: Mon May 18, 2015 6:37 am
by Meph88
Where did you end up with this project?
I'm trying to get an airplay setup with metadata to display on screen for an in car system.
I have shairport installed and working great but the metadata thing isn't happening for me.
Did you get this working?

Re: Shairport Metadata

Posted: Sun May 24, 2015 7:42 pm
by certain-death
I still haven't finished my project but I opted to use the version of shairport that allowed metadata to be saved to a txt file. Link to ths version is here:

https://github.com/dangerjain/shairport

If you look back through my posts you will see the init.d script I used for startup which automatically generated the metadata when shairport started and saved it to a specified directory.

For me this worked fine and text files where alot easier to handle. The last time I looked at this project I had the song and artist details showing on a 16x2 LCD but was struggling to get them scrolling properly on seperate lines.

Thanks

Ian

Re: Shairport Metadata

Posted: Sun Apr 23, 2017 3:01 pm
by TheMiddle36
You guys have made some awesome process here!!

I've got as far as being able to read the metadata in terminal, after manually starting the shairport-metadata-reader program.

Next steps are to automatically start it, then somehow pass the content to a HTML file sitting on localhost... no idea how to do this, am fine with HTML and JS, but not the Python side of things.

If I can manage this, I might add some buttons to the webpage and see if I can pause/skip/volume etc from the iPhone, which is mentioned in the (scare) docs for the meta reader git.

Just posting to say I'm giving this a go, but if anyone has any info on bridging the gap from the pipe to HTML, I'd really like to hear your thoughts!

Cheers,
Nick