Exemplo n.º 1
0
    def __add_sort_method_to_handle(self, handle, items=None):
        """ Add a sort method to the plugin output. It takes the Add-On settings into
        account. But if none of the items have a date, it is forced to sort by name.

        :param int handle:              The handle to add the sortmethod to.
        :param list[MediaItem] items:   The items that need to be sorted

        :rtype: None

        """

        if AddonSettings.mix_folders_and_videos():
            label_sort_method = xbmcplugin.SORT_METHOD_LABEL_IGNORE_FOLDERS
        else:
            label_sort_method = xbmcplugin.SORT_METHOD_LABEL

        if items:
            has_dates = len(list([i for i in items if i.has_date()])) > 0
            if has_dates:
                Logger.debug("Sorting method: Dates")
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_DATE)
                xbmcplugin.addSortMethod(handle=handle,
                                         sortMethod=label_sort_method)
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
                return

            has_tracks = len(list([i for i in items if i.has_track()])) > 0
            if has_tracks:
                Logger.debug("Sorting method: Tracks")
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_DATE)
                xbmcplugin.addSortMethod(handle=handle,
                                         sortMethod=label_sort_method)
                xbmcplugin.addSortMethod(
                    handle=handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
                return

        Logger.debug("Sorting method: Default (Label)")
        xbmcplugin.addSortMethod(handle=handle, sortMethod=label_sort_method)
        xbmcplugin.addSortMethod(handle=handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_DATE)
        xbmcplugin.addSortMethod(handle=handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
        xbmcplugin.addSortMethod(handle=handle,
                                 sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
        return
Exemplo n.º 2
0
    def __add_sort_method_to_handle(self, handle, items=None):
        """ Add a sort method to the plugin output. It takes the Add-On settings into
        account. But if none of the items have a date, it is forced to sort by name.

        :param int handle:              The handle to add the sortmethod to.
        :param list[MediaItem] items:   The items that need to be sorted

        :rtype: None

        """

        sort_methods = []

        # Add the default sorting options
        if AddonSettings.mix_folders_and_videos():
            sort_methods.append(xbmcplugin.SORT_METHOD_LABEL_IGNORE_FOLDERS)
        else:
            sort_methods.append(xbmcplugin.SORT_METHOD_LABEL)
        sort_methods.append(xbmcplugin.SORT_METHOD_EPISODE)
        sort_methods.append(xbmcplugin.SORT_METHOD_UNSORTED)

        # And then the specialized ones ad default sort options
        if items:
            has_dates = any([i for i in items if i.has_date()])
            if has_dates:
                sort_methods.insert(0, xbmcplugin.SORT_METHOD_DATE)

            has_tracks = any([i for i in items if i.has_track()])
            if has_tracks:
                sort_methods.insert(0, xbmcplugin.SORT_METHOD_TRACKNUM)

        # Actually add them
        Logger.debug("Sorting methods: %s", sort_methods)
        for sort_method in sort_methods:
            xbmcplugin.addSortMethod(handle=handle, sortMethod=sort_method)
        return