Problem with sorting
#1
I'm trying to add sorting to the YouTube plugin, everything seems to work ok, but I've come into a little problem and i don't know if it's me using the API wrong or a bug.

Basically I want the user to be able to change the sorting of a video list sorting, but i don't want to alter the default sorting that YouTube provides as these are often sorted by something "YouTube specfic". In order to achieve this im currently add the following sort methods to all video lists:
Code:
xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_PLAYLIST_ORDER )
        xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_LABEL )
        xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RATING )
        xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_DATE )
        xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_VIDEO_RUNTIME )
Since the first item set's the default order for the list i have choosen playlist order as I saw this was hard-coded to a running count in FileItem.cpp:

Code:
case SORT_METHOD_PROGRAM_COUNT:
  case SORT_METHOD_PLAYLIST_ORDER:
    // TODO: Playlist order is hacked into program count variable (not nice, but ok until 2.0)
    FillSortFields(SSortFileItem::ByProgramCount);
    break;

This seems to work fine at first, the video list is produced in the same order as if i had set it to SORT_METHOD_NONE but after cycling through all the sorting options I can't get the list to return to the original order.. Is this by design or am I doing something wrong?
Reply
#2
Never Mind I'm an idiot..

SORT_METHOD_UNSORTED

was the answer, should have read the docs instead of running around looking through code..
Reply
#3
And i Spoke too soon, this exhibits the same problems as program count and playlist count, after you cycle through and back to "default" the original order isn't restored..
Reply
#4
You'll need to set _something_ to use as the ordering you want so that it can re-sort it. If you use program count, then you'll need to set the program count variable (not sure if this is doable from python or not). Basically just find something you can set that isn't shown in the UI and throw an increasing sequence of integers in it.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
jmarshall Wrote:You'll need to set _something_ to use as the ordering you want so that it can re-sort it. If you use program count, then you'll need to set the program count variable (not sure if this is doable from python or not). Basically just find something you can set that isn't shown in the UI and throw an increasing sequence of integers in it.

Cheers,
Jonathan
I've tried setting the program count both via

listitem.setProperty( "ProgramCount", item("ProgramCount"))

and as part of the dictionary passed in

listitem.setInfo(type='Video', infoLabels=item_params)

Neither work. I can't see any other way to get sort to work with viewcount, nothing in this list seems useful.

http://xbmc.sourceforge.net/python-docs/xbmcplugin.html


Any suggestions?
Reply
#6
figured it out, had to pass it as 'count' in the dict.

listitem.setInfo(type='Video', infoLabels=item_params)
Reply
#7
Ok, I've given up on getting this to work properly. Because we fill out so may different fields we've run out of fields where the track value could fit and I'm getting too frustrated to make more ugly hacks to work around what I view as deficiencies in xbmc's python API..

Basically we tried putting the counter into "count" and that works, but at the same time our users requested being able to sort after YouTube's watched count.

Now lib/libPython/xbmcmodule/listitem.cpp actually supports importing this variable as either "watched" or "playcount" but FileItem.cpp doesn't implement any way to sort by these variables (Ehm, why?). An alternative would be to use "tracknumber", but this variable automatically gets prefixed to the title (seeing as this is normally used for music tracks this is understandable) and we already have problems with overly long titles in the video view so that option is out.

So we're stuck having to choose between these to functions, and I choose the broken default sort with more sort options as the alternative is only slightly better from my perspective (we could use the "year" variable but the label for the default sort would still be messed up and look unprofessional).

But my real problem with all of this is that it shouldn't be this hard to do sorting in a plugin, why should every plugin developer have to write the same 10 lines of code implementing the same counter and at the same time waste precious info labels? In my view this code clearly belongs in XBMC as it's entirely an internal xbmc matter, all the plugin developer should do would be to place this line as the first sort:

Code:
xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_UNSORTED )
and xbmc would auto-magically add a counter and restore this sorting when the user returned to this view, this could also be used to get rid of the ugly playlist hacks that litter FileItem.cpp..

Anyway as it stands now we continue to use SORT_METHOD_UNSORTED, but it has the same problems as described above and the user will just have to live with it.. Oo
Reply
#8
Agreed. Please throw up a ticket on trac which details the problem and we'll see what we can do on the XBMC side.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
Nice, I'll write one up as soon as I've gotten some sleep Smile


==== EDIT ===
Done : http://trac.xbmc.org/ticket/10252
Reply

Logout Mark Read Team Forum Stats Members Help
Problem with sorting0