Difference between revisions of "Integrate Sirius"

From MythTV Official Wiki
Jump to: navigation, search
(Introducing SIPIE: formatting line breaks)
(Introducing PYXIS)
Line 34: Line 34:
 
*[http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&rlz=1B2GGIC_enUS209US209&q=python-notify python-notify] (highly recommended)
 
*[http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&rlz=1B2GGIC_enUS209US209&q=python-notify python-notify] (highly recommended)
  
==Introducing SIPIE==
+
==Introducing PYXIS==
 
<pre>
 
<pre>
 
A Command Line Player for SIRIUS and XM Satellite Radio
 
A Command Line Player for SIRIUS and XM Satellite Radio

Revision as of 04:05, 9 January 2012

This article is going to give you all of the info you need in order to pipe your online Sirius Satellite Radio account directly through your MythTV system. The first draft of this article is based around a Fedora Core 6 setup but it should be EASILY adapted to any distro. Please, READ THE ENTIRE ARTICLE CAREFULLY all the way to the end before you start anything.


Important.png Note: this is NOT a plug-in and is basically a hack but when completed it looks just like a plug-in.

Important.png Note: article has been significantly updated to replace Sipie with Pyxis. Pyxis is more robust including recording capabilities.


Article from 10,000 feet

What this article is...

This article IS about:

  • Setting up MythTV to play streams from Sirius Radio Online
  • How-To use programs that other people wrote (and are not affiliated with MythTV)
  • How-To integrate everything with the default MythTV menu theme

What this article is not...

This article IS NOT:

  • How-To get free access to the streams (although a Sirius online guest account will work fine)
  • How-To perfectly integrate with your particular MythTV GUI (we only cover the default menu theme)
  • A Sirius Radio Plug-in for MythTV

What you need to have

Setup

  • You only need to have an account setup at Sirius.com.

Installed

Required:

Optional:

Introducing PYXIS

A Command Line Player for SIRIUS and XM Satellite Radio
Pyxis is a wrapper that provides access to SIRIUS’ internet radio streams through the command line. 
Pyxis is written entirely in python.
Pyxis is a large rewrite of the original project Sipie written and maintained by Eli Criffield at 
http://sipie.sourceforge.net/ and none of Pyxis would have been possible without Sipie’s 
authentication code. Big thank you to Eli Criffield.

The reason for Pyxis’s existence is because in recent years development on Sipie has slowed 
and as such when SIRIUS changes something the time required to bring it back to a working 
version can sometimes be a long time. 
So a couple of us decided to rip out all the largely unused portions of Sipie, refactor a lot of 
it and bring it into a more stable and adaptable package. Thus Pyxis was born when we realized 
we could no longer pretend it was still Sipie.

Let's get started!

Installing pyxis Requirements

TwoOneSix wrote a script for sipie (sipie_myth) that is for usage in MythTV. This script has been modified (below) to work with pyxis. Remember that ONLY when you get pyxis working OUTSIDE of MythTV, will it work INSIDE of MythTV. Also, make sure when you do your initial pyxis setup that you do it under your mythtv account (or whatever account runs the front end).


Installing pyxis

This is from [1]

sudo add-apt-repository ppa:pyxis/pyxis
sudo apt-get update
sudo apt-get install pyxis

Note: Should you already have python-setuptools, you may have to remove first with:

apt-get remove python-setuptools

Installing Beautiful Soup

Current version of BeautifulSoup will now generate a stack trace. Appears to be reported as a bug in BeautifulSoup [2] Sirius.com doesn't put quotes around one style tag and BeautifulSoup crashes.

3.0.7 still works for Sipie so use the following.:

# cd ~
# wget http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.7.tar.gz
# tar xvf BeautifulSoup-3.0.7.tar.gz
# cd BeautifulSoup-3.0.7
# sudo easy_intall .


Configuring pyxis

You need to ensure that the configuration is done under the same user account that MythTV runs under, in my case it's the mythtv user, simple enough.

$ cd ~
$ pyxis

username and a crypted password will be stored in ~/.sipie/config
no plain text passwords are stored
if you want to change your password remove ~/.sipie/config
then run sipie and it'll ask you for username and password again

Enter username: MySiriusUsername
Enter password:

Login Type, type guest or subscriber
Enter login type: subscriber
  • Enter the captcha in the popup window or if sipie can't find wxGTK you will have to open the image file it tells you to open and enter the captcha at the command prompt.
  • You should now be prompted to select a station, if you have a GUI, pick one from the drop-down and chose "play"... you should hear the stream...

Important.png Note: it doesn't matter if you see a GUI app window... in a minute, we'll force it to run with no user input. We're currently only focused on hearing the stream.

  • Stop the stream VIA the "stop" button on the GUI or Ctrl+C twice on the command line.


Let's hack it together

OK, now we are going to write a simple shell script that we will use to make MythTV happy while talking to sipie.

Create pyxis_myth

We need to create a single executable file so find a nice place you can execute it from. Personally, I use /usr/bin. You can replace vi with gedit or kedit if you prefer a GUI text editor.

# vi /usr/bin/pyxis_myth

