Example #1
0
 def keyOk(self):
     current = self["config"].getCurrent()[1]
     if isinstance(current, ConfigDirectory):
         self.session.openWithCallback(self.pathSelected, LocationBox, "",
                                       "", current.value)
     elif isinstance(current, ConfigNumber):
         pass
     elif isinstance(current, ConfigText):
         entryName = self["config"].getCurrent()[0]
         self.session.openWithCallback(self.virtualKBCB,
                                       VirtualKeyBoard,
                                       title=removeDiac(entryName),
                                       text=removeDiac(current.getValue()))
Example #2
0
def getTextInput(session, title, text=""):
    def getTextInputCB(word):
        if word is None:
            d.callback('')
        else:
            d.callback(word)

    d = defer.Deferred()
    #session.openWithCallback(getTextInputCB, VirtualKeyBoard, title=toString(title), text=text)
    session.openWithCallback(getTextInputCB,
                             VirtualKeyBoard,
                             title=removeDiac(title),
                             text=removeDiac(text))
    return d
Example #3
0
 def ok(self):
     try:
         #self.close(self.text.encode("utf-8"), self.configEntry)
         self.close(removeDiac(self["text"].getText()).strip().rstrip('|').strip(), self.configEntry)
     except:
         log.logError("OK VirtualKeyBoardCFG failed.\n%s"%traceback.format_exc())
         raise
Example #4
0
 def ok(self):
     try:
         #self.close(self.text.encode("utf-8"), self.configEntry)
         self.close(removeDiac(self.text), self.configEntry)
     except:
         log.logError("OK VirtualKeyBoardCFG failed.\n%s"%traceback.format_exc())
         raise
Example #5
0
    def __init__(self, session, currService):
        BaseArchivCZSKListSourceScreen.__init__(self, session)
        self.session = session
        self.currService = currService
        self.searchList = seeker.getCapabilities()
        event = EventInfo(session.nav, EventInfo.NOW).getEvent()
        self.searchExp = event and event.getEventName() or ''
        self.searchExp = removeDiac(self.searchExp)
        self['red_label'] = StaticText(_("change search expression"))
        self['green_label'] = StaticText(_("remove diacritic"))
        self['blue_label'] = StaticText(_("choose from EPG"))
        self['search'] = Label(self.searchExp)

        self["actions"] = ActionMap(
            ["archivCZSKActions"], {
                "ok": self.ok,
                "cancel": self.cancel,
                "up": self.up,
                "down": self.down,
                "green": self.keyGreen,
                "red": self.keyRed,
                "blue": self.keyBlue,
            }, -2)

        self.onShown.append(self.updateTitle)
Example #6
0
    def __init__(self, session, entryName, configEntry):
        try:
            self.configEntry = configEntry

            #VirtualKeyBoard.__init__(self, session, entryName.encode('utf-8'), configEntry.getValue().encode('utf-8'))
            VirtualKeyBoard.__init__(self,
                                     session,
                                     title=removeDiac(entryName),
                                     text=removeDiac(configEntry.getValue()))
            self.skinName = "VirtualKeyBoard"

            #from Plugins.Extensions.archivCZSK.engine.tools.util import decode_string
            #VirtualKeyBoard.__init__(self, session, entryName, configEntry.getValue())
            #self.skinName = "VirtualKeyBoard"
        except:
            log.logError("Init VirtualKeyBoardCFG failed.\n%s" %
                         traceback.format_exc())
            raise
Example #7
0
 def __init__(self, session, captcha_file):  
     BaseArchivCZSKScreen.__init__(self,session,False)
     VirtualKeyBoard.__init__(self, session, title=removeDiac(_('Type text of picture')))
     self["captcha"] = Pixmap()
     self.Scale = AVSwitch().getFramebufferScale()
     self.picPath = captcha_file
     self.picLoad = ePicLoad()
     self.picLoad_conn = eConnectCallback(self.picLoad.PictureData, self.decodePicture)
     self.onLayoutFinish.append(self.showPicture)
     self.onClose.append(self.__onClose)
