Esempio n. 1
0
def getBouquetNowNextEpg(ref, servicetype, encode=False):
    ref = unquote(ref)
    ret = []
    services = eServiceCenter.getInstance().list(eServiceReference(ref))
    if not services:
        return {"events": ret, "result": False}

    search = ['IBDCTSERNWX']
    if servicetype == -1:
        for service in services.getContent('S'):
            search.append((service, 0, -1))
            search.append((service, 1, -1))
    else:
        for service in services.getContent('S'):
            search.append((service, servicetype, -1))

    epgcache = eEPGCache.getInstance()
    events = epgcache.lookupEvent(search)
    if events is not None:
        for event in events:
            ev = {}
            ev['id'] = event[0]
            ev['begin_timestamp'] = event[1]
            ev['duration_sec'] = event[2]
            ev['title'] = filterName(event[4], encode)
            ev['shortdesc'] = convertDesc(event[5], encode)
            ev['longdesc'] = convertDesc(event[6], encode)
            if event[7] is not None:
                achannels = GetWithAlternative(event[7], False)
                if achannels:
                    ev['asrefs'] = achannels
            ev['sref'] = event[7]
            ev['sname'] = filterName(event[8], encode)
            ev['now_timestamp'] = event[3]
            ev['genre'], ev['genreid'] = convertGenre(event[9])
            ret.append(ev)

    return {"events": ret, "result": True}
