1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HME for Python

Discussion in 'Developers Corner' started by wmcbrine, Jan 28, 2008.

  1. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    Thank you - this is exactly what I wanted - I didn't want to have to go through mind - a direct request to pytivo was what I wanted - but I didn't know there was such an interface.

    Now that I can do it this way, it should be complete soon.
     
  2. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    What is the !File! - is that the fully qualified path to the video file? Why the bangs instead of % ?
     
  3. orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    You're welcome! Yep, pyTivo has a listening port that I use regularly.

    Bang is needed in Window's batch when using a FOR loop, and expands variables after the original command line is interpreted. It basically functions the same as percent.

    This is my batch in it's entirety, with an explanation following:
    Code:
    @ECHO off
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET tsn=%1
    SHIFT
    
    :HouseKeeping
    ::-----------------------------------------::
    :: Clean up successfully transferred files ::
    ::-----------------------------------------::
    FOR /f "tokens=2* delims= " %%A IN ('FINDSTR /I /L "\TV\ \Cut" "\\DL380-Server\pyTivo\transfers.txt"') DO (
       SET File=%%B
       CALL :Trim_File !File!
       IF EXIST "!File!"        (2>NUL DEL "!File!")
       IF EXIST "!File!.txt"    (2>NUL DEL "!File!.txt")
       IF EXIST "!File!.xfer"   (2>NUL DEL "!File!.xfer")
       REM IF EXIST "%%~dpnB.mkv"   (2>NUL DEL "%%~dpnB.mkv")
       IF EXIST "%%~dpB\*.nfo"  (2>NUL DEL "%%~dpB\*.nfo")
       IF EXIST "%%~dpB\*.sfv"  (2>NUL DEL "%%~dpB\*.sfv")
       IF EXIST "%%~dpB\*.srr"  (2>NUL DEL "%%~dpB\*.srr")
       IF EXIST "%%~dpB\*.srt"  (2>NUL DEL "%%~dpB\*.srt")
    )
    
    FINDSTR /I /L     "\TV\ \Cut"     "\\DL380-Server\pyTivo\transfers.txt"   >>  "\\DL380-Server\pyTivo\deleted.transfers.txt"
    FINDSTR /I /L /V  "\TV\ \Cut"     "\\DL380-Server\pyTivo\transfers.txt"   >>  "\\DL380-Server\pyTivo\transfers.tmp"
    
    TYPE NUL>   "\\DL380-Server\pyTivo\transfers.txt"
    TYPE        "\\DL380-Server\pyTivo\transfers.tmp"             >>  "\\DL380-Server\pyTivo\transfers.txt"
    
    SORT  /R    "\\DL380-Server\pyTivo\pushed.txt"                /O  "\\DL380-Server\pyTivo\pushed.txt"
    SORT  /R    "\\DL380-Server\pyTivo\transfers.txt"             /O  "\\DL380-Server\pyTivo\transfers.txt"
    SORT  /R    "\\DL380-Server\pyTivo\deleted.transfers.txt"     /O  "\\DL380-Server\pyTivo\deleted.transfers.txt"
    
    DEL         "\\DL380-Server\pyTivo\transfers.tmp"
    
    :Loop
    ::-----------------------------------------::
    :: Process all files until arguments empty ::
    ::-----------------------------------------::
    IF "%~1"=="" GOTO Done
    
    :Look
    ::-----------------------------------------::
    :: Parse conf file looking for containers  ::
    ::-----------------------------------------::
    FOR /F "usebackq delims=[]" %%A IN (`type "\\DL380-Server\pyTivo\pytivo.conf" ^|FINDSTR "["`) DO (
    	FOR /F %%B IN ('ECHO "%~1" ^|FIND /C "%%A"') DO (
    		IF %%B EQU 1 SET Container=%%A
    		IF DEFINED Container GOTO Found
    	)
    )
    ECHO pyTivo container not found.
    ECHO File not pushed.
    GOTO End
    
    :Found
    ::-----------------------------------------::
    :: Container found, create variables       ::
    ::-----------------------------------------::
    SET DisplayFile=%~1
    SET File=%~1
    SET File=!File:*%Container%=!
    SET File=!File:\=/!
    SET File=!File: =+!
    SET ThisPath=%~dp1
    SET ThisPath=!ThisPath:~0,-1!
    
    :MetaData
    ::-----------------------------------------::
    :: Create metadata if there isn't any      ::
    ::-----------------------------------------::
    IF NOT EXIST "%~dpnx1.txt" (
    	IF NOT EXIST "%~dp1\.meta\%~nx1.txt" (
    		"\\DL380-Server\lan path\pyTivoMetaThis.py" -d -p "!ThisPath!"
    	)
    )
    IF NOT EXIST "%~dpnx1.txt" (
    	IF NOT EXIST "%~dp1\.meta\%~nx1.txt" (
    		>"%~dpnx1.txt" ECHO episodeTitle : "%~n1"
    	)
    )
    
    :Push
    ::-----------------------------------------::
    :: Request pytivo PUSH of files using cURL ::
    ::-----------------------------------------::
    IF /I "%tsn%" EQU "TivoS3" (
        SET port=9033
    ) ELSE (
        SET port=9033
    )
    
    IF EXIST "!ThisPath!\Push.Results.txt" DEL "!ThisPath!\Push.Results.txt"
    
    ECHO Pushing: %DisplayFile%
    curl.exe -s -d "Command=Push&Container=%Container%&File=!File!&tsn=%tsn%" "http://DL380-Server:%port%/TivoConnect?" >>"!ThisPath!\Push.Results.txt"
    
    FOR /F "tokens=5,12,16 delims=^<^>" %%A IN ('FINDSTR /R "\<<.>\>" "!ThisPath!\Push.Results.txt"') DO (
    	@ECHO %date:~-10% %time:~0,8% %%A >>"!ThisPath!\Push.Results.txt"
    	@ECHO %date:~-10% %time:~0,8% %%B >>"!ThisPath!\Push.Results.txt"
    	@ECHO %date:~-10% %time:~0,8% %%C >>"!ThisPath!\Push.Results.txt"
    )
    
    :End
    ::-----------------------------------------::
    :: File is done, go get next one           ::
    ::-----------------------------------------::
    SHIFT
    GOTO Loop
    
    :Done
    ::-----------------------------------------::
    :: Files done. Go back from wence you came ::
    ::-----------------------------------------::
    EXIT /B
    
    :Trim_File
    SET File=%*
    GOTO :EOF
    
    The batch would be called like this: Push.To.TiVo.bat <TiVo name> "<Full path to video file>"

    The first part of the batch sets up the environment, and gathers the TiVo name I want to push to from "%1", and then "shifts" that first argument away.

    The "Housekeeping" section reads a text file created by a pyTivo hack that lists successfully transferred files, and deletes a variety of different files within my "TV" and "Cut Programs" directories only. This is merely a disk maintenance step, and not really pertinent to the "push" functionality.


    The "Loop" section is only there if I want to push more that one file.


    The "Look" section parses through the pytivo.conf file, looking for pyTivo Share names (or container) that are found within the path of the file I'm trying to push. If a Share name can't be found, the batch ends since pyTiVo wouldn't know where to find the file to push.


    The "Found" section manipulates the "File" variable derived from the file path, starting at the container name, making it "url" friendly by replacing spaces with pluses, and back-slashes with forward-slashes. As an example, with TV being the name of a Share or container:

    File="C:\Videos\TV\Smallville\Clark Kent goes to Washington.mpg"
    would turn into:
    File="/Smallville/Clark+Kent+goes+to+Washington.mpg"

    pyTivo already knows that the "TV" container is rooted at "C:\Videos\TV" from the conf file.


    The "MetaData" section should be self explanatory.


    The "Push" section starts off by selecting a port number based on TiVo name. I've had occasion where I needed two instances of pyTivo running to connect to an alternate mind server (NTTABs).

    I log the results of the push in a text file, so some clean up is done to allow this.

    Next, cURL is used to actually make the push request to pyTivo, with the results captured into the text file.

    After variable substitution:

    curl.exe -s -d "Command=Push&Container=%Container%&File=!File!&tsn=%tsn%" "http://DL380-Server:%port%/TivoConnect?"

    would look like:

    curl.exe -s -d "Command=Push&Container=TV&File=/Smallville/Clark+Kent+goes+to+Washington.mpg&tsn=TivoS3" "http://DL380-Server:9033/TivoConnect?"


    The "End" section shifts the file name argument out, and goes to the Loop label to start all over.


    The "Done" section will actually exit the batch file once all files have completed.


    The "Trim_File" section merely drops trailing blanks from the file name, and only relates to the "Housekeeping" section.
     
  4. NatasNJ

    NatasNJ Bone marrow lover!

    11,558
    3
    Jan 7, 2002
    Philly
    Not sure if this is the right place to ask but figured it can't hurt.

    I installed and had pyTivo running for months on end with no problems. Well tonight I went into my list and no longer see the WHS icon. Both my TivoHD's don't see it they BOTH however see the HP WHS EX495 Server which is where my WHS pytivo videos are housed.

    So I don't think it is a connection (wifi) issue since I can see and access the EX495. I tried rebooting the TIVO. No luck.
    I tried logging into the EX495 and stopping/starting the Pytivo service. No luck.
     
  5. orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    Here would be the place to ask: http://www.tivocommunity.com/tivo-vb/showthread.php?t=328459
     
  6. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    OK - so I incorporated orangeboy's suggestion into the code, and now I can send the push request to pytivo. I even get back the response that the file is queued. However, the blue light never comes on and the push never occurs. This happened late last night and I haven't had a chance to diagnose it yet. This morning before I left for work, I logged onto my NAS, emptied the pytivo log file, fired up the HME script and requested a push. Again, I got the "queued for push" message. I wasn't able to wait to see if the push started - I had to leave for work. But I'll check this evening and report my findings. This way, the log file should contain ONLY messages dealing with my push request, so hopefully there'll be fewer messages to focus in on.

    If I'm still baffled, I'll post my code, program output, and log file contents.
     
  7. Apr 3, 2011 #147 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    OK - I have put the first version of my HME application up on github. The installation instructions are in the included README file, but basically, this program is meant to be run under wmcbrine's python HME. WIth it, you can request that videos be pushed to your tivo. You can also delete files.

    Be kind with your criticism. Although a programmer for 30+ years, OO programming has never been my strong suit. Also, this is my first use of Python, so I'm still learning the finer points of the language.

    The source code can be found here.

    Thanks
     
  8. Apr 3, 2011 #148 of 231
    orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    Bah. I can't get ConfigParser to open config.ini. This is even in HME's "start.py". With no config.ini being available, I get "No Tivos found - exiting".

    Windows XP,
    python 2.6.6
    python HME v0.19
     
  9. Apr 3, 2011 #149 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    My screw-up. It's there now.
     
  10. Apr 3, 2011 #150 of 231
    orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    No worries. I used the info out of the Readme. I'm just having issues with HME for Python, and not necessarily your app!
     
  11. Apr 3, 2011 #151 of 231
    orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    I added this to __init__.py close to the beginning (at line 25):

    Code:
    p = os.path.dirname(__file__)
    
    and altered the Images class:
    Code:
    class Images:
    	def __init__(self, app):
    		self.Background = Image(app, os.path.join(p, 'background.png'))
    		self.CueUp      = Image(app, os.path.join(p, 'cueup.png'))
    		self.CueDown    = Image(app, os.path.join(p, 'cuedown.png'))
    		self.CueLeft    = Image(app, os.path.join(p, 'cueleft.png'))
    		self.HiLite     = Image(app, os.path.join(p, 'hilite.png'))
    		self.MenuBkg    = Image(app, os.path.join(p, 'menubkg.png'))
    		self.IconFolder = Image(app, os.path.join(p, 'folder.png'))
    		self.IconVideo  = Image(app, os.path.join(p, 'video.png'))
    
    This alleviated this problem in Windows:
    Code:
    IOError: [Errno 2] No such file or directory: 'vidmgr/background.png'
    
    I like what I see so far!

    I ended up hard-coding the *full path* to my config.ini in Start.py to get ConfigParser to work.
     
  12. Apr 3, 2011 #152 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I didn't have any such problems on my system. Did you organize your files differently than what wmcbrine was expectiing? On my system, vidmgr was a subdirectory of the main pyhme directory.

    In any event, I felt that the changes you suggested make the code more defensive and so they have already been added to the repository.
     
  13. Apr 3, 2011 #153 of 231
    orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    I put vidmgr as a subdirectory, too. It may be an issue with embedded spaces in the path. I had problems with HME for Python's start.py finding config.ini as well. Here's the result of a Window's "Tree" command:
    Code:
    Sun 04/03
    19:30:00=>Tree /A /F "D:\Program Files\HME for Python .19"
    Folder PATH listing for volume Recovery
    Volume serial number is 006E006F 7887:9D2E
    D:\PROGRAM FILES\HME FOR PYTHON .19
    |   config.ini
    |   hme.py
    |   hme.pyc
    |   metadata.py
    |   metadata.pyc
    |   README.txt
    |   start.py
    |   Zeroconf.py
    |   Zeroconf.pyc
    |
    +---animate
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---clock
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---effects
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---fontinfo
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---hello
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---picture
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---test
    |       back1.jpg
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---tictactoe
    |       bg.jpg
    |       grid.png
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    +---transition
    |       icon.png
    |       __init__.py
    |       __init__.pyc
    |
    \---vidmgr
            background.png
            cuedown.png
            cueleft.png
            cueup.png
            folder.png
            hilite.png
            icon.png
            menubkg.png
            pushmsgbkg.png
            video.png
            __init__.py
            __init__.pyc
    
    Regardless, I'm "pushing" from the TiVo interface! I like it! :up::up::up:
     
  14. Apr 3, 2011 #154 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    Glad you like it. I know it still has a few rough edges, but I thought I'd get it out there.
     
  15. Apr 4, 2011 #155 of 231
    Allanon

    Allanon Member

    580
    0
    Nov 2, 2005
    Jbernardis, worked fine for me and I didn't have to modify the code, good work. I really have no use for this program since I usually just push from my computer once I download a video or use pyTivo's interface from the Tivo. I don't think I ever was at my Tivo thinking I really need to send a video to the other Tivo right now. What I really could use is a program that allows me to transfer a show from the Tivo I'm watching to another Tivo on the network. I know this could probably be done by downloading the show then pushing it to the other Tivo but that would probably take a lot longer than a MRV transfer. Is there anyway to fake a Tivo MRV file request?
     
  16. Apr 4, 2011 #156 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    Thanks for the kind words!

    Regarding your request, I can't imagine how you would fake out the receiving tivo. The sending tivo - yes - but the receiving tivo is the one usually initiating the request, so to have it suddenly be presented with an inbound MRV request? I don't know how that would be done.

    OTOH, you could as you suggest, write an HME app to initiate a pull to the HME server and then a push to the recipient tivo. This sounds pretty complicated, and it would take a while since the transfers would have to take place successively.

    Regarding code modifications, I THINK orangeboy's issue was that the pyhme directory was not the current directory. After thinking about it, I think that would cause the symptoms he describes.
     
  17. Apr 4, 2011 #157 of 231
    orangeboy

    orangeboy yes, I AM orangeboy!

    4,083
    0
    Apr 19, 2004
    East Moline, IL
    That makes sense. I was invoking start.py from a command line:

    Code:
    Sun 04/03
    19:43:08=>"D:\Program Files\HME for Python .19\start.py"
    HME Server for Python 0.19
    Sun Apr 03 19:43:10 2011 Server Starts
    Registering: vidmgr
    
     
  18. Apr 4, 2011 #158 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I created an init.d startup script that changes into the installation directory before trying to start up hme. Basically it's the same script I use to start up pytivo - I just changed the directory and all occurrences of pytivo.py to start.py. I can post it when I get home if you're interested.

    All that remains is to hook it into the actual system startup - I just wanted to be sure it was somewhat stable before I did that.
     
  19. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    WOW. Finally got around to installing this and getting it working. THANKS!

    Any chance you could enhance the app to display thumbnails and moviesheets for selection of items rather than a simple list? Tools for the creation of the moviesheets etc already exist, the app would need to display them. Let me know if this is something you could or would like to do, I am quite willing to help where I can.
     
  20. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    If you could give me some more information on moviesheets, I'll let you know. I'm not sure what they are or what would be involved in doing what you ask.

    As far as thumbnails are concerned, I'm not sure I want to get into that. I am already leery of how long it takes to process each directory as they are traversed. Adding something like this (real-time processing of a video file) could be too expensive.

    Of course I guess we could generate the thumbnails separately and just display them. I can experiment with something over the next few days to see what might be possible. I'm thinking that we need to define the image size, but if I find a file in the current directory with the same basename as the video file, but with an extension of say .jpg, then I could display it, perhaps instead of the ubiquitous dot. If no such file, just the dot gets displayed.
     

Share This Page