# Running pyTivo on a QNAP



## hmspain (Oct 11, 2015)

Executing pyTivo.py using "python pyTivo.py", I'm getting:

[/share/pyTivo] # Traceback (most recent call last):
File "/share/pyTivo/pyTivo.py", line 21, in <module>
import httpserver
File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 16, in <module>
from Cheetah.Template import Template
File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 23, in <module>
import new # used to bind methods and create dummy modules
ImportError: No module named new

[/share/pyTivo] #

I'm running Python 2.7.12.1. Perhaps a Python update broke things, dunno. I would really appreciate being pointed in the right direction. It appears to get stuck at line 21 trying to import the httpserver?

I can run pyTivo on a RPi, but then I have to SAMBA the /movies share, and performance is terrible .


----------



## Allanon (Nov 2, 2005)

Are you sure you're using Python version 2.7? The problem you are having is the new module is missing, it was depreciated in version 2.6 but still present in version 2.7 but was removed from version 3. The module is a built in module that should be present when Python 2.7 is installed.


----------



## hmspain (Oct 11, 2015)

Allanon said:


> Are you sure you're using Python version 2.7.10? The problem you are having is the new module is missing, it was depreciated in version 2.6 but still present in version 2.7 but was removed from version 3. The module is a built in module that should be present when Python 2.7.10 is installed.


My QNAP supports both 2.7.12.1 and 3.5.2.0. I think I had both installed (strange as that sounds). Right now, I have only the 2.7.12.1 installed.


----------



## Allanon (Nov 2, 2005)

hmspain said:


> My QNAP supports both 2.7.12.1 and 3.5.2.0. I think I had both installed (strange as that sounds). Right now, I have only the 2.7.12.1 installed.


Might check if your Python paths are correct.


----------



## hmspain (Oct 11, 2015)

Allanon said:


> Might check if your Python paths are correct.


Excellent thought; let me check.

Env|grep -i py

Returns blank???

The top of my pyTivo.py file is:

#!/usr/bin/env python

Checking to see if it exists, or is the wrong version perhaps?

/usr/bin/env python

Returns Python 2.7.5 (default, Sep 1 2017, 02:44:59)
[GCC 4.9.2] on linux2


----------



## hmspain (Oct 11, 2015)

echo $PYTHONPATH

Returns blank...

Hmmm.

It appears I have a few symbolic links in /usr/local/bin

python pointing to /mnt/etc/opt/Python/bin/python
python2 pointing to /mnt/etc/opt/Python/bin/python
python2.7 pointing to /mnt/ext/opt/Python/bin/python2.7


----------



## Dan203 (Apr 17, 2000)

Even if you can get this to run pyTivo requires an executable of ffmpeg to remux/recode as needed. Even if you only intend to use it to serve .tivo files, which don't need any processing, it still requires ffmpeg as it uses it as part of the server routine to determine if a file, even a .tivo file, is compatible with the TiVo you're sending it too. Not sure you'll have much luck finding a version of ffmpeg built for the chip in your Qnap.


----------



## hmspain (Oct 11, 2015)

It’s been running (for more than a year) just fine. I did a reboot last night, and ever since... well. I think I had everything configured OK, I’m just chasing what has changed.

I have to suspect some update, perhaps to Python.

My QNAP is a fairly high end running a quad-core Intel Core i7-4790S 3.2 Ghz (Turbo boost to 4 GHz) processor.

The reasons for continuing to fight this one:

1) I tried running on a RPi using Samba to mount the QNAP share, and the performance was poor and spotty (as I recall).

2) Running pyTivo on the same system that hosts the VOB files (for my Tivo) just kinda makes sense to me.

3) It has been running forever, so I know (at least I think I know) it should work...


----------



## Dan203 (Apr 17, 2000)

Interesting. Did you find a build of ffmpeg that runs on the Qnap? Do you have one of the really high end Qnaps that have the Intel processor?


----------



## hmspain (Oct 11, 2015)

Doing a quick reboot for the latest firmware. A reboot broke it, perhaps another will fix it LOL.


----------



## hmspain (Oct 11, 2015)