Esempio n. 2
0
def getTimers(session):
    rt = session.nav.RecordTimer
    epg = Epg()
    timers = []
    for timer in rt.timer_list + rt.processed_timers:
        if hasattr(timer, "wakeup_t"):
            energytimer = timer.wakeup_t or timer.standby_t or timer.shutdown_t or timer.fnc_t != "off" or 0
            if energytimer:
                continue

        descriptionextended = "N/A"
        filename = None
        nextactivation = None
        if timer.eit and timer.service_ref:
            descriptionextended = epg.getEventDescription(
                timer.service_ref, timer.eit)

        try:
            filename = timer.Filename
        except Exception:
            pass

        try:
            nextactivation = timer.next_activation
        except Exception:
            pass

        disabled = 0
        if timer.disabled:
            disabled = 1

        justplay = 0
        if timer.justplay:
            justplay = 1

        if hasattr(timer, "allow_duplicate"):
            allow_duplicate = timer.allow_duplicate and 1 or 0
        else:
            allow_duplicate = 1

        autoadjust = -1
        if hasattr(timer, "autoadjust"):
            autoadjust = timer.autoadjust and 1 or 0
        elif hasattr(config.recording, "adjust_time_to_event"):
            autoadjust = config.recording.adjust_time_to_event.value and 1 or 0

        if timer.dirname:
            dirname = timer.dirname
        else:
            dirname = "None"

        dontSave = 0
        if timer.dontSave:
            dontSave = 1

        toggledisabled = 1
        if timer.disabled:
            toggledisabled = 0

        toggledisabledimg = "off"
        if timer.disabled:
            toggledisabledimg = "on"

        asrefs = ""
        achannels = GetWithAlternative(str(timer.service_ref), False)
        if achannels:
            asrefs = achannels

        vpsplugin_enabled = False
        vpsplugin_overwrite = False
        vpsplugin_time = -1
        if hasattr(timer, "vpsplugin_enabled"):
            vpsplugin_enabled = True if timer.vpsplugin_enabled else False
        if hasattr(timer, "vpsplugin_overwrite"):
            vpsplugin_overwrite = True if timer.vpsplugin_overwrite else False
        if hasattr(timer, "vpsplugin_time"):
            vpsplugin_time = timer.vpsplugin_time
            if not vpsplugin_time:
                vpsplugin_time = -1

        always_zap = -1
        if hasattr(timer, "always_zap"):
            if timer.always_zap:
                always_zap = 1
            else:
                always_zap = 0
        if hasattr(timer, "zapbeforerecord"):
            if timer.zapbeforerecord:
                always_zap = 1
            else:
                always_zap = 0

        pipzap = -1
        if hasattr(timer, "pipzap"):
            if timer.pipzap:
                pipzap = 1
            else:
                pipzap = 0

        isAutoTimer = -1
        if hasattr(timer, "isAutoTimer"):
            if timer.isAutoTimer:
                isAutoTimer = 1
            else:
                isAutoTimer = 0

        if six.PY2:
            descriptionextended = six.text_type(descriptionextended,
                                                'utf_8',
                                                errors='ignore').encode(
                                                    'utf_8', 'ignore')

        recordingtype = "normal"

        if timer.record_ecm:
            recordingtype = "scrambled"
            if timer.descramble:
                recordingtype = "descrambled"

        ice_timer_id = -1
        if hasattr(timer, "ice_timer_id"):
            ice_timer_id = timer.ice_timer_id or -1

        # switch back to old way.
        #fuzzyBegin = ' '.join(str(i) for i in FuzzyTime(timer.begin, inPast = True)[1:])
        #fuzzyEnd = ""
        #if strftime("%Y%m%d", localtime(timer.begin)) == strftime("%Y%m%d", localtime(timer.end)):
        #	fuzzyEnd = FuzzyTime(timer.end)[1]
        #else:
        #	fuzzyEnd = ' '.join(str(i) for i in FuzzyTime(timer.end, inPast = True))

        fuzzyBegin = strftime(_("%d.%m.%Y %H:%M"),
                              (localtime(float(timer.begin))))
        fuzzyEnd = strftime(_("%d.%m.%Y %H:%M"), (localtime(float(timer.end))))

        timers.append({
            "serviceref":
            str(timer.service_ref),
            "servicename":
            removeBad(timer.service_ref.getServiceName()),
            "eit":
            timer.eit,
            "name":
            timer.name,
            "description":
            timer.description,
            "descriptionextended":
            descriptionextended,
            "disabled":
            disabled,
            "begin":
            timer.begin,
            "end":
            timer.end,
            "duration":
            timer.end - timer.begin,
            "startprepare":
            timer.start_prepare,
            "justplay":
            justplay,
            "afterevent":
            timer.afterEvent,
            "dirname":
            dirname,
            "tags":
            " ".join(timer.tags),
            "logentries":
            timer.log_entries,
            "backoff":
            timer.backoff,
            "firsttryprepare":
            timer.first_try_prepare,
            "state":
            timer.state,
            "repeated":
            timer.repeated,
            "dontsave":
            dontSave,
            "cancelled":
            timer.cancelled,
            "toggledisabled":
            toggledisabled,
            "toggledisabledimg":
            toggledisabledimg,
            "filename":
            filename,
            "nextactivation":
            nextactivation,
            "realbegin":
            fuzzyBegin,
            "realend":
            fuzzyEnd,
            "asrefs":
            asrefs,
            "vpsplugin_enabled":
            vpsplugin_enabled,
            "vpsplugin_overwrite":
            vpsplugin_overwrite,
            "vpsplugin_time":
            vpsplugin_time,
            "always_zap":
            always_zap,
            "pipzap":
            pipzap,
            "isAutoTimer":
            isAutoTimer,
            "allow_duplicate":
            allow_duplicate,
            "autoadjust":
            autoadjust,
            "recordingtype":
            recordingtype,
            "ice_timer_id":
            ice_timer_id
        })

    return {"result": True, "timers": timers}
