Ejemplo n.º 1
0
    def __init__(self, archivczsk, path):
        ContentProvider.__init__(self)
        self._archivczsk = archivczsk
        self._categories_io = CategoriesIO(path)
        self.on_start.append(self.__create_config)
        self.on_pause.append(self.__create_config)
        self.on_stop.append(self.__save_categories)

        all_addons_category = PCategory()
        all_addons_category.name = _("All addons")
        all_addons_category.params = {'category_addons': 'all_addons'}
        all_addons_category.image = PNG_PATH + '/category_all.png'
        tv_addons_category = PCategory()
        tv_addons_category.name = _("TV addons")
        tv_addons_category.image = PNG_PATH + '/category_tv.png'
        tv_addons_category.params = {'category_addons': 'tv_addons'}
        video_addons_category = PCategory()
        video_addons_category.name = _("Video addons")
        video_addons_category.image = PNG_PATH + '/category_video.png'
        video_addons_category.params = {'category_addons': 'video_addons'}
        self.default_categories = {
            'all_addons': {
                'item': all_addons_category,
                'title': _("All addons"),
                'call': self._get_all_addons
            },
            'tv_addons': {
                'item': tv_addons_category,
                'title': _("TV addons"),
                'call': self._get_tv_addons
            },
            'video_addons': {
                'item': video_addons_category,
                'title': _("Video addons"),
                'call': self._get_video_addons
            }
        }
        self.default_categories_order = [
            'all_addons', 'tv_addons', 'video_addons'
        ]
Ejemplo n.º 2
0
    def __init__(self, archivczsk, path):
        ContentProvider.__init__(self)
        self._archivczsk = archivczsk
        self._categories_io = CategoriesIO(path)
        self.on_start.append(self.__create_config)
        self.on_pause.append(self.__create_config)
        self.on_stop.append(self.__save_categories)

        all_addons_category = PCategory()
        all_addons_category.name = _("All addons")
        all_addons_category.params = {'category_addons':'all_addons'}
        all_addons_category.image = PNG_PATH + '/category_all.png'
        tv_addons_category = PCategory()
        tv_addons_category.name = _("TV addons")
        tv_addons_category.image = PNG_PATH+'/category_tv.png'
        tv_addons_category.params = {'category_addons':'tv_addons'}
        video_addons_category = PCategory()
        video_addons_category.name = _("Video addons")
        video_addons_category.image = PNG_PATH+'/category_video.png'
        video_addons_category.params = {'category_addons':'video_addons'}
        self.default_categories={
                                 'all_addons':{'item':all_addons_category
                                               ,'title':_("All addons"),
                                               'call':self._get_all_addons
                                               },
                                 'tv_addons':{
                                              'item':tv_addons_category,
                                              'title':_("TV addons"),
                                              'call':self._get_tv_addons
                                              },
                                  'video_addons':{
                                                  'item':video_addons_category,
                                                  'title':_("Video addons"),
                                                  'call':self._get_video_addons
                                                  }
                                  }
        self.default_categories_order = ['all_addons','tv_addons','video_addons']