My QNAP is a fairly high end running a quad-core Intel Core i7-4790S 3.2 Ghz (Turbo boost to 4 GHz) processor.


----------



## Dan203 (Apr 17, 2000)

hmspain said:


> My QNAP is a fairly high end running a quad-core Intel Core i7-4790S 3.2 Ghz (Turbo boost to 4 GHz) processor.


That makes sense then. I have one, but it's one of the cheaper ARM ones. I tried running Plex on it once and it couldn't do anything because it couldn't transcode.


----------



## hmspain (Oct 11, 2015)

The ffmpeg running on my QNAP is in;

/mnt/ext/opt/medialibrary/bin/ffmpeg

I don't recall where I found it, sorry!

[/share/pyTivo] # /mnt/ext/opt/medialibrary/bin/ffmpeg
ffmpeg version 2.8.5 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --enable-cross-compile --arch=i686 --target-os=linux --disable-yasm --disable-static --enable-shared --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libvo-aacenc --enable-libsoxr --enable-version3 --enable-nonfree --disable-decoder=ac3 --disable-decoder=ac3_fixed --disable-decoder=eac3 --disable-decoder=dca --disable-decoder=truehd --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=eac3 --disable-encoder=dca --extra-ldflags='-L/root/daily_build/64_23/4.3.3/Model/TS-X71/build/RootFS/usr/local/medialibrary/lib -Wl,--rpath -Wl,/usr/local/medialibrary/lib' --extra-cflags='-I/root/daily_build/64_23/4.3.3/Model/TS-X71/build/RootFS/usr/local/medialibrary/include -D_GNU_SOURCE -DQNAP' --prefix=/root/daily_build/64_23/4.3.3/Model/TS-X71/build/RootFS/usr/local/medialibrary
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'
[/share/pyTivo] #


----------



## hmspain (Oct 11, 2015)

The reboot didn't fix pyTivo BTW .


----------



## hmspain (Oct 11, 2015)

Is it possible that Python 2.7.12.1 broke something? Perhaps I can roll back.

Can pyTivo use Python V3.5.2.0?


----------



## Dan203 (Apr 17, 2000)

There is a user on this forum who branched pyTivo and upgraded it to run in python 3.x. I can't remember who it was though


----------



## hmspain (Oct 11, 2015)

The best experts say to stick with Python V2. Trying to fix this, I reset my QNAP, and I’m restoring the applications one by one. No luck so far.

It keeps looking for an oddly named module “new”. It is supposed to be in 2.6 (which I tried by downgrading Python) and it should be in 2.7 which I’m running now.

I’m quickly running out of things to try other than breaking out my old RPi and getting Samba back online...


----------



## wmcbrine (Aug 2, 2003)

Dan203 said:


> Even if you can get this to run pyTivo requires an executable of ffmpeg to remux/recode as needed.


Actually, pyTivo can run without FFmpeg. In that case, it falls back on the filename extensions to decide if files are compatible.

And yes, there are FFmpeg builds for ARM. My NAS even came with one (actually avconv), although it's limited in functionality.


----------



## hmspain (Oct 11, 2015)

Thank you Dan203! I’m still fighting the good fight on my QNAP trying to get pyTivo back online. It seems to be struggling with the module “new” even though by all appearances, I’m running Python V2.7. Even the pyTivo.py code checks the Python version!

But it says it can’t find a module “new”. The module “new” was replaced by the “types” module in V3, so I made a backup and commented out the “new” module and added a “types” module.

It is getting farther, but still complaining about the “new” module inb other parts of the pyTivo code. I think I made a mistake of using a QNAP app packed up by someone... the files are still in there and being used even though the pyTivo I’m running is in a /share/pyTivo directory.


----------



## wmcbrine (Aug 2, 2003)

hmspain said:


> I'm running Python *2.7.12.1*.


Um...


> The top of my pyTivo.py file is:
> 
> #!/usr/bin/env python
> 
> ...


Not that this is your issue.

There are several problems due to the Cheetah library, which is really overkill for how it's used in pyTivo. But, refactoring it out would be a big project.