Example #8
0
 def ask_if_download_callback(answer):
     if not answer or answer == "no":
         player_callback and player_callback()
     else:
         if answer == "yes":
             do_download()
         if answer == "change":
             downloads_path = (self.downloads_path.endswith("/")
                               and self.downloads_path
                               or self.downloads_path + "/")
             session.openWithCallback(change_download_path_callback,
                                      LocationBox,
                                      _("Select new location"),
                                      currDir=downloads_path)
         if answer == "filename":
             session.openWithCallback(change_filename_callback,
                                      VirtualKeyBoard,
                                      title=removeDiac(
                                          _("Edit filename")),
                                      text=removeDiac(filename[0]))
Example #9
0
def showCSFDInfo(session, item):
    try:
        #name = removeDiacriticsCsfd(item.name)
        name = removeDiac(item.name)
        name = name.replace('.', ' ').replace('_', ' ').replace('-', ' ')

        name = name.replace(" CZ ", "").replace(" EN ", "").replace(
            " SK ", "").replace(" DA ", "").replace(" FI ", "").replace(
                " CH ", "").replace(" HI ",
                                    "").replace(" JP ",
                                                "").replace(" KH ", "")
        name = name.replace(" RU ", "").replace(" KO ", "").replace(" SP ", "")

        year = 0
        yearStr = ""
        try:
            mask = re.compile('([0-9]{4})', re.DOTALL)
            yearStr = mask.findall(name)[0]
            year = int(yearStr)
        except:
            pass

        if ' (' in name:
            name = name[0:name.index("(")]

        name = name.strip()
        log.logDebug("Csfd search '%s', year=%s." % (name, year))

        csfdType = int(config.plugins.archivCZSK.csfdMode.getValue())

        if csfdType == 1:
            from Plugins.Extensions.archivCZSK.gui.archivcsfd import ArchivCSFD
            session.open(ArchivCSFD, name, year)
        elif csfdType == 2:
            from Plugins.Extensions.CSFD.plugin import CSFD
            session.open(CSFD, name)
        elif csfdType == 3:
            from Plugins.Extensions.CSFDLite.plugin import CSFDLite
            try:
                session.open(CSFDLite, name, yearStr)
            except:
                log.logDebug("Trying CsfdLite older version compatibility...")
                session.open(CSFDLite, name)
        else:
            raise Exception("CsfdMode '%s' not supported." % csfdType)
    except:
        log.logError(
            "Show CSFD info failed (plugin may not be installed).\n%s" %
            traceback.format_exc())
        try:
            showInfoMessage(session, _("Show CSFD info failed."), timeout=6)
        except:
            pass
Example #10
0
 def __init__(self, session, captcha_file):
     BaseArchivCZSKScreen.__init__(self, session, False)
     VirtualKeyBoard.__init__(self,
                              session,
                              title=removeDiac(_('Type text of picture')))
     self["captcha"] = Pixmap()
     self.Scale = AVSwitch().getFramebufferScale()
     self.picPath = captcha_file
     self.picLoad = ePicLoad()
     self.picLoad_conn = eConnectCallback(self.picLoad.PictureData,
                                          self.decodePicture)
     self.onLayoutFinish.append(self.showPicture)
     self.onClose.append(self.__onClose)
Example #11
0
 def askOverrideCB(callback=None):
     if callback:
         if callback[1] == "override":
             try:
                 if dInstance:
                     dManager.removeDownload(dInstance)
                 else:
                     os.remove(download.local)
                 dManager.addDownload(download)
             except OSError as e:
                 print e
         elif callback[1] == "rename":
             session.openWithCallback(renameCB, VirtualKeyBoard, title=removeDiac(_("Rename filename")), text=removeDiac(download.filename))
Example #12
0
 def askOverrideCB(callback=None):
     if callback:
         if callback[1] == "override":
             try:
                 if dInstance:
                     dManager.removeDownload(dInstance)
                 else:
                     os.remove(download.local)
                 dManager.addDownload(download)
             except OSError as e:
                 print e
         elif callback[1] == "rename":
             session.openWithCallback(renameCB, VirtualKeyBoard, title=removeDiac(_("Rename filename")), text=removeDiac(download.filename))