Esempio n. 3
0
def getPicon(sname):

    pp = PICON_PATH
    if pp is not None:
        # remove URL part
        if ("://" in sname) or ("%3a//" in sname) or ("%3A//" in sname):
            cname = unquote(sname.split(":")[-1])
            sname = unquote(sname)
            # sname = ":".join(sname.split(":")[:10]) -> old way
            sname = ":".join(sname.split("://")[:1])
            sname = GetWithAlternative(sname)
            cname = unicodedata.normalize(
                'NFKD', unicode(cname, 'utf_8',
                                errors='ignore')).encode('ASCII', 'ignore')
            cname = re.sub(
                '[^a-z0-9]', '',
                cname.replace('&', 'and').replace('+', 'plus').replace(
                    '*', 'star').replace(':', '').lower())
            # picon by channel name for URL
            if len(cname) > 0 and fileExists(pp + cname + ".png"):
                return "/picon/" + cname + ".png"
            if len(cname) > 2 and cname.endswith('hd') and fileExists(
                    pp + cname[:-2] + ".png"):
                return "/picon/" + cname[:-2] + ".png"
            if len(cname) > 5:
                series = re.sub(r's[0-9]*e[0-9]*$', '', cname)
                if fileExists(pp + series + ".png"):
                    return "/picon/" + series + ".png"

        sname = GetWithAlternative(sname)
        if sname is not None:
            pos = sname.rfind(':')
        else:
            return "/images/default_picon.png"
        cname = None
        if pos != -1:
            cname = ServiceReference(sname[:pos].rstrip(':')).getServiceName()
            sname = sname[:pos].rstrip(':').replace(':', '_') + ".png"
        filename = pp + sname
        if fileExists(filename):
            return "/picon/" + sname
        fields = sname.split('_', 8)
        if len(fields) > 7 and not fields[6].endswith("0000"):
            # remove "sub-network" from namespace
            fields[6] = fields[6][:-4] + "0000"
            sname = '_'.join(fields)
            filename = pp + sname
            if fileExists(filename):
                return "/picon/" + sname
        if len(fields) > 1 and fields[0] != '1':
            # fallback to 1 for other reftypes
            fields[0] = '1'
            sname = '_'.join(fields)
            filename = pp + sname
            if fileExists(filename):
                return "/picon/" + sname
        if len(fields) > 3 and fields[2] != '1':
            # fallback to 1 for tv services with nonstandard servicetypes
            fields[2] = '1'
            sname = '_'.join(fields)
            filename = pp + sname
            if fileExists(filename):
                return "/picon/" + sname
        if cname is not None:  # picon by channel name
            cname1 = cname.replace('\xc2\x86',
                                   '').replace('\xc2\x87', '').replace(
                                       '/', '_').encode('utf-8', 'ignore')
            if fileExists(pp + cname1 + ".png"):
                return "/picon/" + cname1 + ".png"
            cname = unicodedata.normalize(
                'NFKD', unicode(cname, 'utf_8',
                                errors='ignore')).encode('ASCII', 'ignore')
            cname = re.sub(
                '[^a-z0-9]', '',
                cname.replace('&',
                              'and').replace('+',
                                             'plus').replace('*',
                                                             'star').lower())
            if len(cname) > 0:
                filename = pp + cname + ".png"
            if fileExists(filename):
                return "/picon/" + cname + ".png"
            if len(cname) > 2 and cname.endswith('hd') and fileExists(
                    pp + cname[:-2] + ".png"):
                return "/picon/" + cname[:-2] + ".png"
    return "/images/default_picon.png"