----------



## hmspain (Oct 11, 2015)

It runs “kinda”... at least it does not abort, but here is the dialog (HOPING someone can see what I’m missing). Prepare for an eye chart...

File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 158, in do_command method(self, query) File "/share/CACHEDEV1_DATA/pyTivo/plugins/video/video.py", line 481, in QueryContainer t = Template(XML_CONTAINER_TEMPLATE, filter=EncodeUnicode) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1192, in __init__ self._compile(source, file, compilerSettings=compilerSettings) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1480, in _compile keepRefToGeneratedCode=True)  File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 754, in compile mod = new.module(uniqueModuleName) NameError: name 'new' is not defined ERRORyTivo:Exception during request from ('192.168.1.131', 47190) Traceback (most recent call last): File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 593, in process_request_thread File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 334, in finish_request File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 91, in __init__ client_address, server) File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 649, in __init__ File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/BaseHTTPServer.py", line 340, in handle File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 126, in do_GET self.handle_query(query, tsn) File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 173, in handle_query self.root_container() File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 320, in root_container filter=EncodeUnicode) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1192, in __init__ self._compile(source, file, compilerSettings=compilerSettings) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1480, in _compile keepRefToGeneratedCode=True) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 754, in compile mod = new.module(uniqueModuleName)  NameError: name 'new' is not defined ERRORyTivo:Exception during request from ('192.168.1.131', 47191) Traceback (most recent call last): File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 593, in process_request_thread File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 334, in finish_request File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 91, in __init__ client_address, server) File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/SocketServer.py", line 649, in __init__ File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/BaseHTTPServer.py", line 340, in handle File "/root/daily_build/64_23/4.3.3/SysUtil/Python-2.7.5-cross/install_path_full/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 126, in do_GET self.handle_query(query, tsn) File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 173, in handle_query self.root_container() File "/share/CACHEDEV1_DATA/pyTivo/httpserver.py", line 320, in root_container filter=EncodeUnicode) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1192, in __init__ self._compile(source, file, compilerSettings=compilerSettings) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 1480, in _compile keepRefToGeneratedCode=True) File "/share/CACHEDEV1_DATA/pyTivo/Cheetah/Template.py", line 754, in compile mod = new.module(uniqueModuleName) 
NameError: name 'new' is not defined 

The smoking gun appears to be the “name ‘new’ is not defined. It can’t find the new module because it was replaced by the types module, and somehow the new module is not in this version of 2.7.


----------



## Dan203 (Apr 17, 2000)

Can you run pip on the NAS? Maybe you can install the new module that way?


----------



## hmspain (Oct 11, 2015)

Good thought Dan203, but unfortunately pip is an unknown command. I worked around the problem using a Rpi and Samba mounting the share from my QNAP.

I would still ike to get pyTivo running on the QNAP directly... I just wanted to both thank everyone for the awesome help, and let you know I’m up and running albiet slowly .


----------



## Rowan (Jun 29, 2000)

I have had pyTivo running on my QNAP NAS for a few years now. I have been meaning to update the code to use the new code that Dan has and modify the tray program to talk to the NAS instead of the local pyTivo.

The steps I took to install it are:


Install Python 2.7.3 package
Install Qffmpeg (more about this later)
Install my pyTivo.qpkg
Setup the correct paths to movies, music pictures shared folders and set the ffmpeg setting to point to the version thta you just installed. I use: /opt/Qffmpeg/bin/ffmpeg
There are a few Qnap programs that have ffmpeg included but they are all not complied correctly and do not support the features that tyTivo requires. To download the package visit this site: Qnapclub Store: ffmpeg there are lots of versions and the latest ones are for the latest QNAP OS that my older QNAP (TS-259) does not support, so you have to click on the "older versions" tab and select the proper version for the type of NAS you have. You can then download the .qpkg file and install it.

Here is a link to the pyTivo_0.3.qpkg that I created: If anyone wants the source for the qpkg I can zip it up. To build it you need to have the QDK package installed

