Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, May 25, 2014

How to Install PyTivo on Synology NAS

PyTivo is a free program that allows you to serve to your Tivo videos, pics and music stored on your Synology. Here are instructions that attempt to be complete enough so that most anyone can get PyTivo working on their Synology NAS.

There are a number of web pages and forum entries talking about how to get PyTivo to run on a Synology NAS but they assume that you are already knowledgeable about Linux and this very process. I have attempted to provide a complete set of steps so that just about anyone can get PyTivo to work on their Synology.


The steps will cover the following:

  • Setup of a Command Line Interface (CLI) to send commands to the Synology NAS.
  • Installing ipkg using a bootstrap. This will make it easy to install other programs such as PyTivo.
  • Installing Git which makes it easier to download open source programs such as PyTivo.
  • Install Python which is needed to run PyTivo.
  • Download and install PyTivo.
  • Setup of PyTivo.

And now for the steps.

  1. Download PuTTY. This is the CLI program that enables SSH communications with the NAS.
    http://...~sgtatham/putty
  2. Log onto Synology NAS
  3. Enable SSH on the Synology NAS. This will allow you to externally execute commands on the NAS.
    1. Go to Control Panel and select the "Terminal & SNMP" page.
    2. Check the box for Enable SSH Service
    3. Click Apply.
  4. While in Control Panel lookup the CPU type. You will need this to get the correct ipkg bootstrap.
    1. Select the "Info Center" page.
    2. Look for and note the value after "CPU". For example, the CPU on the DS213j is "MARVELL Armada 370"
  5. Find the correct bootstrap. In most cases, you will download and install using commands typed into the PuTTY command window (see step 7).
  6. Execute PuTTY.exe
    1. The Configuration screen will appear. Enter the IP address for the Synology NAS, enter a name for the "Saved Session" and hit Save. You will reuse this session info in the future so you don’t have to reenter the IP address.
    2. Click on Open. You will get a command window asking, "login as".
    3. Login using the "root" account. The password is the same as admin.
  7. Using the PuTTY CLI, the following commands are to download and install the bootstrap for the Armada 370. Each bootstrap has its own instructions. Note the first command is too long to fit on one line in the window below but it is to be entered as one line.
    • /usr/syno/bin/wget https://github.com/hsleep/ds213j_bootstrap/archive/master.zip --no-check-certificate -O ds213j_bootstrap-master.zip
    • unzip ds213j_bootstrap-master.zip
    • cd ds213j_bootstrap-master
    • sh bootstrap.sh
  8. Verify the install
    • source /etc/profile
    • ipkg info
      You will see something like:
      Package: wget
      Version: 1.12-2
      Conflicts: wget-ssl
      Status: install user installed
      Architecture: arm
      Installed-Time: 1400475847

      Successfully terminated.
  9. Make sure everything is up to date
    • ipkg update
    • ipkg upgrade
  10. If you haven’t already installed python using the Synology Package Center (the recommended method), you can install it from the PuTTY CLI. However, using the command below will not likely install the latest version.
    • ipkg install python
  11. Install git to make it easier to download pyTivo.
    • ipkg install git
  12. Verify the location of ffmpeg.
    • ls /usr/syno/bin/ffmpeg

    You will see the path repeated if the file exists at this location. If it doesn’t, you will need to install it.
  13. Install pyTivo
    • mkdir -p /usr/local/src/pytivo
    • cd /usr/local/src/pytivo
    • git clone git://repo.or.cz/pyTivo/wmcbrine.git
    • cd /usr/local
    • ln -s src/pytivo/wmcbrine pyTivo
    • cd pyTivo
    • cp pyTivo.conf.dist pyTivo.conf
  14. Edit pyTivo.conf and set the path to ffmpeg (from step 12).
    • vi pyTivo.conf

    vi is a text editor. Here are some useful commands (Hit ESC to enter a command):
    dd
    delete line
    O
    insert line above cursor
    o
    insert line below cursor
    u
    undo
    :wq{Enter}
    save and quit
    :q! {Enter}
    quit without saving
    ZZ
    Save
    The line to be changed will say
      "ffmpeg=/usr/bin/ffmpeg"
    but it needs to say
      "ffmpeg=/usr/syno/bin/ffmpeg".

    More commands available at
    ...synology.com...Linux_VI_Editor
  15. Additional changes to the file include changing the name of the Share (which displays on your Tivo under "Now Playing"), changing the path for that share, and adding additional shares if needed.
    1. The default share is MyMovies and appears in the file as "[MyMovies]" (a section header).
    2. The correct path will be something like "path=/volume1/video".
  16. Find the location of python.
    Depending on how you installed python, it will likely be in one of the following two directories:
    • /usr/bin
    • /opt/bin
    Run the following two commands to see if it is in one of those directories. The response of each command will either be a repeat of the path indicating the file is there or "No such file or directory".
    • ls /usr/bin/python
    • ls /opt/bin/python

    You can get the version of python by running it (and then hit {Ctrl}+D to exit). For example:
    • /usr/bin/python
      You will see something like:
      Python 2.7.6 (default, Apr 8 2014, 23:36:51)
      [GCC 4.6.4] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>>

  17. Create file "start.sh". If you’ve been following the instructions, you are already in the "/usr/local/src/pytivo/wmcbrine" directory and don’t need to specify it.
    • vi start.sh

    The contents will be as follows. Note that you will either be entering "/usr/bin/python" or "/opt/bin/python" on line 2.
sleep 60
/usr/bin/python /usr/local/pyTivo/pyTivo.py > /dev/null 2>&1 &

  1. Create file "pyTivo.sh".
    • vi pyTivo.sh

    The contents will be as follows (from Iluvatar on pytivo.sourceforge.net...)
RETVAL=0

start() {
   echo -n ""Starting pyTivo: ""
   ps | grep pyTivo.py | grep python
   RETVAL=$?
   [ $RETVAL -eq 0 ] && echo ""pyTivo already running: Exiting"" && exit 1

   sh /usr/local/pyTivo/start.sh > /dev/null 2>&1 &
   RETVAL=$?
   [ $RETVAL -eq 0 ] && echo -n ""done""
   Echo
   return $RETVAL
}

stop() {
   echo -n ""Stopping pyTivo: ""
   kill -9 `ps |grep pyTivo.py |grep python | awk -F" " '{print $1}'`
   RETVAL=$?
   Echo
   [ $RETVAL -eq 0 ] && echo -n ""done""
   Echo
   return $RETVAL
}

case ""$1"" in
   start)
    start
    ;;
   stop)
    stop
    ;;
   restart|reload)
    stop
    sleep 1
    start
    RETVAL=$?
    ;;
   *)
    echo ""Usage: $0 {start|stop|restart}""
    exit 1
esac
exit $RETVAL


























  1. Make the two .sh files executable.
    • chmod 755 start.sh
    • chmod 755 pyTivo.sh

  2. Create a link to pyTivo.sh so that it will get auto started when the NAS is booted. The file has to appear as if it is located under "/usr/syno/etc/rc.d/" and has "S99" at the beginning of its name.
  • ln -s /usr/local/pyTivo/pyTivo.sh /usr/syno/etc/rc.d/S99pyTivo.sh

  1. Restart the NAS and, after a minute, pyTivo should have a web page at http://your_NAS:9032. You can make option changes here instead of reediting the pyTivo.conf file. You can also start pyTivo without a restart by running the following:
    • /usr/syno/etc/rc.d/S99pyTivo.sh start

A lot of steps, but this should be enough to get you enabled. However, there is the question of whether this is even worthwhile given that Synology now has native support for Chromecast.



Read more »