Sort ListItems on date and size
#1
My iPhoto plugin adds a bunch of ListItems with urls to file paths that I'd like to be able to sort by date or size. Calling addSortMethod() with SORT_METHOD_DATE or SORT_METHOD_SIZE adds the sort options to the GUI but does not actually sort the files.

XBMC appears to scan each file for creation date and resolution (at least), but it only re-sorts on the title (SORT_METHOD_LABEL).

How do I make this work?

Thanks,
-jingai
Reply
#2
jingai Wrote:My iPhoto plugin adds a bunch of ListItems with urls to file paths that I'd like to be able to sort by date or size. Calling addSortMethod() with SORT_METHOD_DATE or SORT_METHOD_SIZE adds the sort options to the GUI but does not actually sort the files.

XBMC appears to scan each file for creation date and resolution (at least), but it only re-sorts on the title (SORT_METHOD_LABEL).

Are you setting the infolabels for size and date? If the infolabels are set properly the sorting should be automatic. I have never done a picture plugin though - but I assume it is similar or the same as video and audio plugins in this regard...
Reply
#3
galvanash Wrote:Are you setting the infolabels for size and date? If the infolabels are set properly the sorting should be automatic. I have never done a picture plugin though - but I assume it is similar or the same as video and audio plugins in this regard...

No, I'm not, because according to the log it scans every file I add anyway. Should I scan them on my own as well? Seems like a waste.

-j
Reply
#4
you have to set them yourself.
Reply
#5
spiff Wrote:you have to set them yourself.

Hmm. Ok, well I tried this. If I don't call setInfo() at all, Confluence's "Pic Thumbs" view displays the image resolution and creation date. If I do call it, the creation date is no longer displayed and resolution shows as "0 x 0".

In the List view, the date is displayed for each item if I do call setInfo() and it's not if I don't.

How can I get the skin to display date and resolution while also enabling sorting by date...?

-jingai
Reply
#6
jingai Wrote:Hmm. Ok, well I tried this. If I don't call setInfo() at all, Confluence's "Pic Thumbs" view displays the image resolution and creation date. If I do call it, the creation date is no longer displayed and resolution shows as "0 x 0".

In the List view, the date is displayed for each item if I do call setInfo() and it's not if I don't.

How can I get the skin to display date and resolution while also enabling sorting by date...?

-jingai

Im afraid I don't have pictures in my library to actually try this, and I have never written a picture plugin... But I took a look at the confluence skin and the documentation and it looks like these are the two infolabels you want to set (this might get you started in the right direction at least):

exif:resolution
exif:exiftime

I think these correspond to the following properties when read by the skin:

PictureResolution
PictureDateTime

Which is what the skin uses for display.

Please remember that although the infolabels mechanism in xbmc is extremely flexible and allows you to set nearly anything you want on an item - the skin decides how to use it and when for the most part - and certain combinations of properties may yield differing results, because the skin often is setup to make decisions based on which combination of infolabels is available. The only place this is documented is in the skin itself unfortunately, and each skin tends to be a bit different.

A good approach when you are trying to get a specific view mode to display your information is to look at the skin itself and find the view mode defintion in it - then figure out what infolabels it is trying to read and make sure you set those particular ones correctly.

There is also quite a bit of default behavior you need to be aware of. You may have better luck (since you are saying that the items are being scanned in anyway) to simply not set the infolabels or the sort methods at all - if you leave those unmodified the skin will generally do what it normally does and you may get the result you are looking for without having to do a lot of customization.
Reply
#7
galvanash Wrote:There is also quite a bit of default behavior you need to be aware of. You may have better luck (since you are saying that the items are being scanned in anyway) to simply not set the infolabels or the sort methods at all - if you leave those unmodified the skin will generally do what it normally does and you may get the result you are looking for without having to do a lot of customization.

That's what I was hoping for, since it does scan the EXIF data on the images if I don't set any infolabels at all. Unfortunately, sorting on date doesn't work unless I manually set it.. and if I manually set it, it looks like I have to scan the EXIF data on my own too..

I could definitely do this, but it looks like libexif is not exposed to addons? So I'd have to do it all on my own.. ugh.

Sorting by date in a picture plugin is a pretty useful thing, so if there is no other way to do this, I guess this is what I have to do.

