# Photo module for pyTivo



## wmcbrine (Aug 2, 2003)

Edit: Go here for the latest version. It fixes most of the problems described below.

Seriously, unless you're just into historical curiosities, *don't* bother with the version attached to *this* message, or any of them except for the latest. But do note the bit about the Python Imaging Library.

------------------------------

Here's my first stab at a "Photos" module for pyTivo. Now it's got all the HMO services covered.  I wrote this against the December 4th version of pyTivo... I might do a backport as well.

To use this, you need the Python Imaging Library. Get it from your distro, or go here:

http://www.pythonware.com/products/pil/index.htm

The Good: Aspect ratios are correct, even for 16:9 (but see below). My pictures never looked right with Tivo Desktop, IIRC.

The Bad: The aspect ratio is hardwired -- I want to change it automatically for 16:9 and 4:3, but I haven't worked that out yet. In the meantime, you can edit it at the top of photo.py: if you're using a 4:3 TV, comment out the 16:9 PIXEL_ASPECT line, and uncomment the 4:3 line.

The Ugly: Performance really drags on folders with a lot of pictures, apparently due to the way the Tivo builds a list for slide-show purposes. (That's only when you do "View photo"; thumbnails are fast.) I'm not sure if I can do anything about it. In extreme cases, pictures may fail to come up at all.

In the (short!) course of developing this, I found that sending too large an image can instantly reboot the Tivo, no questions asked. But that shouldn't happen with this version. 

This should support HD resolutions if you have the HD Photos HME app, but I haven't tested that. (It switches to 1:1 aspect ratio if the request is for a size larger than SD.)


----------



## wmcbrine (Aug 2, 2003)

P.S. Supported formats... anything readable by PIL, which is practically anything. Currently it filters on .jpg, .gif, .png, .bmp and .tif, but if you want others, just add them to the "goodexts" tuple.


----------



## wmcbrine (Aug 2, 2003)

P.P.S. Usage... just add a share to pyTivo.conf with "type = photo":

[pics]
type = photo
path = /home/wmcbrine/pictures


----------



## dlfl (Jul 6, 2006)

Cool beans! And what are we both doing up at this ungodly hour!


----------



## wmcbrine (Aug 2, 2003)

When I said thumbnails were fast, I obviously hadn't tried it with really large pictures.  Here's a new version that generates thumbnails faster, and caches them.


----------



## steve101 (Jan 4, 2005)

I installed pil 1.1.6 and unzipped your files to my pytivo
folder. The photos folder shows up on the tivo and when
I select it - it starts to expand but then shows error 5-6
and that's it.

The trace text from the pyTivo window includes:
File "F:\pyTivo\plugins\photo\photo.py", line 110, in QueryContainer
local_base_path = self.get_local_base_path(handler, query)
AttributeError: 'Photo' object has no attribute 'get_local_base_path'


----------



## wmcbrine (Aug 2, 2003)

It sounds like you're not running a recent enough pyTivo. get_local_base_path() is defined in plugin.py, but only after a certain version... I dunno when exactly, but it's in the latest.

This is why I said I might do a backport... in principle there's no reason this can't work with 2.01 or even older, but the interface for pyTivo modules has changed slightly.


----------



## dlfl (Jul 6, 2006)

wmcbrine said:


> It sounds like you're not running a recent enough pyTivo. get_local_base_path() is defined in plugin.py, but only after a certain version... I dunno when exactly, but it's in the latest.
> 
> This is why I said I might do a backport... in principle there's no reason this can't work with 2.01 or even older, but the interface for pyTivo modules has changed slightly.


I believe windows users are currently unable to use the versions that have the get_local_base_path function, i.e., where the use of "full" paths was introduced. This is ticket #52 on the Wiki.


----------



## wmcbrine (Aug 2, 2003)

dlfl said:


> I believe windows users are currently unable to use the versions that have the get_local_base_path function, i.e., where the use of "full" paths was introduced. This is ticket #52 on the Wiki.


I see that now.  I guess I'll take a look at it... Meanwhile, here's my backport of the photo module to pyTivo "d498" of November 25th.

Edit: Hmm, the whole thing works better with d498. The large folder problem kinda just goes away. Interesting.


----------



## dlfl (Jul 6, 2006)

wmcbrine said:


> I see that now.  I guess I'll take a look at it... Meanwhile, here's my backport of the photo module to pyTivo "d498" of November 25th.


Hmmm... Worked partly -- but no photos.

When I selected the photo share name the python window scrolled a huge barrage of messages, too many to try to copy. The page of thumbnails did show up and all the text seemed OK but no images in the thumbnails. When I selected one image, the next page showed up with a large black area where the image would have been and all the normal metadata was present (date taken, etc.) When I selected to view the image, my Tivo rebooted.

Here is the last error dump from the python command window when I selected one of the thumbnails:


> Exception happened during processing of request from ('192.168.0.158', 1332)
> Traceback (most recent call last):
> File "C:\Python25\lib\SocketServer.py", line 463, in process_request_thread
> self.finish_request(request, client_address)
> ...


I'm guessing you've only tested this on linux (?). I suspect the problem may be something like the '/' vs '\' path delimiter difference?

I tried both delimiters in my share path -- no difference in behavior.

Using d498, python 2.5 and pil 1.1.6 for python 2.5


----------



## steve101 (Jan 4, 2005)

Yeah I forgot to mention windows 2000 server.
BTW python 2.5, pil 1.1.6 for python 2.5

Guess I'll wait - I'm moving my server over to
a linux box after some hardware changes are done.


----------



## wmcbrine (Aug 2, 2003)

OK... boy was that a pain. *&@!$^# Windows. And it's not fixed yet...

The failure was on the line

```
pic.save(handler.wfile, 'JPEG')
```
 In Python terms, handler.wfile is a file-like object (it's the http output stream). File-like objects may not have all the properties of a real file, like the ability to seek. In Linux, handler.wfile evidently satisfied Image.save(); but in Windows, it didn't. That was truly bizarre. To get around it, I had to use cStringIO. On the plus side, this should make the thumbnail cache work even faster.

So, that got it mostly working in Windows. But there were still some problems: rotation didn't stick, and sometimes pictures didn't appear, or it would just pop out of slideshow mode for no apparent reason. I managed to fix the rotation, by doing a lot of backslash-to-slash replacing (it made the cache keys match), but I still got the other problems -- and then I hit a reboot. So, I'm giving up for the night. I recommend you _not_ try to use it on Windows at this time.  (None of these problems occur in Linux, nor probably in Mac OS X, etc.)

Anyway, here's what I have right now, minus the ugly backslash-to-slash stuff. Besides the Image.save() workaround, I also reverted to using PixelShape, but doing it correctly this time.  This actually does work automatically with both 16:9 and 4:3 sets, assuming that you have the ratio set in your Tivo's video settings.

This is the "backported" version, which is now the main version, at least until I can get it performing as well under the newer pyTivo.


----------



## wmcbrine (Aug 2, 2003)

OK, I take it back -- a Tivo reboot can still happen even with the photo module running under Linux.  I don't yet know exactly what provokes this behavior, but it's preceeded by a bogus request from the Tivo:


```
GET /TiVoConnect?Command=QueryContainer&Container=pics1&#37;2Factress&Width=634&Height=432&PixelShape=40%3A33&Format=image%2Fjpeg&Rotation=1593802088 HTTP/1.0
```
that mixes elements from the two basic kinds of requests it normally makes (for info, and for pictures). I especially like the "Rotation=1593802088" bit.


----------



## wmcbrine (Aug 2, 2003)

Here's my latest. 0.4 is for the most recent pyTivo release; 0.4b is for d498. They both perform acceptably on large folders now, although d498 is still faster. These also include the path kludges to make them work on Windows.

I wish I could say I'd eliminated reboots, but I can't. I probably won't post another version until I've sorted that out. If you avoid trying to advance past the last picture in a folder from the full-screen ("View photo") view, you can probably avoid reboots. But I can't promise that..


----------



## wmcbrine (Aug 2, 2003)

AFAICT, I've fixed the reboot problem.  When the Tivo asked for a recursive list of files, get_files() was returning a list that included directory names along with their contents. This should probably be fixed in plugin.py, but in the meantime, I've included a replacement get_files() in photo.py.

I also found a more elegant way to deal with the path problems in windows. Instead of a bunch of replace()s, it's just this:


```
if os.path.sep == '\\':
    os.path.sep = '/'
```
I wasn't sure it would work, but it does. The module still seems to act a bit more flaky under Windows than Linux, for reasons undetermined, but I think I can recommend it now.

For now, this is only for the latest pyTivo.


----------



## dlfl (Jul 6, 2006)

Worked great for me! Good job!


----------



## wmcbrine (Aug 2, 2003)

I expect people will be annoyed that I'm posting another version less than three hours after the last one, but I managed a big performance boost in slideshow mode by caching the last recursive lookup. I'm finally happy with the speed now. But please note that this means new pictures in a folder won't show up until you trash the cache, by doing "View photo" in a different directory (or by restarting pyTivo).

Remaining issues: I need to implement the date sort modes; right now it's always alphabetical, despite what the Tivo says onscreen. Also, when scrolling backwards in thumbnail mode, the last item disappears. I see the same thing in the music module. What I don't know is whether Tivo Desktop has the same problem, or if this is a pyTivo problem I can hope to fix. Can anyone with TD answer?


----------



## reneg (Jun 19, 2002)

Tried it out for a few minutes and it worked great. Will play with it some more later this week. :up:


----------



## wmcbrine (Aug 2, 2003)

wmcbrine said:


> What I don't know is whether Tivo Desktop has the same problem, or if this is a pyTivo problem I can hope to fix.


To answer my own question: It _is_ a pyTivo problem, and I _have_ fixed it. However, my os.path.sep hack didn't really work as well as I'd thought. So, I'll spare you version 0.7 while I try to sort that out.


----------



## wmcbrine (Aug 2, 2003)

OK, here's the new version, with much better handling of Windows paths, and no more missing items when scrolling through the thumbnails. But I'm still getting "error #5-6" from the Tivo sporadically when pyTivo is running under Windows (not under Linux, so far), and I can't quite figure it out. It goes away when I try to debug it.


----------



## wmcbrine (Aug 2, 2003)

Tested OK on Mac OS X now, in case you were wondering.


----------



## wmcbrine (Aug 2, 2003)

Much faster thumbnails, much better quality on fullscreen view, and a few more extensions added to the good list:


----------



## wmcbrine (Aug 2, 2003)

This does all the sort modes. I think the module is functionally complete now. (Which isn't to say that it can't be improved!)

I have it sorting folders first only when "Arrange by Type" is On; otherwise they're mixed in with the pictures. Anyone who uses Tivo Desktop, please let me know if this is actually the expected behavior.


----------



## jcthorne (Jan 28, 2002)

First I gotta say GREAT WORK! and THANKS! This is MUCH faster and easier to navigate than the photobucket app that Tivo just added in.

I got the 0.9 version working and have a question if you don't mind.

Is there a way to get this module to display the photos in a higher resolution? It does not appear to be using the HD resolution of the TivoHD at all, resizing to 6xx x 4xx or so.

If you just have not gotten that far OK, just asking in case there is something I should be setting.

It does appear to be navigating my albums directories several layers deep just fine.

When I select a photo, it shows it and offers several options. One of which is 'view slideshow' Selecting that does indeed play a slideshow but it seems to select from all photos in this diretory and others adjacent or at the same level in the tree, not just from within this folder. Is that right?

Is there a way to adjust the rate at which the slideshow advances to the next picture or to manually select next picture?

Thanks again for all your work in adding this much needed piece to pyTivo.


----------



## wmcbrine (Aug 2, 2003)

jcthorne said:


> First I gotta say GREAT WORK! and THANKS! This is MUCH faster and easier to navigate than the photobucket app that Tivo just added in.


Well, it should be faster; it's working over your LAN instead of the public Internet.  As for navigation, that's credit to Tivo -- the HMO picture viewer is a built-in function. My module just supplies the pictures.



> _Is there a way to get this module to display the photos in a higher resolution?_


Unfortunately, like the rest of the Tivo menus, the picture viewer doesn't make use of HD. Only Tivo could change that. My photo module is ready if they do.

The only way currently to get HD pictures on your Tivo is via HME. There's an HD photos HME app that comes with Tivo Desktop, and I understand that some people have gotten it to work with Galleon. (It needs an HMO server as a backend.) It should also work with pyTivo as the backend, but I haven't tested that.

It would be nice to have a Python interface to HME (and I don't mean in Jython)...



> _When I select a photo, it shows it and offers several options. One of which is 'view slideshow' Selecting that does indeed play a slideshow but it seems to select from all photos in this diretory and others adjacent or at the same level in the tree, not just from within this folder. Is that right?_


It should be all photos in subfolders, not folders at the same level. Anyway, this is an option you can turn off -- select "Options" off of the slideshow option.



> _Is there a way to adjust the rate at which the slideshow advances to the next picture_


Yes, that's also in the Options menu.



> _or to manually select next picture?_


In slideshow mode, you can use FF and REV almost as in a video. In "View photo" mode, FF and REV go back and forth between pictures.

P.S. Writing this was actually great fun and a breeze, except for trying to make it work right under Windows (which it still doesn't). But anyway, you're welcome.


----------



## wmcbrine (Aug 2, 2003)

So, I finally tested it with the HD Photos HME app, and it needed a couple of tweaks. (pyTivo was only sending 10 items when no ItemCount was specified -- it should be all items; and I'd set 200x200 as the maximum size to treat as a thumbnail, but the HD app used 225x225. (My module loads thumbnails in "draft" mode, which is much faster.) So now the cutoff is 250x250.)

Also in this version, I decided to use the highest-quality resize, antialias, even for thumbnails. It looks much better, and loading in draft mode makes most of the speed difference anyway.

*How to use the HD Photos app*

See here:

http://www.tivocommunity.com/tivo-vb/showthread.php?p=5032599#post5032599

Where he says, "Make sure TiVo Desktop is running and sharing photos", substitute "pyTivo"; and where he has port 8101, make it 9032 (unless you've changed this in pyTivo.conf). Note that it requires Java 1.5; Java 1.6 (or 6, or whatever Sun is calling it today) will not work, because it doesn't like the certificate the app is signed with.

There seems to be a fear of posting the .jnlp file itself in that thread, although personally I think it's too trivial to be covered by copyright. (It's not the app, just a pointer to it, basically. Like a .ram or .m3u file.) Not to mention that it's part of a package that Tivo distributes for free anyway. But I'd just as soon not be the first to test the issue...


----------



## reneg (Jun 19, 2002)

The .9 version works very well on my system.

From version .9 back to .10, that may confuse some folks between version .1 & .10 in the first post in the thread.

Do you know if there is any support in the Tivo to support metadata for Photos? I'd like to add descriptions to some of my photos.


----------



## wmcbrine (Aug 2, 2003)

reneg said:


> From version .9 back to .10, that may confuse some folks between version .1 & .10 in the first post in the thread.


Don't think of it as a decimal point. It's just a separator (like in a URL). Basically, it's version ten... the "zero dot" meaning "it isn't finished yet".

I did hesitate to call it "0.10", because I had this conversation already ten years ago.  But I'd thought that this kind of version numbering was common enough now that it wouldn't confuse anyone. And calling it "1.0" would be wrong, because there are still a few things I need to sort out before I'd feel comfortable saying "yes, this is a complete substitute for the photo function of Tivo Desktop".



> _Do you know if there is any support in the Tivo to support metadata for Photos? I'd like to add descriptions to some of my photos._


There is a "Caption" tag mentioned in the HMO spec that didn't seem to do anything in the regular viewer when I tried it, but it looks like it may be honored in the HD viewer. I'll look into it further.


----------



## jcthorne (Jan 28, 2002)

I followed the instructions in the referenced link for editing the jnlp file etc. right up to the point that it generated the .jar files. 10 of them.

Need some instructions on what I am to do with them and how to use them to get pytivo to serve HD photos.

I can see the share I named in the hdphotos.jnlp file. Selecting it starts the HD photos ap and shows the share name from pytivo.conf as a folder.

Selecting that folder yields "This folder does not contain any viewable photos" Also of note is that pyTivo shows a message "Bad request synax"

Looking at the responses from pytivo from the HD ap and the SD ap are different in one place. In the working SD ap the share name is called out as:

Container=Thornoli's&#37;20Photo%20Albums%2F2000.....

In the non working HD ap the same share is referenced as:

Container=Thornoli's Photo Albums&....


Seems the spaces are being represented differently and pyTivo does not like the second one.

Thanks


----------



## wmcbrine (Aug 2, 2003)

jcthorne said:


> Need some instructions on what I am to do with them and how to use them to get pytivo to serve HD photos.


No, it looks like you did it right.



> _Also of note is that pyTivo shows a message "Bad request synax"
> 
> Looking at the responses from pytivo from the HD ap and the SD ap are different in one place. In the working SD ap the share name is called out as:
> 
> ...


The "Bad request" message must be from Python's BaseHTTPRequestHandler, and the bad request itself from the HD photos app. Nothing I can really do about either of those... It looks like it's not quoting the request properly. However, I can't reproduce this. I have no problem with directories with spaces in their names. Maybe it's the single quote mark that's screwing it up?

You could try making that directory the base of the share (with a different share name), so it won't be passed on.


----------



## wmcbrine (Aug 2, 2003)

I finally have it working right (i.e., in the same way as Tivo Desktop) when cycling past the beginning/ending pictures AND when in slideshow mode. Previously, I'd managed get it cycling when moving manually, but also ended up with a looping slideshow even when it was set not to repeat. I had to packet sniff Tivo Desktop to see exactly what was going on.

I've about given up on getting it stable in Windows. It works most of the time, but then for no apparent reason, at random (too-frequent) intervals, will give "Error #5-6". Packet sniffing hasn't helped me yet. (It doesn't help that WireShark doesn't recognize these as HTTP transactions, the way it does with Tivo Desktop's. I'd be happy just to fix _that_.) It seems to be more stable with the HD Photos app, oddly enough (no errors yet).

BTW, the HD Photos app will also run in standard def, but I don't recommend it -- it accomodates SD in the way it lays out the screen, but it doesn't compensate for the non-square pixels (no "PixelShape" in its requests).


----------



## wmcbrine (Aug 2, 2003)

wmcbrine said:


> There is a "Caption" tag mentioned in the HMO spec that didn't seem to do anything in the regular viewer when I tried it, but it looks like it may be honored in the HD viewer. I'll look into it further.


Nope, still doesn't work. The HD Photos app does display captions for Flickr, but it doesn't use HMO for those. So, it doesn't look like I can do anything beyond what's there now, except for the Capture date, which I have it reading out of Exif now. (More on that later...)

I'm disappointed that no one's grabbed 0.11 yet... to clarify my comments, it's not any _less_ stable on Windows than any previous version. I was talking about the photo module in general there, not that specific version. 0.11 is better than 0.10 for any platform.


----------



## jcthorne (Jan 28, 2002)

You were right on the spaces and quote mark. Changed to Thornoli_Photo_Albums and it works fine now. Wierd. Giving 0.11 a try now....


----------



## MacerX (Nov 9, 2007)

wmcbrine said:


> I'm disappointed that no one's grabbed 0.11 yet... to clarify my comments, it's not any _less_ stable on Windows than any previous version. I was talking about the photo module in general there, not that specific version. 0.11 is better than 0.10 for any platform.


It is working great for me, at least so far, "The Missing Link"! Thanks

-DB


----------



## MacerX (Nov 9, 2007)

Oh, and I am on Windows XP with a 652-HD and dual 649-S2s.

-DB


----------



## billbobbill (Dec 17, 2007)

I'm having troubles and I'm sure what I am doing wrong. I have my pyTivo on Ubuntu and I installed pil 1.1.6. I unzipped 0.11 to pyTivo folder and now I have a photo folder in my plugins directory. pyTivo works great but when I add the following entry to my pyTivo.conf, it crashes. 

```
[Photos]
type=photo
path=/home/j/media/pics
```
Here is my error message.

```
192.168.0.11 - - [17/Dec/2007 17:08:38] "GET /TiVoConnect?Command=QueryContainer&Container=%2F HTTP/1.0" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.0.11', 1063)
Traceback (most recent call last):
  File "SocketServer.py", line 464, in process_request_thread
    self.finish_request(request, client_address)
  File "SocketServer.py", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "SocketServer.py", line 522, in __init__
    self.handle()
  File "BaseHTTPServer.py", line 316, in handle
    self.handle_one_request()
  File "BaseHTTPServer.py", line 310, in handle_one_request
    method()
  File "/home/j/Desktop/pyTivo/httpserver.py", line 54, in do_GET
    self.RootContiner()
  File "/home/j/Desktop/pyTivo/httpserver.py", line 78, in RootContiner
    self.wfile.write(t)
  File "socket.py", line 255, in write
    data = str(data) # XXX Should really reject non-string non-buffers
  File "/home/j/Desktop/pyTivo/Cheetah/Template.py", line 990, in __str__
  File "_home_j_pyTivo_templates_root_container_tmpl.py", line 104, in respond
  File "/home/j/Desktop/pyTivo/plugin.py", line 8, in GetPlugin
    plugin = getattr(module, name)()
AttributeError: 'module' object has no attribute 'photo'
```
Do I need a later version of pyTivo installed to get this working? I'm not sure what version I'm running, but I installed it earlier this month.

EDIT: I tried the latest d42194 version. Now it doesn't crash, but it just ignores the section


----------



## wmcbrine (Aug 2, 2003)

This version reads the capture date and orientation from Exif. The orientation data is very handy if you have a modern camera that senses the way it's being held, as you no longer have to rotate the pics manually. (You still _can_, of course.) But I've only tested this with two orientations.

The Exif data isn't read until the picture is displayed (but this includes thumbnails). As a result, the orientation takes effect immediately, but the capture date doesn't show up until the next time you read in the descriptive XML -- e.g., by switching to a different directory (or exiting the picture viewer altogether) and coming back. (If you have enough files in the folder, you can just scroll it off-screen and back.)


----------



## wmcbrine (Aug 2, 2003)

This one is a little more thread-safe, and does a little more caching. Also, I decided to use draft mode for everything, because it's soooo much faster, and I didn't see a meaningful difference in PQ after extensive eyeballing with my one TV. Please let me know if you feel differently.


----------



## wmcbrine (Aug 2, 2003)

When a request came in with "ItemCount" set to zero, I was returning the whole list, which made the Tivo barf on directories with too many files. Also, the random sort order wasn't being changed if a new seed was used.

I'm still looking for anyone who can tell me what "Error #5-6" means. (Seen only when running on Windows, at unpredictable intervals.) If I knew what it meant, then maybe I'd have a better chance of fixing it.


----------



## wmcbrine (Aug 2, 2003)

I found a new way to make the Tivo reboot -- send it some progressive JPEGs. Don't worry, that's not in any of the released versions, and won't be.


----------



## wmcbrine (Aug 2, 2003)

This version has better error messages, and allows for Unicode filenames etc.


----------



## wmcbrine (Aug 2, 2003)

The latest version is now available in the main pyTivo thread, or via git.


----------



## shredhead (Oct 15, 2003)

I have a DirecTivo unit. Would this work for me? Only the photos module. 

I know the videos part would not because of the lack of the correct software version, the GoBack feature / TTG. Just curious. For photos I now use JavaHMO and I have to downsize all my photos because it doesn't appear to be able to handle anything above 5 megapixel.


----------



## wmcbrine (Aug 2, 2003)

shredhead said:


> I have a DirecTivo unit. Would this work for me? Only the photos module.


Yes, and the music, too.


----------



## shredhead (Oct 15, 2003)

wmcbrine said:


> Yes, and the music, too.


Setting this up was quick... (sorry I doubted you in the other thread!)

I noticed immediately that it doesn't like it if you have a space in a share name.

Photos works exactly like Tivo Desktop and JavaHMO. I didn't try large sized photos but I will next time I dump some off the SD chip. Nice work.

Music works exactly like Tivo Desktop. The songs are listed in alphabetical order. One of javaHMO's music modules will read the ID tag info from MP3 files and list them in the track order. This (and taking load off my Windows machine) was what attracted me to it. Has anyone come up with a fix for this?


----------



## wmcbrine (Aug 2, 2003)

shredhead said:


> One of javaHMO's music modules will read the ID tag info from MP3 files and list them in the track order.


I could probably do that, but I'd need to know more about it. I've never used the track number feature of ID3 myself -- I just named the files such that the track number came before the song name. My usual MP3 player doesn't even display this info... is it part of ID3v1?

Edit: Ah, here it is: "As the comments field is to short to write anything useful in the ID3v1.1 standard declares that this field should be 28 characters, that the next byte always should be zero and that the last byte before the genre byte should contain which track on the CD this music comes from." That explains it...


----------



## shredhead (Oct 15, 2003)

wmcbrine said:


> I could probably do that, but I'd need to know more about it. I've never used the track number feature of ID3 myself -- I just named the files such that the track number came before the song name. My usual MP3 player doesn't even display this info... is it part of ID3v1?
> 
> Edit: Ah, here it is: "As the comments field is to short to write anything useful in the ID3v1.1 standard declares that this field should be 28 characters, that the next byte always should be zero and that the last byte before the genre byte should contain which track on the CD this music comes from." That explains it...


 I renamed all my MP3s so they WOULDN'T have the track number at the beginning of the filename. My MP3 player wasn't displaying the names how I like them. I guess it's not the end of the world if the only solution is renaming all of 'em again. I use The Godfather (Windows) and it works really well.


----------



## wmcbrine (Aug 2, 2003)

It's not the only solution. A simpler solution (that will work right now) is to create a playlist, with the songs in the correct order. An .m3u file is good -- it's just a simple text file with the filenames one per line. But don't give up on getting me to sort by ID3 track number yet. 

In javaHMO, how is this behavior triggered? Does it always do it, or do you have to tell it to? Does it confine the behavior to, say, bottom-level directories with fewer than 30 tracks, and with the filenames all starting with the same characters? (This is what I'm thinking of doing. I'd rather not do it all the time, because it's much slower than a simple name sort.) Or does it sort any sized collection, first by artist, then album, then track number? (I could do that too, but like I say, slowsville.)

P.S. My track numbers aren't at the beginning of the filename -- I name them like so:

Artist - Album - NN - Song.mp3

This is enough to sort them properly. But, when I'm not putting them into an album, I generally go with "Artist - Song.mp3". So it would be good if that form could still sort by track number...


----------



## armooo (Feb 2, 2003)

You should be able to sort with something like this.



> def sort_nicely( l ):
> """ Sort the given list in the way that humans expect.
> """
> convert = lambda text: int(text) if text.isdigit() else text
> ...


You will need to write convert as a def for python 2.4 support.


----------



## shredhead (Oct 15, 2003)

wmcbrine said:


> It's not the only solution. A simpler solution (that will work right now) is to create a playlist, with the songs in the correct order. An .m3u file is good -- it's just a simple text file with the filenames one per line. But don't give up on getting me to sort by ID3 track number yet.


My music folders don't have playlists in them now. That's an awful lot of playlists to build. I have not found a good Linux command line tool to automate this for me yet but I know they are out there. The playlists I do have are from the Windows box so all the paths are wrong.

Renaming all my MP3's took about 20 minutes to do.. just a few mouse clicks really, since I used the app I mentioned in the earlier message. No big deal.

That said, I think it would be a worthwhile project if you are willing to do it. I am sure others who use pyTivo would appreciate having the sorting features. I don't write code myself otherwise I might have done it and posted it instead of renaming my files as the workaround. Still, if the option were there to sort on other ID3 variables I would use it.



wmcbrine said:


> In javaHMO, how is this behavior triggered? Does it always do it, or do you have to tell it to? Does it confine the behavior to, say, bottom-level directories with fewer than 30 tracks, and with the filenames all starting with the same characters? (This is what I'm thinking of doing. I'd rather not do it all the time, because it's much slower than a simple name sort.) Or does it sort any sized collection, first by artist, then album, then track number? (I could do that too, but like I say, slowsville.)


There are three javaHMO plug ins for music. The first one does it identically to how pyTivo currently does it (and Tivo Desktop too), that is, sorted on the filename. The second one called Audio Organizer reads the ID3 tags and then you can sort the music all sorts of ways, by artist/title, by genre, track number, year/decade, etc. Go here to get the details: http://javahmo.sourceforge.net/documentation.html. One thing that's really cool is that you can customize the sorts by manually editing the config file (since the gui has a limited number of options offered). The third plug in, I'm not sure has a real use. It's called Jukebox. It's sort of a way to create playlists on the fly within the Tivo interface. But you have to play the tracks for them to get added to the list.

So to answer your question, if you don't need sorting you would use the so called standard music plug in. If you want to sort then you would use Audio Organizer (it lets you use both) and you can pick up to I think 6 ways to sort.

I'd like to see it implemented this way in pyTivo. In the conf file, a user would set up a music plug as it is done today, but there would be some additional optional parameters to tell pyTivo how to sort it (or not to). Something like:
[Music]
type=music
path=/usr/public/photos
auto_subshares=False
sort_on=default

[Music_sorted_by_Artist_Title_Track]
type=music
path=/usr/public/photos
auto_subshares=False
sort_on = Artist;Title;Track

[Music_sorted_by_genre]
type=music
path=/usr/public/photos
auto_subshares=False
sort_on=Genre;Year;Artist;Title;Track

So, I'd have three music items in Music and Photos.


----------



## CuriousMark (Jan 13, 2005)

There are a couple of good ID3 tag reader/editor modules out there, check the cheese shop.

I have iTunes set to store my MP3s in Artist/album folders with ##-title.mp3 filenames. In this setup TiVo Desktop always plays them in the right order. When I want to play things across artists or albums I use a playlist. 

I suppose for people who throw 10,000 files in a single folder, that wouldn't work too well. Luckily iTunes can sort that mess out for them pretty quickly.

A typical album folder will always have fewer than 30 or 40 songs, so your idea to sort on ID3 track number for small folders and otherwise punt makes a lot of sense. The case that would break that is multi-volume albums where the track numbers duplicate and you would have to sort on the disc # tag too. TiVoDesktop doesn't handle those right for me, playing two track 01s followed by two track 02s, sometimes it plays the disc 2 track first, sometimes not. iTunes, of course, sorts on disc then track and plays them in the right order. 

I fixed that problem by having iTunes store the discs separately by changing their disc titles slightly.

The ID3 tag module I saw returns a dictionary of ID3 tags. You could build a list of dictionaries for up to 30 songs in a folder and sort the list on the disc and track values of the dicts. It should go pretty quickly, and would only slow the start of the first song in the folder.

If you want to be clever, you could check the first file returned by the folder walk and if its values indicate it is the first song, start playing it and finish the sort in the background. More often than not, that will be the first song anyway.


----------



## JamesRisse (Mar 31, 2005)

I'm guessing this isn't really the correct place to ask this, but I'm at a loss for where the correct place is. 

I just discovered pyTivo and installed it yesterday and after seeing how much better it was than tivo destop I uninstalled tivo desktop. Fantastic work by the way. I added a photo share and it shows up and I can navigate the files, but the images only display the broken image icon.

The folder I'm sharing has several GB of photos if that makes a difference. The images all displayed fine using the tivo desktop software.

I'm pretty sure there's something simple I need to fix this as obviously the photo plugin works for most people, but I wasn't able to find the answer in my quick search.

I'm using the 2008.05.02 version as a service on a windows XP machine. If you need more info I'll be happy to provide it.

Thanks for your work in developing this fantastic program, and thanks in advance for any help resolving this issue.


----------



## wmcbrine (Aug 2, 2003)

You have to install the Python Imaging Library for photos to work. See the first post in this thread.


----------



## JamesRisse (Mar 31, 2005)

Thanks ... I tried to install it, but I'm guessing I installed it incorrectly. I'll read some documentation on the image library when I reinstall instead of just clicking through as fast as possible and maybe it'll resolve my issue.

*Edit*
The imaging library seems to be installed properly ... maybe I need to restart the service or something before it works? I'll try that.

*Edit #2*
That didn't seem to work either. Is there a .conf file or something for the imaging library that needs editing?


----------



## wmcbrine (Aug 2, 2003)

It has to be installed for all users if you're running pyTivo as a service. Not just you.

If that's not the answer, then post your log. (As an attachment, please. Don't paste it in.)


----------



## JamesRisse (Mar 31, 2005)

Issue is resolved ... I'm not really sure what I did that fixed it. 

I re-ran the imaging install for a 3rd time looking for something that let me say to install it for all users and found nothing.

I launched the python GUI and typed in "import _imaging" and verified that there was no error.

I stopped the service and launched the console to see if it would provide any error messages.

The images were displayed properly, so I thought that this must have been an issue with the imaging module not being installed for all users so to verify I closed the console and restarted the service.

Images were still displayed properly much to my confusion, but a pleasant surprise.

Thanks for you for all your help. I looked at the pyTivoService.log it didn't appear to have any useful information there.


----------