Example #13
0
    def __init__(self, session, entryName, configEntry):
        try:
            self.configEntry = configEntry
            
            #VirtualKeyBoard.__init__(self, session, entryName.encode('utf-8'), configEntry.getValue().encode('utf-8'))
            VirtualKeyBoard.__init__(self, session, title=removeDiac(entryName), text=removeDiac(configEntry.getValue()))
            self.skinName = "VirtualKeyBoard"

            #from Plugins.Extensions.archivCZSK.engine.tools.util import decode_string
            #VirtualKeyBoard.__init__(self, session, entryName, configEntry.getValue())
            #self.skinName = "VirtualKeyBoard"
        except:
            log.logError("Init VirtualKeyBoardCFG failed.\n%s"%traceback.format_exc())
            raise
Example #14
0
    def showCSFDInfo(self, session, searchExp):
        try:
            name = removeDiac(searchExp)
            name = name.replace('.', ' ').replace('_', ' ').replace('*', '')

            # remove languages ... "Mother - CZ, EN, KO (2017)"
            name = re.sub("\s-\s[A-Z]{2}(,\s[A-Z]{2})*\s\(", " (", name)

            year = 0
            yearStr = ""
            try:
                mask = re.compile('([0-9]{4})', re.DOTALL)
                yearStr = mask.findall(name)[0]
                year = int(yearStr)
            except:
                pass
            # remove year
            name = re.sub("\([0-9]{4}\)", "", name)

            name = name.strip()
            log.logDebug("Csfd search '%s', year=%s." % (name, year))

            csfdType = int(config.plugins.archivCZSK.csfdMode.getValue())

            if csfdType == 1:
                from Plugins.Extensions.archivCZSK.gui.archivcsfd import ArchivCSFD
                session.open(ArchivCSFD, name, year)
            elif csfdType == 2:
                from Plugins.Extensions.CSFD.plugin import CSFD
                session.open(CSFD, name)
            elif csfdType == 3:
                from Plugins.Extensions.CSFDLite.plugin import CSFDLite
                try:
                    session.open(CSFDLite, name, yearStr)
                except:
                    log.logDebug(
                        "Trying CsfdLite older version compatibility...")
                    session.open(CSFDLite, name)
            else:
                raise Exception("CsfdMode '%s' not supported." % csfdType)
        except:
            log.logError(
                "Show CSFD info failed (plugin may not be installed).\n%s" %
                traceback.format_exc())
            try:
                showInfoMessage(session,
                                _("Show CSFD info failed."),
                                timeout=6)
            except:
                pass
Example #15
0
 def ask_if_download_callback(answer):
     if not answer or answer == "no":
         player_callback and player_callback()
     else:
         if answer == "yes":
             do_download()
         if answer == "change":
             downloads_path = (self.downloads_path.endswith("/") and 
                     self.downloads_path or self.downloads_path + "/")
             session.openWithCallback(change_download_path_callback,
                     LocationBox, _("Select new location"),
                     currDir=downloads_path)
         if answer == "filename":
             session.openWithCallback(change_filename_callback,
                     VirtualKeyBoard, title = removeDiac(_("Edit filename")),
                     text = filename[0])