Ejemplo n.º 3
0
class ArchivCZSKContentProvider(ContentProvider):
    def __init__(self, archivczsk, path):
        ContentProvider.__init__(self)
        self._archivczsk = archivczsk
        self._categories_io = CategoriesIO(path)
        self.on_start.append(self.__create_config)
        self.on_pause.append(self.__create_config)
        self.on_stop.append(self.__save_categories)

        all_addons_category = PCategory()
        all_addons_category.name = _("All addons")
        all_addons_category.params = {'category_addons': 'all_addons'}
        all_addons_category.image = PNG_PATH + '/category_all.png'
        tv_addons_category = PCategory()
        tv_addons_category.name = _("TV addons")
        tv_addons_category.image = PNG_PATH + '/category_tv.png'
        tv_addons_category.params = {'category_addons': 'tv_addons'}
        video_addons_category = PCategory()
        video_addons_category.name = _("Video addons")
        video_addons_category.image = PNG_PATH + '/category_video.png'
        video_addons_category.params = {'category_addons': 'video_addons'}
        self.default_categories = {
            'all_addons': {
                'item': all_addons_category,
                'title': _("All addons"),
                'call': self._get_all_addons
            },
            'tv_addons': {
                'item': tv_addons_category,
                'title': _("TV addons"),
                'call': self._get_tv_addons
            },
            'video_addons': {
                'item': video_addons_category,
                'title': _("Video addons"),
                'call': self._get_video_addons
            }
        }
        self.default_categories_order = [
            'all_addons', 'tv_addons', 'video_addons'
        ]

    def __create_config(self):
        choicelist = [('categories', _("Category list"))]
        choicelist.extend([(category_key,
                            self.default_categories[category_key]['title'])
                           for category_key in self.default_categories_order])
        choicelist.extend([(category.id, category.name)
                           for category in self._get_categories(user_only=True)
                           ])
        config.plugins.archivCZSK.defaultCategory = ConfigSelection(
            default='categories', choices=choicelist)

    def __save_categories(self):
        self._categories_io.save()

    def get_content(self, params=None):
        log.info('%s get_content - params: %s' % (self, str(params)))
        if not params or 'categories' in params:
            return self._get_categories()
        if 'category' in params:
            return self._get_category(params['category'])
        if 'category_addons' in params:
            if 'filter_enabled' in params:
                return self._get_category_addons(params['category_addons'],
                                                 params['filter_enabled'])
            return self._get_category_addons(params['category_addons'])
        if 'categories_user' in params:
            return self._get_categories(user_only=True)

    def add_category(self, category_title):
        pcategory = PCategory()
        pcategory.name = category_title
        self._categories_io.add_category(pcategory)
        # update params
        pcategory.params = {'category_addons': pcategory.id}
        self._categories_io.update_category(pcategory)

    def rename_category(self, pcategory, new_title):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.name = new_title
        self._categories_io.update_category(pcategory)
        # update params
        pcategory.params = {'category_addons': pcategory.id}
        self._categories_io.update_category(pcategory)

    def remove_category(self, pcategory):
        self._categories_io.remove_category(pcategory)

    def add_to_category(self, pcategory, paddon):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.add_addon(paddon)
        self._categories_io.update_category(pcategory)

    def remove_from_category(self, pcategory, paddon):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.remove_addon(paddon)
        self._categories_io.update_category(pcategory)

    def _get_category(self, category_id):
        if category_id in self.default_categories:
            return self.default_categories[category_id]['item']
        pcategory = self._categories_io.get_category(category_id)
        return pcategory

    def _get_categories(self, user_only=False):
        category_list = self._categories_io.get_categories()
        if not user_only:
            category_list.extend([
                self.default_categories[category_key]['item']
                for category_key in self.default_categories_order
            ])
        return category_list

    def _get_category_addons(self, category_id, filter_enabled=True):
        def filter_enabled_addons(paddon):
            return paddon.addon.get_setting('enabled')

        if category_id in self.default_categories:
            return self.default_categories[category_id]['call'](filter_enabled)
        addons = [
            PCategoryVideoAddon(self._archivczsk.get_addon(addon_id))
            for addon_id in self._categories_io.get_category(category_id)
        ]
        if filter_enabled:
            addons = filter(filter_enabled_addons, addons)
        # order addons by setting 'addonorder'
        try:
            addons = sorted(addons, key=lambda x: x.order)
        except:
            pass
        return addons

    def _get_all_addons(self, filter_enabled=True):
        def filter_enabled_addons(paddon):
            return paddon.addon.get_setting('enabled')

        addons = [
            PVideoAddon(addon)
            for addon in self._archivczsk.get_video_addons()
        ]
        if filter_enabled:
            addons = filter(filter_enabled_addons, addons)
        # order addons by setting 'addonorder'
        try:
            addons = sorted(addons, key=lambda x: x.order)
        except:
            pass
        return addons

    def _get_video_addons(self, filter_enabled=True):
        #addons = [paddon for paddon in self._get_all_addons(filter_enabled) if not paddon.addon.get_setting('tv_addon')]
        addons = [
            paddon for paddon in self._get_all_addons(filter_enabled)
            if not paddon.addon.setting_exist('tv_addon')
            or not paddon.addon.get_setting('tv_addon')
        ]
        #addons.sort(key=lambda addon: addon.name.lower())
        # order addons by setting 'addonorder'
        try:
            addons = sorted(addons, key=lambda x: x.order)
        except:
            pass
        return addons

    def _get_tv_addons(self, filter_enabled=True):
        #addons = [paddon for paddon in self._get_all_addons(filter_enabled) if paddon.addon.get_setting('tv_addon')]
        addons = [
            paddon for paddon in self._get_all_addons(filter_enabled)
            if paddon.addon.setting_exist('tv_addon')
            and paddon.addon.get_setting('tv_addon')
        ]
        #addons.sort(key=lambda addon: addon.name.lower())
        # order addons by setting 'addonorder'
        try:
            addons = sorted(addons, key=lambda x: x.order)
        except:
            pass
        return addons