Esempio n. 4
0
def getTimers(session):
    rt = session.nav.RecordTimer
    timers = []
    for timer in rt.timer_list + rt.processed_timers:

        if hasattr(timer, "wakeup_t"):
            energytimer = timer.wakeup_t or timer.standby_t or timer.shutdown_t or timer.fnc_t != "off" or 0
            if energytimer:
                continue

        descriptionextended = "N/A"
        filename = None
        nextactivation = None
        if timer.eit and timer.service_ref:
            event = eEPGCache.getInstance().lookupEvent(
                ['EX', (str(timer.service_ref), 2, timer.eit)])
            if event and event[0][0]:
                descriptionextended = event[0][0]

        try:
            filename = timer.Filename
        except Exception:
            pass

        try:
            nextactivation = timer.next_activation
        except Exception:
            pass

        disabled = 0
        if timer.disabled:
            disabled = 1

        justplay = 0
        if timer.justplay:
            justplay = 1

        if hasattr(timer, "allow_duplicate"):
            allow_duplicate = timer.allow_duplicate and 1 or 0
        else:
            allow_duplicate = 1

        autoadjust = -1
        if hasattr(timer, "autoadjust"):
            autoadjust = timer.autoadjust and 1 or 0
        elif hasattr(config.recording, "adjust_time_to_event"):
            autoadjust = config.recording.adjust_time_to_event.value and 1 or 0

        if timer.dirname:
            dirname = timer.dirname
        else:
            dirname = "None"

        dontSave = 0
        if timer.dontSave:
            dontSave = 1

        toggledisabled = 1
        if timer.disabled:
            toggledisabled = 0

        toggledisabledimg = "off"
        if timer.disabled:
            toggledisabledimg = "on"

        asrefs = ""
        achannels = GetWithAlternative(str(timer.service_ref), False)
        if achannels:
            asrefs = achannels

        vpsplugin_enabled = False
        vpsplugin_overwrite = False
        vpsplugin_time = -1
        if hasattr(timer, "vpsplugin_enabled"):
            vpsplugin_enabled = True if timer.vpsplugin_enabled else False
        if hasattr(timer, "vpsplugin_overwrite"):
            vpsplugin_overwrite = True if timer.vpsplugin_overwrite else False
        if hasattr(timer, "vpsplugin_time"):
            vpsplugin_time = timer.vpsplugin_time
            if not vpsplugin_time:
                vpsplugin_time = -1

        always_zap = -1
        if hasattr(timer, "always_zap"):
            if timer.always_zap:
                always_zap = 1
            else:
                always_zap = 0

        pipzap = -1
        if hasattr(timer, "pipzap"):
            if timer.pipzap:
                pipzap = 1
            else:
                pipzap = 0

        isAutoTimer = -1
        if hasattr(timer, "isAutoTimer"):
            if timer.isAutoTimer:
                isAutoTimer = 1
            else:
                isAutoTimer = 0

        timers.append({
            "serviceref":
            str(timer.service_ref),
            "servicename":
            timer.service_ref.getServiceName().replace('\xc2\x86', '').replace(
                '\xc2\x87', ''),
            "eit":
            timer.eit,
            "name":
            timer.name,
            "description":
            timer.description,
            "descriptionextended":
            unicode(descriptionextended, 'utf_8',
                    errors='ignore').encode('utf_8', 'ignore'),
            "disabled":
            disabled,
            "begin":
            timer.begin,
            "end":
            timer.end,
            "duration":
            timer.end - timer.begin,
            "startprepare":
            timer.start_prepare,
            "justplay":
            justplay,
            "afterevent":
            timer.afterEvent,
            "dirname":
            dirname,
            "tags":
            " ".join(timer.tags),
            "logentries":
            timer.log_entries,
            "backoff":
            timer.backoff,
            "firsttryprepare":
            timer.first_try_prepare,
            "state":
            timer.state,
            "repeated":
            timer.repeated,
            "dontsave":
            dontSave,
            "cancelled":
            timer.cancelled,
            "toggledisabled":
            toggledisabled,
            "toggledisabledimg":
            toggledisabledimg,
            "filename":
            filename,
            "nextactivation":
            nextactivation,
            "realbegin":
            strftime("%d.%m.%Y %H:%M", (localtime(float(timer.begin)))),
            "realend":
            strftime("%d.%m.%Y %H:%M", (localtime(float(timer.end)))),
            "asrefs":
            asrefs,
            "vpsplugin_enabled":
            vpsplugin_enabled,
            "vpsplugin_overwrite":
            vpsplugin_overwrite,
            "vpsplugin_time":
            vpsplugin_time,
            "always_zap":
            always_zap,
            "pipzap":
            pipzap,
            "isAutoTimer":
            isAutoTimer,
            "allow_duplicate":
            allow_duplicate,
            "autoadjust":
            autoadjust
        })

    return {"result": True, "timers": timers}