Example #16
0
def showCSFDInfo(session, item):
    try:
        #name = removeDiacriticsCsfd(item.name)
        name = removeDiac(item.name)
        name = name.replace('.', ' ').replace('_', ' ').replace('*','')
        
        # remove languages ... "Mother - CZ, EN, KO (2017)"
        name = re.sub("\s-\s[A-Z]{2}(,\s[A-Z]{2})*\s\(", " (", name)
        
        year = 0
        yearStr = ""
        try:
            mask = re.compile('([0-9]{4})', re.DOTALL)
            yearStr = mask.findall(name)[0]
            year = int(yearStr)
        except:
            pass
        # remove year
        name = re.sub("\([0-9]{4}\)","", name)

        name = name.strip()
        log.logDebug("Csfd search '%s', year=%s."%(name,year))

        csfdType = int(config.plugins.archivCZSK.csfdMode.getValue())

        if csfdType == 1:
            from Plugins.Extensions.archivCZSK.gui.archivcsfd import ArchivCSFD
            session.open(ArchivCSFD, name, year)
        elif csfdType == 2:
            from Plugins.Extensions.CSFD.plugin import CSFD
            session.open(CSFD, name)
        elif csfdType == 3:
            from Plugins.Extensions.CSFDLite.plugin import CSFDLite
            try:
                session.open(CSFDLite, name, yearStr)
            except:
                log.logDebug("Trying CsfdLite older version compatibility...")
                session.open(CSFDLite, name)
        else:
            raise Exception("CsfdMode '%s' not supported." % csfdType)
    except:
        log.logError("Show CSFD info failed (plugin may not be installed).\n%s"%traceback.format_exc())
        try:
            showInfoMessage(session, _("Show CSFD info failed."), timeout=6)
        except:
            pass
Example #17
0
    def videoLink(self, url):
        result = []
        doc = ''
        try:
            cacheTime = 1
            # this shit can failed <main> not contain <iframe> ... clear cache workaround not help, no-cache also .. f*****g markiza server
            doc = MarkizaCache().get_data_cached(url, self.useCache, -1) # special
            main = doc.find('main')
            url = main.find('iframe')['src']
            httpdata = MarkizaCache().get_data_cached(url, self.useCache, 1, False)

            httpdata = httpdata.replace("\r","").replace("\n","").replace("\t","")

            playlist = {}
            src = re.search('src = ({.+?});',httpdata,re.DOTALL).group(1)
            videoUrl = json.loads(src)
            if videoUrl:
                thumb = re.compile('<meta property="og:image" content="(.+?)">').findall(httpdata)
                thumb = thumb[0] if len(thumb) > 0 else ''
                desc = re.compile('<meta name="description" content="(.+?)">').findall(httpdata)
                desc = desc[0] if len(desc) > 0 else ''
                name = re.compile('<meta property="og:title" content="(.+?)">').findall(httpdata)
                name = name[0] if len(name) > 0 else '?'
                item = []
                item.append({'bitrates': videoUrl, 'contentTitle': toString(name), 'contentDescription': toString(desc), 'thumbnail': thumb})
                playlist['playlist'] = item;
            else:
                url = re.search('relatedLoc: "(.+?)",',httpdata,re.DOTALL).group(1).replace('\/','/')
                jsonData = MarkizaCache().get_data_cached(url, self.useCache, 1, False)
                playlist = json.loads(jsonData)
                # not working correctly on VTi 11
                # maybe @TODO
                # result.append(self.addLink('PREHRAŤ VŠETKO',url))

            if playlist and len(playlist['playlist']) > 0:
                # sort by title
                data = sorted(playlist['playlist'], key=lambda i: removeDiac(i['contentTitle']))
                for url in data:
                    result.append(self.addLink(url['contentTitle'],url['bitrates']['hls'],url['thumbnail']))
            else:
                raise Exception('Chyba - Video nejde prehrat')
        except:
            MarkizaCache().clear_cache(self.useCache) # special
            #markizalog.logDebug('########## POJEBANY REPSPONSE (<iframe>):\n%s'%doc)
            raise Exception("Ziskanie videolinku zlyhalo (clear cache).\n%s"%traceback.format_exc())
        return result
Example #18
0
def sanitize_filename(value):
    tmp = removeDiac(value)
    tmp = unicode(re.sub(r'(?u)[^\w\s.-]', '', tmp).strip().lower())
    return re.sub(r'(?u)[-\s]+', '-', tmp)