Now, paste in the following code: {{Code box|/usr/bin/pyxis_myth|

#!/bin/bash
# Script By: Josh <TwoOneSix AT thatclothingco DOT com>
# revised to work with pyxis by Eric <eric DOT dreher AT gmail DOT com>
# Used to control pyxis (Sirius radio player) from MythTV menu

pid_file=/tmp/pyxis_myth.pid

killtree() {
    local _pid=$1
    local _sig=${2-TERM}
    for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
        killtree ${_child} ${_sig}
    done
    kill -${_sig} ${_pid}
}

die_mythPyxis()
{
        killtree `cat $pid_file`
        rm -f $pid_file
        return 0
}

play_mythPyxis()
{
        stream="$*"
        echo "I'm about to play: $stream"
        exec /usr/bin/pyxis "$stream" &
        echo $! > $pid_file
        return 0
}

# If we see the kill command, kill the old processes/streams
if [ "$1" = "kill" ]; then
        die_mythPyxis

# If we see the play command, kill any existing streams then play the stream
elif [ "$1" = "play" ] && [ "$2" != "" ]; then
        if [ ! -e $pid_file ] ; then
                play_mythPyxis $2
        else
                die_mythPyxis
                # Just to be sure it's gone...
                if [ ! -e $pid_file ] ; then
                        play_mythPyxis $2
                else
                        echo 1>&2 '******FATAL ERROR STARTING STREAM PLAY******'
                        exit 1
                fi
        fi
        exit 0
else
         echo 1>&2 'Usage: ' $0 '{kill | play} stream (stream only required on play)'
         exit 127
fi


Now you will want to make the file executable:
<pre>
# chmod a+x /usr/bin/pyxis_myth

Test scripts

Now, as your mythtv user, pull up a command window and run the command we just "made" with the stream to test.

  • Usage: /usr/bin/pyxis_myth {kill | play} stream (stream only required on play)
$ pyxis_myth play octane

Do you hear the stream without having to enter a single thing in the command window? Do you see the song names in the command window and in the pop-up notifier (if you left tryPopus=True)? That's good, now use this to kill the stream:

$ pyxis_myth kill

Did you have to enter information? That's bad. Make sure you configured pyxis as your mythtv user and try again.


Setting up the MythTV GUI

At this point, you should be able to listen to (and kill) streams from the command line with no user intervention... that's 1/2 the battle. Now, we are going to hack a couple of buttons onto the default menu theme.


Important.png Note: If you are currently running .20+ chances are that you're using the default menu theme. No, not the actual MythTV theme, just the menu theme. To check out which one you're using do this in Myth: Utilities / Setup (or Setup) -> Setup -> Appearance -> and at the bottom of the first options page you will see the menu themes selection box, we will be hacking into "Default" so make sure it's set to that one. If you use classic or DVR you can change some of the commands below so that your work is being done on that particular theme (just add /themes/classic or /themes/DVR respectively to the "cd" commands below).

Backup the default theme

# cd /usr/share/mythtv
# tar cfvz default_backup.tar.gz *.xml

I use the -v option because it's an easy way to verify (VIA verbose) what files were put into the tar ball.

Hack the default theme

I'm only going to show you the 2 required changes to get this hack to work.


Important.png Note: If you're running a MythDora release these files might be located in a different directory.

Now, add the following to mainmenu.xml file.

# cd /usr/share/mythtv
# vi mainmenu.xml
   <button>
      <type>MUSIC</type>
      <text>Play Sirius Radio</text>
      <action>MENU siriusmenu.xml</action>
   </button>

Then, create the siriusmenu.xml file (be sure to add all of the streams you want access to). Run pyxis from the command line and enter "list" to get a current channel listing. A few current channels are included as an example. Add as many as you want, but the more you add the further the "Stop" command is to navigate to.

# vi siriusmenu.xml
<mythmenu name="SIRIUS">

   <button>
      <type>MUSIC</type>
      <text>80s On 8</text>
      <action>EXEC /usr/bin/pyxis_myth play "80s On 8"</action>
   </button>

   <button>
      <type>MUSIC</type>
      <text>Octane</text>
      <action>EXEC /usr/bin/pyxis_myth play Octane</action>
   </button>

   <button>
      <type>MUSIC</type>
      <text>The Bridge</text>
      <action>EXEC /usr/bin/pyxis_myth play "The Bridge"</action>
   </button>

   <button>
      <type>MUSIC</type>
      <text>Outlaw Country</text>
      <action>EXEC /usr/bin/pyxis_myth play "Outlaw Country"</action>
   </button>

   <button>
      <type>TV_DELETE</type>
      <text>Stop Listening</text>
      <action>EXEC /usr/bin/pyxis_myth kill</action>
   </button>

</mythmenu>


Tag definitions

OK, now the tag definitions for the above xml file

  • "button" tells the theme to paint a button on the screen
  • "type" tells the theme what image to use for the button
  • "text" tells MythTV what button text to put on the screen
  • "action" tells MythTV what to do when you select the button

Why it works

You have to wrap pyxis_myth around the stream because when MythTV runs the EXEC it waits for a response before it releases the button. pyxis_myth simply kicks off the stream and tells MythTV that it's finished executing. You are going to have to modify the XML menu files if you want to add another language tag or if you want to add additional channels.

Additional Setup and Usage Notes

  1. Be patient after you choose a stream as sometimes it will take 30 - 45 seconds to start playing
  2. The stream will play until you choose the "Stop Listening" button on the GUI (or pyxis_myth kill is executed)
  3. When you're listening to a stream, it locks up the audio output device for MythTV which can be good and it can be bad, see below.
GOOD
  • If you want to watch a Football game on TV and listen to the commentators from Sirius instead of the TV commentators
BAD
  • If you wanted to play 2 audio streams at once to make your own mix tapes. ;-)

Screen shots

The new default main menu: Main Menu

The Sirius stream selection menu: Sirius Menu