Lastfm2myth
From MythDora
Contents |
Lastfm2myth
These instructions will allow you to install and listen to Lastfm through the Mythtv interface. The neon-wide theme is installed by default in Mythdora. The picture above was made by myself for the Mythtv gui (hacking at another icon I found in /usr/share/mythtv/themes/neon-wide/watermark the website for the theme is: http://www.mythtvthemes.co.uk/neon-wide.shtml) . You are encouraged to add you own icons here for other themes so others may benefit.
This mod to Mythtv needs a couple of things to get it up and running, I recommend you install it on the backend because you probably have that already set up for a static IP and have a running webserver or a shared network folder that maps to the same path on all computers you want to listen to streams on. First, we need to sign up to Lastfm http://www.last.fm/ (it's free) and get the program lastfmproxy and edit its config file. Then we need to create an m3u file with a pointer of where to find the Lastfm stream. We also need a 2 second blank file and lastly we need to edit our theme and xml files.
Files Used:
- lastfmproxy > config.py
- neon theme > theme.xml
- mythtv > library.xml
- playlist file lastfm.m3u
- Next_Track.mp3
- rc.local
Let's get started...
Lastfmproxy Program
Get the program
Lastfmproxy connects to the Lastfm network and allows us to use a standard media player to listen to music. Lastfmproxy is a great program and was written by Vidar Madsen. His web address is: http://vidar.gimp.org/?page_id=50
As of writing, the latest release is lastfmproxy-1.3b.tar.gz. Change the wget command below to get the latest.
as user
$ cd /tmp $ wget http://vidar.gimp.org/wp-content/uploads/2007/12/lastfmproxy-1.3b.tar.gz $ tar xvzf lastfmproxy*.tar.gz $ cd lastfmproxy* $ nano config.py
Edit the Config.py file
Fill in your Lastfm user name and password along with any proxy details as appropriate. Yes, your username and password are stored in plain text within this file! This is only a problem if someone looks at this file then logs into the Lastfm website as you, and finds out you have Alison Moyet playlist! If you are a paid user you may want to consider the above and what sort of local security you have.
Let's talk about the IP address you could put in this config.py file. If you want to use different frontends or have the Lastfm music stream available to other computers on the local network, then instead of using the loopback address as default, (127.0.0.1 or localhost) use the local IP address which may look like 192.168.0.* Alternatively, use its hostname. If it's a combined frontend/backend then you can just leave it as the 127.0.0.1 loopback address as long as you understand this is the only computer that can access the stream. The brave can use 0.0.0.0 and have lastfmproxy grab onto all interfaces.
To save the changes made in nano hold down Ctrl key and press the letter o then Enter to save, then hold down Ctrl key and press the letter x to exit.
lastfm.m3u
Next we need to add the ability to skip a song. We achieve this by creating an m3u file. We add our url to the first line and then add a 2 second blank mp3 on the second line. Every time the stream is started a new song is played. If you don't like the current song, hit the next track button on your remote and the next (2 second blank) track is played. Because we call xine with the loop option (from the Mythtv gui) after the 2 second blank mp3 is played it goes back to the first file in the m3u tracklisting, which starts the stream again with a new song.
This lastfm.m3u file is specified when you call lastfm from the mythtv gui so the path needs to be accessible to the frontend(s) (or you can have a local m3u file on each computer). You can also use a shared folder via Samba or NFS or even put it in a folder in mythweb and access it via http:// if you desire.
I keep mine on a NAS drive so this is my path below. Keep a note of the path you decide to use because you'll have to specify it later on for the library.xml file.
# nano /mnt/nas/lastfm.m3u
Here is my file:
http://192.168.0.11:1881/lastfm.mp3 /mnt/nas/lastfm/Next_Track.mp3
But you could use (as long as there is no security on mythweb) :
http://192.168.0.11:1881/lastfm.mp3 http://192.168.0.11/Next_Track.mp3
Save and exit
Quick Test
Let's summarise. We have lastfmproxy program in /tmp> directory, we have an m3u file, and we have a working config.py. Before we look at changing the Mythtv themes we should get this up and running to check it's all working. We are going to put things where they should be and grab the blank mp3.
as root
# mkdir /opt/lastfm && mv /tmp/lastfmproxy-1.3b/* /opt/lastfm cd /mnt/nas/lastfm <---(this will depend on where you have referenced the blank mp3 file in your m3u file - file share, webserver, ~ directory etc.) # wget http://carrick.ndo.co.uk/Next_Track.mp3
Let's start it
/opt/lastfm/main.py &
Hopefully you will see this output
[1] 15686 root@example:/opt/lastfm# Starting LastFMProxy 1.3b... Connecting to last.fm server... To tune in, point your browser to: http://192.168.0.11:1881/
If you get a handshake error check you username and password in the config.py or try and login via the Lastfm website to verify your details. If all is okay, connect mplayer to the following address (modify as required for your IP address)
mplayer http://192.168.0.11:1881/lastfm.mp3
Hopefully you will hear some music. Look at the command line for clues if mplayer is not working.
Troubleshooting at this stage:
- Do you have the mp3 codecs installed?
- Are your IP addresses correct in config.py?
- Can you login to the lastfm website?
- If you get mplayer errors try connecting with xine or xmms
- Did you remember to add the lastfm.mp3 to the end of the URL?
Mythtv Theme Editing
Let's edit a few Mythtv xml files so we can see it in the Mythtv gui. Lastfm should appear as the last item under Media Library
I use the neon-wide theme and the theme layout is default (the theme layout is confusingly called "Menu theme" under Utilities/Setup -> Setup -> Appearance).
First we add the following to the bottom of libaray.xml file. This will put an entry under Media Library (not at the very bottom of the file as the file must end with </mythmenu>)
# cd /usr/share/mythtv # nano libaray.xml
Copy and paste the following into library.xml
<button>
<type>LASTFM</type>
<text>Last.fm</text>
<action>EXEC xine --aspect-ratio anamorphic --loop --no-splash --fullscreen --playlist /mnt/nas/lastfm.m3u </action>
</button>
This command launches xine in full screen (without the splash screen) and then it calls the playlist we made earlier with our stream address and blank file in it. The --loop option was discussed earlier. I have a 16/9 TV so --aspect-ratio anamorphic stretches the visuals when music is playing to fill the screen. If you don't like the current visual you can play any mp3 from the desktop, get the visual you want by right clicking and going through the menu. When you exit xineit will keep the last visual used.
Now let's grab a picture and finally edit the theme.xml
#cd /usr/share/mythtv/themes/neon-wide/watermark wget http://carrick.ndo.co.uk/lastfm.png cd ../ nano theme.xml
scroll down the file until you get to
<!-- ################################--> <!-- ######## mainmenu.xml ########--> <!-- ################################-->
and paste in the following:
<buttondef name="LASTFM">
<image>text-blank.png</image>
<watermarkimage>watermark/lastfm.png</watermarkimage>
<offset>0,0</offset>
</buttondef>
Save and exit. Restart Mythtv and presto, a new entry.
There is one more change that needs to be made. We want lastfmproxy to start on boot.
as root
# nano /etc/rc.d/rc.local
and add the following line to it
/opt/lastfm/main.py &
save exit done!
Hopefully all went well. I have a nova T DVB card which has the dog bone remote. The power button will quit out of lastfm and throw me back to the Mythtv gui which is fine. The (*) asterisk button brings up title and track info and the next track button works as expected. Others may have to fiddle with their lirc config to get it to work as expected. Google is your friend.
Regards
NzCarrick