Example #19
0
    def download(self,
                 session,
                 item,
                 start_callback=None,
                 finish_callback=None,
                 player_callback=None,
                 play_download=False,
                 mode=""):
        #closure fun :)
        def do_download():
            try:
                # have to rename to start_cb otherwise python
                # doesnt see start_callback
                start_cb = start_callback
                finish_cb = finish_callback
                if start_cb is None:
                    start_cb = DownloadManagerMessages.startDownloadCB
                if finish_cb is None:
                    finish_cb = DownloadManagerMessages.finishDownloadCB
                override_cb = DownloadManagerMessages.overrideDownloadCB

                downloadManager = DownloadManager.getInstance()
                d = downloadManager.createDownload(name=item.name,
                                                   url=item.url,
                                                   stream=item.stream,
                                                   filename=filename[0],
                                                   live=item.live,
                                                   destination=destination[0],
                                                   startCB=start_cb,
                                                   finishCB=finish_cb,
                                                   quiet=False,
                                                   playDownload=play_download,
                                                   headers=headers,
                                                   mode=mode)

                if item.subs:
                    remote = item.subs
                    local = os.path.splitext(d.local)[0] + '.srt'
                    if os.path.isfile(remote):
                        copyfile(remote, local)
                    elif remote.startswith('http'):
                        util.download_to_file(remote, local)
                downloadManager.addDownload(d, override_cb)
            except:
                log.logError("Download '%s' failed.\n%s" %
                             (item.name, traceback.format_exc()))
                session.openWithCallback(
                    ask_if_download_callback,
                    MessageBox,
                    text=_("Download error, look into the log file."),
                    timeout=10,
                    type=MessageBox.TYPE_ERROR)
                pass

        def change_filename_callback(answer):
            if answer:
                filename[0] = answer
            ask_if_download()

        def change_download_path_callback(answer):
            if answer:
                destination[0] = answer
            ask_if_download()

        def ask_if_download_callback(answer):
            if not answer or answer == "no":
                player_callback and player_callback()
            else:
                if answer == "yes":
                    do_download()
                if answer == "change":
                    downloads_path = (self.downloads_path.endswith("/")
                                      and self.downloads_path
                                      or self.downloads_path + "/")
                    session.openWithCallback(change_download_path_callback,
                                             LocationBox,
                                             _("Select new location"),
                                             currDir=downloads_path)
                if answer == "filename":
                    session.openWithCallback(change_filename_callback,
                                             VirtualKeyBoard,
                                             title=removeDiac(
                                                 _("Edit filename")),
                                             text=filename[0])
                    #text = toString(filename[0]))

        def ask_if_download():
            filename[0], size_bytes = getFilenameAndLength(
                item.url, headers, filename[0])
            size_mbytes = size_bytes and util.BtoMB(size_bytes) or "???"
            free_bytes = util.get_free_space(destination[0])
            free_mbytes = free_bytes and util.BtoMB(free_bytes) or "???"

            message = "%s:\n\n%s:\n%s - %sMB\n\n%s:\n%s - %sMB %s\n\n%s:\n%s" % (
                _("Do you want to download"), _("Source"), toString(
                    item.name), str(size_mbytes), _("Destination"),
                toString(destination[0]), str(free_mbytes), _("free"),
                _("Filename"), toString(filename[0]))
            choices = [(_("yes"), "yes"), (_("no"), "no"),
                       (_("Change location"), "change"),
                       (_("Edit filename"), "filename")]

            session.openWithCallback(ask_if_download_callback,
                                     MessageBox,
                                     message,
                                     MessageBox.TYPE_YESNO,
                                     list=choices)

        headers = item.settings['extra-headers']
        destination = [self.downloads_path]
        filename = [item.filename or item.name]
        filename[0] = removeDiac(filename[0])
        ask_if_download()
Example #20
0
 def changeSearchExpCB(self, word=None):
     if word is not None and len(word) > 0:
         self.searchExp = removeDiac(word)
         self['search'].setText(self.searchExp)
