# pyTivo plugin for Sirius/XM on Tivo



## smbaker (May 24, 2003)

I've hacked together a pyTivo plugin to let me listen to Sirius. It seems to work for as much of my own use as I need it to (i.e. it lets me listen to 80s on 8), but is very rough around the edges.

It's currently Linux-only due to dependency on mplayer.

I figured I'd share in case anyone wants to try it, the tarball is here: 
http://www.smbaker.com/download/pytivo-sirius-0.1.tar.gz

To be clear, this is leveraged greatly on other peoples' work, including the developers of pyTivo and the Pyxis player for Linux.

Copy of the README follows below:

pyTivo plugin to support Sirius Online Radio
Dr. Scott M Baker, http://www.smbaker.com/

Limitations - 
This plugin is extremely beta. Meaning, I got it work well enough that I 
can listen to "80s on 8" and that's all that's really important to me. 
Things that are known to be broken include - 
* Linux only
* Does not with Windows (in case you missed the line above)
* error-checking is virtually nonexistent. If something is broken,
you're probably screwed. I hope you know python. 
* the "play" page shows a bogus duration of 10,000,000 milliseconds
* the "play" page shows "unknown" for all other fields
* song title and artist information is not displayed or updated
* leftover named pipes may be left in /tmp
* orphaned mplayer and/or ffmpeg processes may get left around

Basically: IT WORKS FOR ME. It may or may not work for you.

Acknowledgements - 
Pyxis
much code was used from the Pyxis online player,
https://github.com/Kasuko/pyxis

Sipie
precursor to Pyxis
http://sourceforge.net/projects/sipie/
http://ionshard.com/pyxis

PyTivo / wmcbrine
I used the music plugin as a basis for this plugin from the wmcbrine 
distribution
https://github.com/wmcbrine/pytivo

Prerequisites - 
1) You must have ffmpeg installed
2) You must have mplayer installed
3) You must have an mp3 encoder installed for ffmpeg (I used liblamemp3)

Those things listed above are actually important. You should check them. 
Getting liblamemp3 working with ffmpeg was nontrivial for me. I had to do
the following:
1) build liblamemp3 from source and install it
2) copy lame libraries from /usr/local/lib to /usr/lib
3) configure ffmpeg with --enable-liblamemp3
4) build ffmpeg from source and install it

Installation
Everything in this directory should go into pyTivo in plugins/sirius

Configuration
Add a section to pytivo.conf that looks like this:

[SatRadio]
type = sirius 
path = none
username = <put your sirius username here>
password = <put your sirius password here>

Also, add a path to mplayer to your [Server] section:

[Server]
... other pyTivo stuff
mplayer = /usr/local/bin/mplayer

Troubleshooting -
If and when something goes horribly wrong, look at the console output
and try to figure out what it was.

The Tivo music player is very fragile. Failure of a stream can occasionally
cause it to fail to the point where reboot is required to get it to work
again.

Make sure your ffmpeg has MP3 encoding support (liblamemp3, etc)

Make sure your sirius username and password are correct

Try downloading pyxis and see if it'll work for you (it's a command-line 
Linux sirius player)

Future Plans -
None, really. I don't have much time.

Song titles/artists would be nice.

This probably should be setup on one of them fancy git respository things.


----------



## wmcbrine (Aug 2, 2003)

(Disclaimer: I haven't looked at this yet, only read the post.)

MPlayer is available for Windows and Mac, if that's the only issue there.

Duration can be given as 0; this is what I'd recommend for streams, rather than a fake value.

Song titles and artists will never work with an HMO server, since they can't be changed in the middle of a stream. But if they're available, you could do it via HME.


----------



## glamperillo (Nov 20, 2010)

I have changed the script to use a windows version of mplayer, but it does not seam to work. I currently do not have an active Sirius account, but I would think it would appear in the Tivo Music menu. No errors are listed in the console.
What will prevent this from working on Windows?


----------



## smbaker (May 24, 2003)

glamperillo said:


> What will prevent this from working on Windows?


There's a couple of things. For one, I placed a cookie file in /tmp/something (I forget the exact path as I'm not looking at the code right now). There's a couple of problems with that, one being that Linux deletes /tmp occasionally, and the other that windows doesn't have a /tmp. There's probably a better place for me to put it in both instances.