-jingai
Reply
#8
I think with Dharma PIL is builtin now... you should be able to get the EXIF info using it. Something like this (copy and pasted example, but it should get you started if that is what you want to do)...

Code:
from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
ret = {}
i = Image.open(fn)
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret

Also, I do not know for sure what infolabel SORT_METHOD_DATE would correspond to - it may not be the exif date, but instead the file date... Often these are not obvious (for example it often depends on the item type and which view mode you are in). You may need to set the "date" infolabel to the exif date if you want the SORT_METHOD_DATE to work.

You may want to try this before doing a whole bunch of work: Add SORT_METHOD_DATE and add a setInfo call to set the "exif:exiftime" infolabel on each item (just set them to incrementing dates or something - just to test). If that works than you know the sorting will work on that infolabel and you wont have to do anything else.

If it doesn't work though, do the same thing but set the "date" infolabel instead. If the sorting works then you will need to set both of them to get the result you want (as the skin probably will not actually display the "date", only the "exif:exiftime"). You will need to set both of these to the same value if that is the case ("date" and "exif:exiftime"). The date infolabel has to be set in the format %d.%m.%Y (i.e. 01.01.2010), but the exif:exiftime probably uses normal iso format yyyy-mm-dd (2010-01-01) - I'm not entirely sure though, just trying to give you pointers as I have run into those gotchas before. Good luck.
Reply
#9
galvanash Wrote:I think with Dharma PIL is builtin now... you should be able to get the EXIF info using it.

I did try this, but it was unbearably slow.. as in 2-5 seconds per image. When you've got thousands of pictures, this just isn't an option.

Quote:Also, I do not know for sure what infolabel SORT_METHOD_DATE would correspond to - it may not be the exif date, but instead the file date... Often these are not obvious (for example it often depends on the item type and which view mode you are in). You may need to set the "date" infolabel to the exif date if you want the SORT_METHOD_DATE to work.

Correct. Setting the "date" infoLabel does enable sorting on date. However, it also prevents XBMC from scanning the files for the EXIF information.. which is unfortunate.

It seems like the best fix would be to have XBMC set the "date" and "size" infoLabels when it scans the files. I've filed a ticket to this effect (#10519).

Or, it could automatically scan for EXIF data if none was provided, rather than assuming the addon author wants all or nothing.

Thanks for the help,
-jingai
Reply
#10
jingai Wrote:I did try this, but it was unbearably slow.. as in 2-5 seconds per image. When you've got thousands of pictures, this just isn't an option.

Yeah... I can see how that would be a problem. You could cache the results in a database/object if you _really_ wanted to implement this (hash the filenames and store the exif data by hash), but if it takes that long for each image it would still be a pita.

jingai Wrote:Correct. Setting the "date" infoLabel does enable sorting on date. However, it also prevents XBMC from scanning the files for the EXIF information.. which is unfortunate.

It seems like the best fix would be to have XBMC set the "date" and "size" infoLabels when it scans the files. I've filed a ticket to this effect (#10519).

Not to dissuade you, I mean good luck with that - but I doubt they will do that kind of change. Fact is date and size simply mean something different in the plugin interface than what you would be trying to use them for (technically they are the last modified date and byte size of the file)... You will probably have better luck asking for a new sort methods to be added just for the exif infolabels.
Reply
#11
galvanash Wrote:Yeah... I can see how that would be a problem. You could cache the results in a database/object if you _really_ wanted to implement this (hash the filenames and store the exif data by hash), but if it takes that long for each image it would still be a pita.

Yeah.. even if it's just one scan, it still is too long..

Quote:Not to dissuade you, I mean good luck with that - but I doubt they will do that kind of change. Fact is date and size simply mean something different in the plugin interface than what you would be trying to use them for (technically they are the last modified date and byte size of the file)... You will probably have better luck asking for a new sort methods to be added just for the exif infolabels.

Sorting on last modified date and byte size of the file would be fine. But that's the problem -- if I let XBMC scan the files on its own, it doesn't scan that info. If I set that info, it doesn't scan the EXIF data..

I just don't see why it couldn't also scan the last modified time and size of the file at the same time? Or at least automatically scan the EXIF data if none of it is set beforehand by the addon author?

-j
Reply

Logout Mark Read Team Forum Stats Members Help
Sort ListItems on date and size0