Ejemplo n.º 4
0
class ArchivCZSKContentProvider(ContentProvider):
    def __init__(self, archivczsk, path):
        ContentProvider.__init__(self)
        self._archivczsk = archivczsk
        self._categories_io = CategoriesIO(path)
        self.on_start.append(self.__create_config)
        self.on_pause.append(self.__create_config)
        self.on_stop.append(self.__save_categories)

        all_addons_category = PCategory()
        all_addons_category.name = _("All addons")
        all_addons_category.params = {'category_addons':'all_addons'}
        all_addons_category.image = PNG_PATH + '/category_all.png'
        tv_addons_category = PCategory()
        tv_addons_category.name = _("TV addons")
        tv_addons_category.image = PNG_PATH+'/category_tv.png'
        tv_addons_category.params = {'category_addons':'tv_addons'}
        video_addons_category = PCategory()
        video_addons_category.name = _("Video addons")
        video_addons_category.image = PNG_PATH+'/category_video.png'
        video_addons_category.params = {'category_addons':'video_addons'}
        self.default_categories={
                                 'all_addons':{'item':all_addons_category
                                               ,'title':_("All addons"),
                                               'call':self._get_all_addons
                                               },
                                 'tv_addons':{
                                              'item':tv_addons_category,
                                              'title':_("TV addons"),
                                              'call':self._get_tv_addons
                                              },
                                  'video_addons':{
                                                  'item':video_addons_category,
                                                  'title':_("Video addons"),
                                                  'call':self._get_video_addons
                                                  }
                                  }
        self.default_categories_order = ['all_addons','tv_addons','video_addons']

    def __create_config(self):
        choicelist = [('categories', _("Category list"))]
        choicelist.extend([(category_key,self.default_categories[category_key]['title']) for category_key in self.default_categories_order])
        choicelist.extend([(category.id, category.name) for category in self._get_categories(user_only=True)])
        config.plugins.archivCZSK.defaultCategory = ConfigSelection(default='categories', choices=choicelist)

    def __save_categories(self):
        self._categories_io.save()

    def get_content(self, params=None):
        if not params or 'categories' in params:
            return self._get_categories()
        if 'category' in params:
            return self._get_category(params['category'])
        if 'category_addons' in params:
            if 'filter_enabled' in params:
                return self._get_category_addons(params['category_addons'], params['filter_enabled'])
            return self._get_category_addons(params['category_addons'])
        if 'categories_user' in params:
            return self._get_categories(user_only=True)

    def add_category(self, category_title):
        pcategory = PCategory()
        pcategory.name = category_title
        self._categories_io.add_category(pcategory)
        # update params
        pcategory.params = {'category_addons':pcategory.id}
        self._categories_io.update_category(pcategory)

    def rename_category(self, pcategory, new_title):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.name = new_title
        self._categories_io.update_category(pcategory)
        # update params
        pcategory.params = {'category_addons':pcategory.id}
        self._categories_io.update_category(pcategory)

    def remove_category(self, pcategory):
        self._categories_io.remove_category(pcategory)

    def add_to_category(self, pcategory, paddon):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.add_addon(paddon)
        self._categories_io.update_category(pcategory)

    def remove_from_category(self, pcategory, paddon):
        # sync category
        pcategory = self._get_category(pcategory.id)
        pcategory.remove_addon(paddon)
        self._categories_io.update_category(pcategory)

    def _get_category(self, category_id):
        if category_id in self.default_categories:
            return self.default_categories[category_id]['item']
        pcategory = self._categories_io.get_category(category_id)
        return pcategory

    def _get_categories(self, user_only=False):
        category_list = self._categories_io.get_categories()
        if not user_only:
            category_list.extend( [self.default_categories[category_key]['item'] for category_key in self.default_categories_order])
        return category_list

    def _get_category_addons(self, category_id, filter_enabled=True):
        def filter_enabled_addons(paddon):
            return paddon.addon.get_setting('enabled')
        if category_id in self.default_categories:
            return self.default_categories[category_id]['call'](filter_enabled)
        addons = [PCategoryVideoAddon(self._archivczsk.get_addon(addon_id)) for addon_id in self._categories_io.get_category(category_id)]
        if filter_enabled:
            addons = filter(filter_enabled_addons, addons)
        return addons

    def _get_all_addons(self, filter_enabled=True):
        def filter_enabled_addons(paddon):
            return paddon.addon.get_setting('enabled')
        addons = [PVideoAddon(addon) for addon in self._archivczsk.get_video_addons()]
        if filter_enabled:
            addons = filter(filter_enabled_addons, addons)
        return addons

    def _get_video_addons(self, filter_enabled=True):
        addons = [paddon for paddon in self._get_all_addons(filter_enabled) if not paddon.addon.get_setting('tv_addon')]
        addons.sort(key=lambda addon: addon.name.lower())
        return addons

    def _get_tv_addons(self, filter_enabled=True):
        addons = [paddon for paddon in self._get_all_addons(filter_enabled) if paddon.addon.get_setting('tv_addon')]
        addons.sort(key=lambda addon: addon.name.lower())
        return addons