There is a small issue that sometimes pops up and that is during some OS upgrades/reboots the python program does not always start backup correctly. I just log into the NAS and then open the pyTivo app and at the menu select "restart pyTivo" and it is back up and running again.

Rowan


----------



## hmspain (Oct 11, 2015)

Thank you SO much! I had to try this right away.

I'm running Python 2.7.12.1 (the latest on the 2 branch I guess). If I downgrade Python, the QNAP continues to whine about it being out of date. I tried downgrading it once when I was using my own pyTivo files; no luck.

The best ffmpeg for my QNAP TVS-871 (64-bit) appears to be the latest 3.4.0 64 bit. The site says it was tested with with 4.2.1 (I'm running 4.3.3). I installed it no problem.

I then installed the 0.3 pyTivo package and started it. I can't see a process using "ps -ef | grep -i pytivo", and can't connect to port 9032 using a browser.

Any ideas?


----------



## wmcbrine (Aug 2, 2003)

hmspain said:


> I'm running Python 2.7.12.1


You keep saying this, but your own /usr/bin/env python results say 2.7.5. That's what you're running, at least as far as pyTivo's concerned. NOT 2.7.12.1. And your missing "new" module indicates, further, that it's a broken installation.


----------



## hmspain (Oct 11, 2015)

Good point. I installed the QNAP version of the 2 branch which says 2.7.12.1, but it appears to be 2.7.5 and broken as you say. Is there someplace elese I can go to find the 2 branch Python for QNAP?


----------



## Rowan (Jun 29, 2000)

I guss one thing I forgot to tell you is the application does not auto start so you will have to tell it to start but I think you already did that.

since you have a shell to the box change into the pyTivo qpkg directory, should be: /share/MD0_DATA/.qpkg/pyTivo
This is the place that the the package is installed to, then look at the file pyTivo.sh this is what the QNAP OS calls to control this application.

The start part looks like this:

# make web link here
/bin/ln -sf ${QPKG_DIR}/$QPKG_NAME /share/${APACHE_ROOT}/$QPKG_NAME

#echo "Starting pyTivo server" >> /tmp/pyTivo.log
PID=`cat /tmp/pyTivo.pid`
if [ -n "$PID" ]
then
#echo "Killing [$PID]" >> /tmp/pyTivo.log
kill $PID
sleep 2
rm -f /tmp/pyTivo.pid
fi

cd $QPKG_DIR
*/usr/bin/python $QPKG_DIR/pyTivo.py* &
echo "$!" > /tmp/pyTivo.pid

The web link and for the control in the qnap app software and just redirects to the pyTivo UX, so you can skip that for now. I then check to see if the program is running, if so I kill the currently running copy. I then start up a new copy so try manually starting it by typing in: */usr/bin/python pyTivo.py*
If there are any errors they will show up on the console. Could be your python is not in the usr/bin directory?

You can modify the files in this directory as you see fit and then will not get changed unless you stop or uninstall the application


----------



## hmspain (Oct 11, 2015)

/usr/bin/python says no such file, but plain "python" runs 2.7.5 (I can change the pyTivo.sh file I suppose).

cd to ... /share/CACHEDEV1_DATA/.qpkg/pyTivo

and ... python ./pyTivo.py

gives me:

[/share/CACHEDEV1_DATA/.qpkg/pyTivo] # python ./pyTivo.py
Traceback (most recent call last):
File "./pyTivo.py", line 21, in <module>
import httpserver
File "/share/CACHEDEV1_DATA/.qpkg/pyTivo/httpserver.py", line 16, in <module>
from Cheetah.Template import Template
File "/share/CACHEDEV1_DATA/.qpkg/pyTivo/Cheetah/Template.py", line 23, in <module>
import new # used to bind methods and create dummy modules
ImportError: No module named new
[/share/CACHEDEV1_DATA/.qpkg/pyTivo] #


----------



## Rowan (Jun 29, 2000)

looks like you do not have a good install of python


----------



## hmspain (Oct 11, 2015)

It looks that way. The missing “new” module is a red flag I think.

I used the 2 branch QNAP install for Python. Is there another way?


----------



## hmspain (Oct 11, 2015)

On the theory that my Python install is corrupt, I uninstalled the QNAP "native" version of Phython 2, and installed Python 2 (64-bit) from the Qnapclub Store. It is branch 2, appears to be 2.7.14.0.

/usr/bin/python ... "No such file"

python = 2.7.5


----------



## Rowan (Jun 29, 2000)

If you installed python from a the Qnapclub store then it will be installed under the .qpkg directory, find it and the binary, then use that path instead of /usr/bin


----------



## hmspain (Oct 11, 2015)

Rowan said:


> If you installed python from a the Qnapclub store then it will be installed under the .qpkg directory, find it and the binary, then use that path instead of /usr/bin


Sorry, got all excited and replied via Email...

Thank you for sticking with me!

Getting real explicit on the python location, and the pyTivo location;

/share/CACHEDEV1_DATA/.qpkg/QPython2/bin/python /share/CACHEDEV1_DATA/.qpkg/pyTivo/pyTivo.py

and configuring it... it RUNS!


----------



## Rowan (Jun 29, 2000)

Great to just change the python path in the pyTivo.sh file and then you are all set.


----------



## hmspain (Oct 11, 2015)

Yup, for once ahead of ya . The command line explcitly points to the QNAP Python, and the QNAP pyTivo.

Works a treat!


----------



## hmspain (Oct 11, 2015)

I'm thinking about upgrading(?) my Bolt to Hydra to support IFTTT auto-skip. When Hydra was released, it was supposed to BREAK pyTivo. Is this still the case?


----------



## wmcbrine (Aug 2, 2003)

hmspain said:


> I'm thinking about upgrading(?) my Bolt to Hydra to support IFTTT auto-skip. When Hydra was released, it was supposed to BREAK pyTivo. Is this still the case?


Last I heard, yes.


----------



## hmspain (Oct 11, 2015)

Back again for some more . I'm hoping that wmcbrine or someone can tell me what's wrong.

PyTivo No longer starts on my QNAP. All I can think of is that perhaps Python was upgraded on my QNAP (I think it is still 2.7).

At any rate, pyTivo is not running, and when I invoke pyTivo.sh start, I get;

[/share/CACHEDEV1_DATA/.qpkg/pyTivo] # ./pyTivo.sh start ./pyTivo.sh: line 26: kill: (7014) - No such process [/share/CACHEDEV1_DATA/.qpkg/pyTivo] # Traceback (most recent call last): File "/share/CACHEDEV1_DATA/.qpkg/pyTivo/pyTivo.py", line 3, in <module> import logging File "//share/CACHEDEV1_DATA/.qpkg/QPython2/lib/python2.7/logging/__init__.py", line 26, in <module> import sys, os, time, cStringIO, traceback, warnings, weakref, collections File "//share/CACHEDEV1_DATA/.qpkg/QPython2/lib/python2.7/weakref.py", line 14, in <module> from _weakref import ( ImportError: cannot import name _remove_dead_weakref [/share/CACHEDEV1_DATA/.qpkg/pyTivo] # ls


----------



## hmspain (Oct 11, 2015)

Found the problem! As always, it was Python related. My QNAP says it has 2.7 on it, but just to be sure I removed everything Python FIRST.

Next you go looking on the QNAP store for Python 2. The latest Python 2.7 is under Python Development. They might as well have called it "software stuff". At any rate, when you start to install it, it will show you the 2.7 etc (latest version).

The next hurdle is to change the first line in pyTivo.py to have #!/share... pointing to the 2.7 Python image. Locate it by searching;

cd /
find . -name pyTivo -print

And find the Python image;

cd /
find . -name python -print

Navigate to the Python location. I had to chmod 777 the files to get them to execute.

Once the Python files can execute (test by executing the python image and then ^D to exit), and the pyTivo.py file points to Python, it should execute. I could not get pyTivo to start via the QNAP interface, so I ran it in the background;

cd [pyTivo location]
./pyTivo.py &

Next, go into your browser and restart pyTivo just to be sure things are working.

Good luck everyone! I suspect I may be the only guy running pyTivo on my QNAP at this point LOL.


----------

