Kodi Community Forum
specifying default sortmethod per directory in a plugin? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: specifying default sortmethod per directory in a plugin? (/showthread.php?tid=35495)



specifying default sortmethod per directory in a plugin? - rwparris2 - 2008-08-03

Is there a way to specify which sort method I want to use per directory in a plugin using xbmcplugin.addSortMethod()?

For example, for a music plugin, if I had the structure artist>album>song.mp3 , I would want artist & album to be sorted by title, but the songs to be sorted by track number.

If so, can someone paste or point me to a working example?


- Nuka1195 - 2008-08-03

xbmcplugin.addSortMethod() <- yes

the pydocs have all the possible sort methods. link in my signature.


- rwparris2 - 2008-08-03

I looked at the docs... but addSortMethod() just adds the ability to use that sort method, but doesn't force it.

so for example if I have
Code:
def listArtists():
            xbmcplugin.addSortMethod(int(sys.argv[1]), 10)#sort by title
            addDir(blah blah blah isfolder=true)

def listTracks():
            xbmcplugin.addSortMethod(int(sys.argv[1]), 7)#sort by track
            addDir(blah,blah,blah)

assuming listTracks always comes after listArtists, the default sort method would always be title. At the point where listTracks gets called, I can manually change the sort to track, but it doesn't automatically do it.

I hope this clarifies my initial question -- Is there a way to not just add a sort method, but force it?

(I found a suitable work-around for this particular plugin, but I would still like to know for the future.)