willforde / script.module.codequick

Kodi addon framework
GNU General Public License v2.0
33 stars 6 forks source link

Manually add sort methods #9

Closed sy6sy2 closed 6 years ago

sy6sy2 commented 6 years ago

Hi Willforde,

Is it possible to manually add a sort method (let's say SORT_METHOD_UNSORTED) for a "videos" content listing?

The behavior that we want is to obtain the Kodi menu in the order in which each item was added during the for loop in the code.

Thank you for your help!

(cc @wwark)

willforde commented 6 years ago

Yes. You can just call route.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED). You can also disable auto sorting by setting route.autosort = False.

see: https://scriptmodulecodequick.readthedocs.io/en/stable/api/route.html#codequick.route.Route.autosort

from codequick import Route, Listitem
import xbmcplugin

@Route.register
def root(route):
    route.autosort = False
    route.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED)

    yield Listitem.from_dict("Extra videos", subfolder)
    yield Listitem.from_dict("Play video", "http://www.example.com/video1.mkv")

P.S. If autosort is disabled and no sortmethods are given then SORT_METHOD_UNSORTED is set.

sy6sy2 commented 6 years ago

Thank you very munch.

And sorry, is my fault, I looked in the documentation but in the Listitem section -_-'