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. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    Crazy.2008.720p.mp4_sheet.jpg

    Crazy.2008.720p.jpg

    Check out a tool called Thumbgen. Its popular for use in generating thumbnails and moviesheets for the WDTV Live media player and others. It auto gathers the information and graphics from various web sites and assembles the sheet and thumbnail files. The player just associates the media file name with the two jpg files using the name convention shown in the two examples attached.

    The files all have to be generated before hand, not on the fly so there is little overhead. By example the processer in the WDTV Live is much less powerful than the tivo.

    On the WDTV live, the thumbnails are displayed in a row across the bottom and the movie sheet is displayed for the thumbnail currently selected and changes as the arrow keys are pressed to move to a different thumbnail.

    This is what I had in mind but realize its a big step. Perhaps just the thumbnail to start?
     
  2. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I played around with a simple thumbnail - I generated a 57x32 png file from a video snapsnot. (57x32 maintains the 16x9 aspect ratio and is as tall as I could get in the existing 32 pixel height of the current screen design).

    It actually wasn't that good. First of all, the HME as I understand it only gives you an SD resolution of 640x480. This has two issues: 1) limited resolution and real estate, amd 2) the image is actually stretched to fit onto a true 16x9 display. I am not at this time interested in making such massive changes to the interface I presently have.

    I might consider adding a screenshot to the video details page where I have more real estate to play with. This is more in line with your example anyway.
     
  3. wmcbrine

    wmcbrine Ziphead

    10,366
    22
    Aug 2, 2003
    That's the default, but it's not limited to that. See the "picture" example app, Reversi, and HME/VLC for programs that do HD using HME for Python. For most cases you can use the handle_resolution() function from the picture app. (1280x720 is the highest HME resolution for Series 3 and 4... this is the resolution for the text and graphics overlay, not to be confused with the background video, which is independent of the overlay's resolution.)

    BTW, you also need to be aware of the "safe areas", which currently your app is not -- text should be within the title-safe area. (On my TV, your title is partly off-screen.)

    Re: thumbnail images, we added the "image" keyword to the pyTivo metadata spec for the benefit of Streambaby, so you could use that. I've never heard of this "moviesheet" thing, and would be curious to know more.

    If you're going to continue developing this app, maybe it should have its own thread?
     
  4. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    Here is a forum topic that discusses moviesheets as relates to the WDTV series of media players. Includes templates for many user generated formats, how to's etc. If I can help in any way, I'd be glad to.

    http://forum.wdlxtv.com/viewforum.php?f=18

    I mostly got involved with the WDTV Live as it was one of the few hardware media players that could play HD mp4 files with ac3 audio in the same format as Tivo. As all video is stored on our server in this format, this becomes a tivo extender box of sorts. it has a bunch of additional capability for other things as well that I really have not made use of. It does a great job of presenting and playing tivo compatible video files in our motorhome though.
     
  5. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    It was never my intent to continue to develop this app. This is exactly what I feared when orangeboy convinced me to post it. The source code is there - people can take it and do what they want with it. It does what I want it to do and I'm not interested in making it everything for everyone.

    I WILL look into the HD resolutions, because that is what my TV's are - so thanks for that. But, for example, I will not be interested in making the app "sense" its environment and operate in SD mode for some or HD mode for others. It is what it is.

    I will also investigate the use of safe areas. I noticed the safe areas on the simulator, but frankly didn't pay them much attention (again - it was working fine on MY tv's).

    If I post an update to the app, I will do so in a separate thread. I had thought that all along.
     
  6. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    No problem. I really appreciate what you have contributed so far as do others. I can full well understand not wanting to take on someone ELSES project when it was just something you needed and decided to share. Please let us know if you implement the HD interface as that would greatly enhance the look of the menus.
     
  7. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    Question: just playing around with the HME, I was trying to play an mp3 file. The interface to the Stream class wants a URI though - not a simple file name. I tried every variant of the 'file;' URI that I could think of. I took a look at the examples, but there is no example of playing an MP3. I looked at the Tivo Java HME documentation and sample code, and tried changing the URI to the base URI of the app followed by a file path, but nothing I did seemed to work.

    How do I provide a file to the Stream class???

    If I am able to implement what I am thinking, this will ultimately run on my NAS in a linux environment. Right now, however, I am developing/debugging in Windows 7.
     
  8. wmcbrine

    wmcbrine Ziphead

    10,366
    22
    Aug 2, 2003
    Take a look at HME/VLC to see how it's done. (I get the feeling, based on some of the other things you did with your app, that you've never looked at it. You really should.)

    The key is to define "datapath" (a command-line or config.ini option for start.py). As it says in start.py, "The default is to not allow any access outside of the app directories." I designed this as a security feature, so that one could put up an HME app without unintentionally exposing one's whole drive to the Internet. HME/VLC sets the datapath to "/" by default instead, with the idea that it will only ever be run on a LAN, and this will make configuration easier. But the whole system doesn't play well with Windows and its stupid drive letters -- basically, you can only expose one drive at a time with start.py. (However, you can have apps on one drive, and data on another.)

    Here's the core part where a file path is converted to a URL by HME/VLC (in hmevlc/__init__.py):

    Code:
    url = url.replace(self.context.server.datapath, '', 1)
    url = 'http://%s/%s' % (self.context.headers['host'],
                            urllib.quote(url.encode('utf-8')))
    The conversion back (on receiving a request) is handled by start.py.

    P.S. Oh, but when you said you "tried changing the URI to the base URI of the app followed by a file path" -- that should have worked, even without setting the datapath. I guess I'd have to see exactly what you were sending to know why it didn't work, but if you can see the "icon.png" requests in your log, those are the right form (and if you're seeing an icon, then it's working).
     
  9. lrhorer

    lrhorer Active Member

    6,924
    0
    Aug 31, 2003
    San...
    Fair enough, but the app could definitely use a little development. So far, the one thing I see that the app really needs is a "Please wait" splash when it receives a valid command. Often it takes quite a while - 30 seconds or more - to implement the received command. During that time, the user is unsure if the system is processing the command, or if the command was just lost. Lost commands are extremely common with IR control systems, so even in the very short time I have been testing this app, I have several times inadvertently entered several commands into the command buffer, not knowing whether the unit had recognized the button press, or not.

    I'm also having a problem with the system locking up whenever I try to go into a particular one of the shares. I need to investigate.

    Is there anyone out there who would like to pick up development of this app and maybe start a development thread?
     
  10. lrhorer

    lrhorer Active Member

    6,924
    0
    Aug 31, 2003
    San...
    Question: If I hard restart pyTivo - that is to say completely kill the python process and start it again, should I re-start pyhme?
     
  11. wmcbrine

    wmcbrine Ziphead

    10,366
    22
    Aug 2, 2003
  12. Jun 3, 2011 #172 of 231
    Allanon

    Allanon Member

    580
    0
    Nov 2, 2005
    Wmcbrine, I am using your Apples and Oranges ListView code from HME/VLC Video Streamer. It works fine except when trying to change icons from one menu to another. The only modification I made was to go fetch the icon from a web server, save it to disk, and then assign the image as a icon. Here is the code I changed:

    Code:
      def redraw(self):
            hme.Color(self.app, 0xcfcfcf)
            count = 0
            for i, item in enumerate(self.items[self.startpos:self.startpos +
                                                self.pagesize]):
                self.page[i][0].remove_resource()
                self.page[i][0].set_text(item['title'], flags=hme.RSRC_HALIGN_LEFT)
                if 'icon' in item:
                    name = 'tempicon'+str(count)+'.png'
                    urllib.urlretrieve(item['icon'],name)
                    im = Image.open(name)
                    newim = im.resize((self.icon_width, self.bar_height))
                    newim.save(name, "png")
                    self.page[i][1].set_image(name)
                    count = count + 1
                else:
                    self.page[i][1].clear_resource()
            hme.Color(self.app)
            self.upwin.set_visible(self.startpos > 0)
            self.downwin.set_visible(len(self.items) >
                                     self.startpos + self.pagesize)
    
    This works fine on the first menu but when I select a menu item and go to the next menu then the icons are the same as the first menu. If there are more menu items in the second menu then it displays icons from the first menu for however many menu items were in the first menu and displays the correct icons for the remaining menu items. If I page down then page back up in the menu then the icons are shown correctly.

    I tried removing and clearing the resource before setting the image but that didn't help. The only thing that seems to work is to call redraw twice then the menu icons are correct. Is there a better way to update the icon images?

    Also, do you think it would be advantageous to do all the menu, text, and icon drawing to one or two large bitmaps then write them to the Tivo opposed to writing a lot of small bitmaps to the Tivo and have it position them and the text? I could just move a semi-transparent view over the bitmaps to act as a menu selection bar. The program I'm working on can have a lot of menu items with a lot of different icons.

    Another question: Do you know of a way to download a bitmap from the web and send it to the Tivo without writing it to a local hard drive? It would be great if I didn't have to save the icon images to disk before sending them to the Tivo.
     
  13. Jun 3, 2011 #173 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I looked at the sample animation applet that comes with the python HME, and it appears to be reliant of the main app processing its message loop. Am I right in saying that if I am doing a busy task, I would need to periodically yield control so that the waiting internal "send_keys" can be processed. If I don't yield control, only the initial animation would occur, and the send key event would not be processed until my task was completed.

    If this is true, one thing that occurs to me would be to have a long-running animation - one that would cover the longest duration I would reasonably expect. But if my task completes before that animation completes, would I be able to stop the animation by just making its view invisible (or something along those lines)?

    Otherwise, I can just use a static view for my purpose.
     
  14. Jun 3, 2011 #174 of 231
    wmcbrine

    wmcbrine Ziphead

    10,366
    22
    Aug 2, 2003
    I'd prefer to leave redraw() (and the rest of ListView) alone, and build the list of icons beforehand. Anyway, I believe what's happening is that you're reusing cached names, so the HME module sees them as the same, and doesn't resend them to the TiVo.

    In case it wasn't clear from what I said here, I thought that the all-in-one background image "solution" that TiVo used for keyboards in Bananas was goofy. :) So no, I wouldn't think that was better. But it all depends... There are limits on the number of resources you can use, including views, but that's mainly an issue for the Series 2.

    Sure. The hme.Image resource will take three kinds of initializers: name, file object, or actual image data. Incidentally, only the named images are cached, so using one of the other methods would solve your original problem as a side effect.

    urllib will of course also allow you to pull an image directly into memory, without saving it to disk. The sticking point then might be PIL. What I did in pyTivo, to generate thumbnails in the photo plugin, was to work around that by using StringIO():

    Code:
    out = StringIO()
    pic.save(out, 'JPEG')
    encoded = out.getvalue()
    out.close()
     
  15. Jun 3, 2011 #175 of 231
    wmcbrine

    wmcbrine Ziphead

    10,366
    22
    Aug 2, 2003
    Yes. But that's what threads are for.

    The "Loading..." screen in HME/VLC gives a nice example of an animation running while waiting on something else to happen, although it doesn't depend on threads, because both processes are asynchronous. Note in particular loadbar_anim() in hmevid.py. What happens is that it first checks if the animation is active, and if so, it updates it and schedules another callback. Meanwhile, the main event (loading the stream) sends its own event when it's done, which causes HME/VLC to remove the animation, setting loadbar = None. loadbar_anim() is then invoked again, as expected, at its next scheduled time, but it sees that the loadbar is inactive, so it does nothing, and no more calls to it are scheduled.
     
  16. Jun 4, 2011 #176 of 231
    Allanon

    Allanon Member

    580
    0
    Nov 2, 2005
    Wmcbrine thanks for the reply, you were correct when suggesting the problem was due to reusing cached names. I also used your advice and now the icon images are read from the web to memory and then to the Tivo without writing to local storage. Thanks again.
     
  17. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    I could use some help getting HME for Python running correctly under linux on my Synology NAS. If it matters, the shell is BusyBox v1.16.1 and its an x86 Intel Atom based NAS.

    If I start HME from a command line using these two commands:

    Code:
    cd /usr/local/pythonHME/
    nohup /opt/bin/python /usr/local/pythonHME/start.py
    It starts and runs fine.

    If I create a startHME.sh script file and run it at boot up by placing it in the /usr/syno/etc/rc.d/ directory;

    Code:
    `sleep 60`
    cd /usr/local/pythonHME
    /opt/bin/python /usr/local/pythonHME/start.py > /usr/local/pyhme.log 2>&1 &
    HME for python starts but it ignores the config file. running the script from a command line yields the errors:

    Code:
    : not foundtc/rc.d/startHME.sh: line 1: 
    /usr/syno/etc/rc.d/startHME.sh: cd: line 2: can't cd to /usr/local/pythonHME
    : not foundtc/rc.d/startHME.sh: line 3:
    Suggestions and help?
     
  18. windracer

    windracer joined the 10k club

    11,580
    3
    Jan 3, 2003
    St. Pete, FL
    Do you need to invoke a shell in Busybox like in Linux? In other words, do you need something like
    Code:
    #!/bin/sh
    on the first line of your script so it invokes the interpreter?
     
  19. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    The other question is what are the permissions on the directroies and what user ID is being user interactively versus at boot-up.

    If you cd to /usr/local and do 'ls -ld pythonHME' what do you see

    incidentally - did you make a mistake when you copied the sleep error message - your posting just says 'leep' not 'sleep'. Did you edit the file correctly when you removed the ticks?

    One other thing - are you editing this file on windows and transferring to Linux, or are you editing on Linux. I have seen situations where a file transferred from a PC to Linux has CR/LF at the end of every line - and thtis has thrown off various shell interpreters.

    DO you have the od command available? If you try 'od -c startHME.sh' what do you see'?
     
  20. jcthorne

    jcthorne Active Member

    2,721
    3
    Jan 28, 2002
    Houston
    This is the result of that query:

    drwxr-xr-x 12 root root 4096 Jun 16 09:20 pythonHME

    No, that is what is so strange, without the ticks, it gives that error message with the missing s. With the tick marks the sleep command actually runs, executed in the script either at boot up or in the command line.

    This may be the problem. Yes I am using notepad in windows to edit the scripts and then cp them into place on the NAS. I do not know how to edit the file from the NAS side command prompt. Any suggestions for editor on either side that I can use/install?

    -ash: od: not found
     

Share This Page