Custom rules based channel group
#1
I am using "PVR: IPTV_Simple_Client" plugin to watch TV.

The PVR playlist that the server provides has defined certain channel groups (or categories).
These groups are based on languages (like English, French, Hindi, Marathi etc), channel categories (like news, sports, entertainment etc) and HD/non-HD.

I would like a mechanism in which I can create custom channel groups, based on rules.
E.g.
1. "English Movies" would mean a channel that belongs to "English" and "movies" categories. (English+movies)
2. "English and Hindi movies" would be something like (English+Movies | Hindi+Movies)

I understand that I can manually create custom groups and add channels to them. However, a rules based mechanism would be a nice thing.

I attempted to make a basic UI with python+IPTV_Simple_Client plugin. However, I did not proceed with the changes in PVR plugin that use these categories.
This code assumes that the PVR backend fills a hidden preference value "categoryList", which the python script can use.
With the above examples, the script will save the list in the form of "English movies=English+movies;English and Hindi movies=English+Movies|Hindi+Movies"

Posting my UI script here to clarify what I am trying to convey:

# -*- coding: utf-8 -*-
import os
import sys
import time
import _strptime
import requests
import xbmc
import xbmcgui
import xbmcaddon
import xbmcvfs

ADDON = xbmcaddon.Addon()
ADDONNAME = ADDON.getAddonInfo('name')
ADDONID = ADDON.getAddonInfo('id')
ADDONVERSION = ADDON.getAddonInfo('version')
CWD = ADDON.getAddonInfo('path').decode("utf-8")
RESOURCE = xbmc.translatePath( os.path.join( CWD, 'resources', 'lib' ).encode("utf-8") ).decode("utf-8")
DATAPATH = xbmc.translatePath(ADDON.getAddonInfo('profile')).decode('utf-8')

sys.path.append(RESOURCE)

categoryList = ADDON.getSetting("categoryList")
categoryList = categoryList.split(";") if categoryList != "" else []

def editCondition(condition):
    conditions = condition.split("+") if condition != "" else []
    dialog = xbmcgui.Dialog()
    multiselectConditions = [categoryList.index(x) for x in conditions]
    selected = dialog.multiselect("Edit condition", categoryList, preselect = multiselectConditions)
    if selected is None:
        return condition
    conditions = [categoryList[x] for x in selected]
    return "+".join(conditions)

def editCategory(name, conditions):
    conditions = conditions.split("|") if conditions != "" else []
    dialog = xbmcgui.Dialog()
    selected = dialog.select("Edit conditions for {}".format(name), conditions + ["Add new condition", "Delete this category"])
    if selected == -1:
        conditions = [x for x in conditions if x != ""]
        return "|".join(conditions)
    if selected == len(conditions) + 1: # Delete the category
        return ""
    if selected == len(conditions): # Add new
        conditions.append("")
    conditions[selected] = editCondition(conditions[selected])
    conditions = [x for x in conditions if x != ""]
    return editCategory(name, "|".join(conditions))


customCategoryList = ADDON.getSetting("customCategoryList")
customCategoryDict = dict(x.split("=") for x in customCategoryList.split(";")) if ("=" in customCategoryList) else {}
def editCustomCategories():
    global customCategoryDict
    showlist = customCategoryDict.keys() + [ "Add new" ]
    dialog = xbmcgui.Dialog()
    selected = dialog.select("Custom Categories", showlist)
    if selected == -1:
        customCategoryList = ";".join(["=".join([key, customCategoryDict[key]]) for key in customCategoryDict.keys()])
        customCategoryList = ";".join(["=".join([key, customCategoryDict[key]]) for key in customCategoryDict.keys()])
        ADDON.setSetting("customCategoryList", customCategoryList)
        sys.exit(0)

    if selected == len(showlist) - 1: # Add new
        keyboard = xbmc.Keyboard("", "Custom category name", False)
        keyboard.doModal()
        if (keyboard.isConfirmed() and keyboard.getText()):
            name = keyboard.getText()
            if name != "":
                if ";" in name or "=" in name:
                    return
                if name in customCategoryDict.keys():
                    dialog.ok(ADDONNAME, "Name '{}' already present. Editing the Category.".format(name))
                else:
                    customCategoryDict[name] = ""
    else:
        name = showlist[selected]

    customCategoryDict[name] = editCategory(name, customCategoryDict[name])
    customCategoryDict = {x:customCategoryDict[x] for x in customCategoryDict.keys() if customCategoryDict[x] != ""}

while True: editCustomCategories()


Reply



Logout Mark Read Team Forum Stats Members Help
Custom rules based channel group0
This forum uses Lukasz Tkacz MyBB addons.