Example #21
0
    def download(self, session, item, start_callback=None, finish_callback=None,
            player_callback = None, play_download=False, mode=""):
        #closure fun :)
        def do_download():
            try:
                # have to rename to start_cb otherwise python
                # doesnt see start_callback
                start_cb = start_callback
                finish_cb = finish_callback
                if start_cb is None:
                    start_cb = DownloadManagerMessages.startDownloadCB
                if finish_cb is None:
                    finish_cb = DownloadManagerMessages.finishDownloadCB
                override_cb = DownloadManagerMessages.overrideDownloadCB

                downloadManager = DownloadManager.getInstance()
                d = downloadManager.createDownload(
                    name=item.name, url=item.url, 
                    stream=item.stream, filename=filename[0],
                    live=item.live, destination=destination[0],
                    startCB=start_cb, finishCB=finish_cb, quiet=False,
                    playDownload=play_download, headers=headers, mode=mode)

                if item.subs:
                    remote = item.subs
                    local = os.path.splitext(d.local)[0] + '.srt'
                    if os.path.isfile(remote):
                        copyfile(remote, local)
                    elif remote.startswith('http'):
                        util.download_to_file(remote, local)
                downloadManager.addDownload(d, override_cb)
            except:
                log.logError("Download '%s' failed.\n%s"%(item.name, traceback.format_exc()))
                session.openWithCallback(ask_if_download_callback, MessageBox, text=_("Download error, look into the log file."), timeout=10, type=MessageBox.TYPE_ERROR)
                pass

        def change_filename_callback(answer):
            if answer:
                filename[0] = answer
            ask_if_download()

        def change_download_path_callback(answer):
            if answer:
                destination[0] = answer
            ask_if_download()

        def ask_if_download_callback(answer):
            if not answer or answer == "no":
                player_callback and player_callback()
            else:
                if answer == "yes":
                    do_download()
                if answer == "change":
                    downloads_path = (self.downloads_path.endswith("/") and 
                            self.downloads_path or self.downloads_path + "/")
                    session.openWithCallback(change_download_path_callback,
                            LocationBox, _("Select new location"),
                            currDir=downloads_path)
                if answer == "filename":
                    session.openWithCallback(change_filename_callback,
                            VirtualKeyBoard, title = removeDiac(_("Edit filename")),
                            text = filename[0])
                            #text = toString(filename[0]))

        def ask_if_download():
            filename[0], size_bytes = getFilenameAndLength(item.url, headers, filename[0])
            size_mbytes = size_bytes and util.BtoMB(size_bytes) or "???"
            free_bytes = util.get_free_space(destination[0])
            free_mbytes = free_bytes and util.BtoMB(free_bytes) or "???"

            message = "%s:\n\n%s:\n%s - %sMB\n\n%s:\n%s - %sMB %s\n\n%s:\n%s"%(
                    _("Do you want to download"),
                    _("Source"), toString(item.name), str(size_mbytes),
                    _("Destination"), toString(destination[0]), str(free_mbytes), _("free"),
                    _("Filename"), toString(filename[0]))
            choices = [ (_("yes"), "yes"), (_("no"), "no"), 
                    (_("Change location"), "change"), (_("Edit filename"), "filename") ]

            session.openWithCallback(ask_if_download_callback,
                    MessageBox, message, MessageBox.TYPE_YESNO, list=choices)

        headers = item.settings['extra-headers']
        destination = [self.downloads_path]
        filename = [item.filename or item.name]
        filename[0] = removeDiac(filename[0])
        ask_if_download()
Example #22
0
def sanitize_filename(value):
    from Plugins.Extensions.archivCZSK import removeDiac
    tmp = removeDiac(value)
    tmp = unicode(re.sub(r'(?u)[^\w\s.-]', '', tmp).strip().lower())
    return re.sub(r'(?u)[-\s]+', '-', tmp)
Example #23
0
def sanitize_filename(value):
    tmp = removeDiac(value)
    tmp = unicode(re.sub(r'(?u)[^\w\s.-]', '', tmp).strip().lower())
    return re.sub(r'(?u)[-\s]+', '-', tmp)
Example #24
0
 def changeSearchExp(self):
     self.session.openWithCallback(self.changeSearchExpCB,
                                   VirtualKeyBoard,
                                   title=removeDiac(
                                       _("Set your search expression")),
                                   text=removeDiac(self.searchExp))