Also not listed above in the README is that it requires a python package called beautifulsoup.

Finally, I do make use of named pipes with mplayer, and I'm not sure to what extent Windows supports named pipes. Basically, I pipe the output of mplayer into a named pipe which is fed into ffmpeg for conversion to mp3, and then piped out via stdout back into the python script where it's streamed to the Tivo.

Nevertheless, it should be appearing on your Tivo's music menu, even if all of the above things don't work right. Have a look at when pyTivo is importing the modules, it could be an import error due to a missing dependency (i.e. beautifulsoup).

I didn't throw this thing together with windows support in mind (at the time I didn't even know pytivo worked under windows), so there's no effort at all in the code for windows support. This is something I can look into some day when I have some free time.


----------



## jbuehl (Nov 23, 2004)

I just saw this thread after having just written a script to record Sirius XM to an mp3 file. My goal was to be able to time shift a show that I like that comes on at an inconvenient time and listen to it on an iPod. It works with the new Sirius XM player which is Flash and has apparently broken Pyxis.

My script launches the player in Firefox, and then uses xdotool to send mouse events and text to the Firefox window to log in and start the player. It plays the last station you were listening to, records the audio using arecord, and encodes as mp3 using lame. It is pretty fragile and probably will break from time to time, but someone may find it useful. The screen coordinates for the login fields may require some tweaking depending on how you have your browser configured and will definitely have to be modified if (when) they change the UI. It only runs on Linux but there may be equivalent ways to do this on Windows or OS X.

There is one hardware requirement. The audio output jack has to be connected to the line-in jack with an audio cable because it literally is recording its own output.

One of the improvements I would like to make is to do something to prevent the inactivity timer from stopping the stream.


```
#!/bin/bash

USERNAME="xxxxxxxx"
PASSWORD="xxxxxxxx"
DURATION=5400
TARGET="/music/mp3/radio/"
NAME="XM-Outlaw"
export DISPLAY=:0

DATE=`date +%F`
echo start `date`

# start the player
firefox -height 768 -width 1024 https://www.siriusxm.com/player/ &

# wait a bit and then get the pid and window ID
sleep 10
WINDOW=`xwininfo  -name "Sirius XM - Mozilla Firefox"|grep xwininfo:|cut -f4 -d" "`

# login
xdotool mousemove --window $WINDOW 330 270
xdotool click --window $WINDOW 1
sleep 1
xdotool type --window $WINDOW $USERNAME
sleep 1
xdotool mousemove --window $WINDOW 330 300
xdotool click --window $WINDOW 1
sleep 1
xdotool type --window $WINDOW $PASSWORD
sleep 1
xdotool mousemove --window $WINDOW 330 340
xdotool click --window $WINDOW 1
sleep 10

# record the audio for the specified duration
arecord -f cd -t raw -d $DURATION| lame -r - $TARGET$NAME-$DATE.mp3

# kill the process
PROC=`ps|grep firefox|head -n1`
PID=`echo $PROC|cut -f1 -d" "`
echo pid $PID
echo end `date`
kill $PID
```


----------



## MrJedi (Apr 13, 2011)

I was just saying to my wife the other day that I wish TiVo would add Sirius/XM support didn't think to look for a pluggin. Does this still work with the new Sirius/XM online streaming interface change that a occurred a few months ago?

I used to use the mplayer work around on a laptop so that I could listen to Sirius on my back deck through my outdoor speakers. The stream only had to be authorized once a day this way and you didn't have to worry about the 90 minute time-out.

I'll definitely have to play with this when I get some time.


----------



## jbuehl (Nov 23, 2004)

I haven't tried it, but apparently the plugin doesn't work with the new Sirius XM interface. See this link http://ionshard.com/pyxis


----------

