コード例 #1
0
ファイル: seeker.py プロジェクト: trtko1964/archivczsk
    def search(self, search_exp, addon_id, mode=None):
        if self.searching:
            showInfoMessage(
                self.session,
                _("You cannot search, archivCZSK Search is already running"))
            print "%s cannot search, searching is not finished" % self
            return
        if addon_id.lower() == 'csfd':
            CsfdSearch().showCSFDInfo(self.session, search_exp)
            return self.cb()
        elif addon_id.lower() == 'internalcsfd':

            return self.cb()
        else:
            searcher = getSearcher(self.session, addon_id, self.archivCZSK,
                                   self._successSearch, self._errorSearch)
            if searcher is not None:
                self.searcher = searcher
                self.searching = True
                self.addon = searcher.addon
                searcher.start()
                searcher.search(search_exp, mode)
            else:
                showInfoMessage(
                    self.session,
                    _("Cannot find searcher") + ' ' + addon_id.encode('utf-8'))
                return self.cb()
コード例 #2
0
ファイル: search.py プロジェクト: natko1412/archivczsk
 def removeDiacritics(self):
     try:
         import unicodedata
     except ImportError:
         showInfoMessage(self.session, _("Cannot remove diacritics, missing unicodedata.so"))
     else:
         self.searchExp = ''.join((c for c in unicodedata.normalize('NFD', unicode(self.searchExp, 'utf-8', 'ignore')) 
                                   if unicodedata.category(c) != 'Mn')).encode('utf-8')
         self["search"].setText(self.searchExp)
コード例 #3
0
ファイル: info.py プロジェクト: Luky68/archivczsk
def showCSFDInfo(session, item):
	try:
		from Plugins.Extensions.CSFD.plugin import CSFD
	except ImportError:
		showInfoMessage(session, _("Plugin CSFD is not installed."))
	else:
		name = item.name
		name = name.replace('.', ' ').replace('_', ' ').replace('-', ' ')
		session.open(CSFD, name, False)
コード例 #4
0
def showCSFDInfo(session, item):
    try:
        from Plugins.Extensions.CSFD.plugin import CSFD
    except ImportError:
        showInfoMessage(session, _("Plugin CSFD is not installed."))
    else:
        name = item.name
        name = name.replace('.', ' ').replace('_', ' ').replace('-', ' ')
        session.open(CSFD, name, False)
コード例 #5
0
ファイル: search.py プロジェクト: m1ngr/archivczsk
 def removeDiacritics(self):
     try:
         import unicodedata
     except ImportError:
         showInfoMessage(self.session, _("Cannot remove diacritics, missing unicodedata.so"))
     else:
         self.searchExp = ''.join((c for c in unicodedata.normalize('NFD', unicode(self.searchExp, 'utf-8', 'ignore')) 
                                   if unicodedata.category(c) != 'Mn')).encode('utf-8')
         self["search"].setText(self.searchExp)
コード例 #6
0
 def open_item_success_cb(result):
     log.logDebug("Trakt (%s) call success. %s" % (action, result))
     list_items, command, args = result
     if command is not None and command.lower() == 'result_msg':
         #{'msg':msg, 'isError':isError}
         if args['isError']:
             showErrorMessage(self.session, args['msg'], 10, finishCb)
         else:
             showInfoMessage(self.session, args['msg'], 10, finishCb)
     else:
         finishCb(None)
コード例 #7
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
コード例 #8
0
ファイル: seeker.py プロジェクト: Luky68/archivczsk
 def getInstance(session, cb=None):
     if ArchivCZSKSeeker.instance is None:
         try:
             return ArchivCZSKSeeker(session, cb)
         except ImportError:
             showInfoMessage(session, _('Cannot search, archivCZSK is not installed'), 5, cb=cb)
             print 'cannot found archivCZSK'
             return None
         except Exception:
             traceback.print_exc()
             showErrorMessage(session, _('unknown error'), 5, cb=cb)
             return None
     return ArchivCZSKSeeker.instance
コード例 #9
0
ファイル: seeker.py プロジェクト: trtko1964/archivczsk
    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
コード例 #10
0
ファイル: seeker.py プロジェクト: Luky68/archivczsk
 def search(self, search_exp, addon_id, mode=None):
     if self.searching:
         showInfoMessage(self.session, _("You cannot search, archivCZSK Search is already running"))
         print "%s cannot search, searching is not finished" % self
         return
     searcher = getSearcher(self.session, addon_id, self.archivCZSK, self._successSearch, self._errorSearch)
     if searcher is not None:
         self.searcher = searcher
         self.searching = True
         self.addon = searcher.addon
         searcher.start()
         searcher.search(search_exp, mode)
     else:
         showInfoMessage(self.session, _("Cannot find searcher") + ' ' + addon_id.encode('utf-8'))
コード例 #11
0
ファイル: seeker.py プロジェクト: puntik1/archivczsk
 def getInstance(session, cb=None):
     if ArchivCZSKSeeker.instance is None:
         try:
             return ArchivCZSKSeeker(session, cb)
         except ImportError:
             log.logError("Cannot search, archivCZSK is not installed")
             showInfoMessage(session, _('Cannot search, archivCZSK is not installed'), 5, cb=cb)
             print 'cannot found archivCZSK'
             return None
         except Exception:
             log.logError("ArchivCZSKSeeker fatala error.\n%s"%traceback.format_exc())
             traceback.print_exc()
             showErrorMessage(session, _('unknown error'), 5, cb=cb)
             return None
     return ArchivCZSKSeeker.instance
コード例 #12
0
ファイル: seeker.py プロジェクト: Luky68/archivczsk
def search(session, search_exp, addon_id, mode=None, cb=None):
    """
    Vyhlada v archivCZSK hladany vyraz prostrednictvom addonu s addon_id s modom vyhladavania mode
    @param : session - aktivna session
    @param : search_exp - hladany vyraz
    @param : addon_id - id addonu v ktorom chceme vyhladavat
    @param : mode - mod vyhladavania podporovany addonom
    """
    if search_exp is None or search_exp == "":
        showInfoMessage(session, _("Empty search expression"))
        return cb()
    
    archivCZSKSeeker = ArchivCZSKSeeker.getInstance(session, cb)
    if archivCZSKSeeker is not None:
        archivCZSKSeeker.search(search_exp, addon_id, mode)
コード例 #13
0
ファイル: seeker.py プロジェクト: natko1412/archivczsk
def search(session, search_exp, addon_id, mode=None, cb=None):
    """
    Vyhlada v archivCZSK hladany vyraz prostrednictvom addonu s addon_id s modom vyhladavania mode
    @param : session - aktivna session
    @param : search_exp - hladany vyraz
    @param : addon_id - id addonu v ktorom chceme vyhladavat
    @param : mode - mod vyhladavania podporovany addonom
    """
    if search_exp is None or search_exp == "":
        showInfoMessage(session, _("Empty search expression"))
        return cb()

    archivCZSKSeeker = ArchivCZSKSeeker.getInstance(session, cb)
    if archivCZSKSeeker is not None:
        archivCZSKSeeker.search(search_exp, addon_id, mode)
コード例 #14
0
ファイル: media.py プロジェクト: trtko1964/archivczsk
 def open_item_success_cb(result):
     log.logDebug("Trakt (%s) call success. %s"%(action, result))
     #OK, ERROR
     list_items, command, args = result
     if args['isError']:
         return showErrorMessage(self.session, args['msg'], 10, finishCb)
     else:
         return showInfoMessage(self.session, args['msg'], 10, finishCb)
コード例 #15
0
ファイル: info.py プロジェクト: mx3L/archivczsk
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
コード例 #16
0
ファイル: addon.py プロジェクト: trtko1964/archivczsk
        def open_item_success_cb(result):
            def continue_cb(res):
                list_items.insert(0, PExit())
                self.content_screen.resolveCommand(command, args)
                self.content_screen.stopLoading()
                self.open_video_addon(item.addon, list_items)

            list_items, command, args = result
            try:
                #client.add_operation("SHOW_MSG", {'msg': 'some text'},
                #                                  'msgType': 'info|error|warning',     #optional
                #                                  'msgTimeout': 10,                    #optional
                #                                  'canClose': True                     #optional
                #                                 })

                if command is not None:
                    cmd = ("%s" % command).lower()
                    params = args
                    if cmd == "show_msg":
                        #dialogStart = datetime.datetime.now()
                        self.content_screen.stopLoading()
                        msgType = 'info'
                        if 'msgType' in args:
                            msgType = ("%s" % args['msgType']).lower()
                        msgTimeout = 15
                        if 'msgTimeout' in args:
                            msgTimeout = int(args['msgTimeout'])
                        canClose = True
                        if 'canClose' in args:
                            canClose = args['canClose']
                        if msgType == 'error':
                            return showErrorMessage(self.session,
                                                    args['msg'],
                                                    msgTimeout,
                                                    continue_cb,
                                                    enableInput=canClose)
                        if msgType == 'warning':
                            return showWarningMessage(self.session,
                                                      args['msg'],
                                                      msgTimeout,
                                                      continue_cb,
                                                      enableInput=canClose)
                        return showInfoMessage(self.session,
                                               args['msg'],
                                               msgTimeout,
                                               continue_cb,
                                               enableInput=canClose)
            except:
                log.logError(
                    "Execute HACK command failed (addon handler).\n%s" %
                    traceback.format_exc())
                command = None
                args = {}

            list_items.insert(0, PExit())
            self.content_screen.resolveCommand(command, args)
            self.content_screen.stopLoading()
            self.open_video_addon(item.addon, list_items)
コード例 #17
0
            def pairTrakt_cb(res):
                import json
                import urllib2
                from Plugins.Extensions.archivCZSK.settings import USER_AGENT

                def post_json(url, data, headers={}):
                    postdata = json.dumps(data)
                    headers['Content-Type'] = 'application/json'
                    req = urllib2.Request(url, postdata, headers)
                    req.add_header('User-Agent', USER_AGENT)
                    response = urllib2.urlopen(req)
                    data = response.read()
                    response.close()
                    return data

                try:
                    data = json.loads(
                        post_json(params['trakt']['url'],
                                  data={
                                      'code':
                                      params['trakt']['code'],
                                      'client_id':
                                      params['trakt']['client_id'],
                                      'client_secret':
                                      params['trakt']['client_secret']
                                  },
                                  headers={'Content-Type':
                                           'application/json'}))
                    TOKEN = data['access_token']
                    REFRESH_TOKEN = data['refresh_token']
                    expire = data['expires_in']  #seconds
                    created = data['created_at']
                    EXPIRE = expire + created

                    log.logDebug(
                        "Get token return token=%s, rtoken=%s, exp=%s" %
                        (TOKEN, REFRESH_TOKEN, EXPIRE))

                    #update settings
                    self.content_provider.video_addon.set_setting(
                        params['settings']['token'], '%s' % TOKEN)
                    self.content_provider.video_addon.set_setting(
                        params['settings']['refreshToken'],
                        '%s' % REFRESH_TOKEN)
                    self.content_provider.video_addon.set_setting(
                        params['settings']['expire'], '%s' % EXPIRE)

                    return showInfoMessage(self.session,
                                           params['msg']['success'], 20,
                                           continue_cb)
                except:
                    log.logDebug("Pair trakt failed.\n%s" %
                                 traceback.format_exc())
                return showErrorMessage(self.session, params['msg']['fail'],
                                        20, continue_cb)
コード例 #18
0
ファイル: seeker.py プロジェクト: trtko1964/archivczsk
def search(session, search_exp, addon_id, mode=None, cb=None):
    """
    Vyhlada v archivCZSK hladany vyraz prostrednictvom addonu s addon_id s modom vyhladavania mode
    @param : session - aktivna session
    @param : search_exp - hladany vyraz
    @param : addon_id - id addonu v ktorom chceme vyhladavat
    @param : mode - mod vyhladavania podporovany addonom
    """
    try:
        if search_exp is None or search_exp == "":
            showInfoMessage(session, _("Empty search expression"))
            return cb()

        archivCZSKSeeker = ArchivCZSKSeeker.getInstance(session, cb)
        if archivCZSKSeeker is not None:
            archivCZSKSeeker.search(search_exp, addon_id, mode)
    except:
        log.logError("Searching failed.\n%s" % traceback.format_exc())
        showInfoMessage(session, _("Search fatal error."))
        return cb()
コード例 #19
0
ファイル: seeker.py プロジェクト: mx3L/archivczsk
def search(session, search_exp, addon_id, mode=None, cb=None):
    """
    Vyhlada v archivCZSK hladany vyraz prostrednictvom addonu s addon_id s modom vyhladavania mode
    @param : session - aktivna session
    @param : search_exp - hladany vyraz
    @param : addon_id - id addonu v ktorom chceme vyhladavat
    @param : mode - mod vyhladavania podporovany addonom
    """
    try:
        if search_exp is None or search_exp == "":
            showInfoMessage(session, _("Empty search expression"))
            return cb()
    
        archivCZSKSeeker = ArchivCZSKSeeker.getInstance(session, cb)
        if archivCZSKSeeker is not None:
            archivCZSKSeeker.search(search_exp, addon_id, mode)
    except:
        log.logError("Searching failed.\n%s"%traceback.format_exc())
        showInfoMessage(session, _("Search fatal error."))
        return cb()
コード例 #20
0
ファイル: addon.py プロジェクト: mx3L/archivczsk
        def open_item_success_cb(result):
            def continue_cb(res):
                list_items.insert(0, PExit())
                self.content_screen.resolveCommand(command, args)
                self.content_screen.stopLoading()
                self.open_video_addon(item.addon, list_items)

            list_items, command, args = result
            try:
                #client.add_operation("SHOW_MSG", {'msg': 'some text'},
                #                                  'msgType': 'info|error|warning',     #optional
                #                                  'msgTimeout': 10,                    #optional
                #                                  'canClose': True                     #optional
                #                                 })

                if command is not None:
                   cmd = ("%s"%command).lower()
                   params = args
                   if cmd == "show_msg":
                       #dialogStart = datetime.datetime.now()
                       self.content_screen.stopLoading()
                       msgType = 'info'
                       if 'msgType' in args:
                           msgType = ("%s"%args['msgType']).lower()
                       msgTimeout = 15
                       if 'msgTimeout' in args:
                           msgTimeout = int(args['msgTimeout'])
                       canClose = True
                       if 'canClose' in args:
                           canClose = args['canClose']
                       if msgType == 'error':
                           return showErrorMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
                       if msgType == 'warning':
                           return showWarningMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
                       return showInfoMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
            except:
                log.logError("Execute HACK command failed (addon handler).\n%s"%traceback.format_exc())
                command = None
                args = {}

            list_items.insert(0, PExit())
            self.content_screen.resolveCommand(command, args)
            self.content_screen.stopLoading()
            self.open_video_addon(item.addon, list_items)
コード例 #21
0
ファイル: archivczsk.py プロジェクト: mx3L/archivczsk
 def opened_first_time(self):
     os.remove(os.path.join(settings.PLUGIN_PATH, 'firsttime'))
     text = _("This is the first time you started archivyCZSK") + "\n\n"
     text += _("For optimal usage of this plugin, you need to check") + "\n"
     text += _("if you have all neccessary video plugins installed") + "."
     showInfoMessage(self.session, text, 0, self.open_player_info)
コード例 #22
0
ファイル: media.py プロジェクト: trtko1964/archivczsk
        def open_item_success_cb(result):
            def continue_cb(res):
                self._filter_by_quality(list_items)
                if len(list_items) > 1:
                    choices = []
                    for i in list_items:
                        name = i.name
                        # TODO remove workaround of embedding
                        # quality in title in addons
                        if i.quality and i.quality not in i.name:
                            if "[???]" in i.name:
                                name = i.name.replace("[???]","[%s]"%(i.quality))
                            else:
                                name = "[%s] %s"%(i.quality, i.name)
                        choices.append((toString(name), i))
                    self.session.openWithCallback(selected_source,
                            ChoiceBox, _("Please select source"),
                            list = choices,
                            skin_name = ["ArchivCZSKVideoSourceSelection"])
                elif len(list_items) == 1:
                    item = list_items[0]
                    callback(item)
                else: # no video
                    self.content_screen.workingFinished()

            self.content_screen.stopLoading()
            self.content_screen.showList()
            list_items, command, args = result

            try:
                #client.add_operation("SHOW_MSG", {'msg': 'some text'},
                #                                  'msgType': 'info|error|warning',     #optional
                #                                  'msgTimeout': 10,                    #optional
                #                                  'canClose': True                     #optional
                #                                 })

                if command is not None:
                   cmd = ("%s"%command).lower()
                   params = args
                   if cmd == "show_msg":
                       #dialogStart = datetime.datetime.now()
                       self.content_screen.stopLoading()
                       msgType = 'info'
                       if 'msgType' in args:
                           msgType = ("%s"%args['msgType']).lower()
                       msgTimeout = 15
                       if 'msgTimeout' in args:
                           msgTimeout = int(args['msgTimeout'])
                       canClose = True
                       if 'canClose' in args:
                           canClose = args['canClose']
                       if msgType == 'error':
                           return showErrorMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
                       if msgType == 'warning':
                           return showWarningMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
                       return showInfoMessage(self.session, args['msg'], msgTimeout, continue_cb, enableInput=canClose)
            except:
                log.logError("Execute HACK command failed (media handler).\n%s"%traceback.format_exc())
                command = None
                args = {}

            self._filter_by_quality(list_items)
            if len(list_items) > 1:
                choices = []
                for i in list_items:
                    name = i.name
                    # TODO remove workaround of embedding
                    # quality in title in addons
                    if i.quality and i.quality not in i.name:
                        if "[???]" in i.name:
                            name = i.name.replace("[???]","[%s]"%(i.quality))
                        else:
                            name = "[%s] %s"%(i.quality, i.name)
                    choices.append((toString(name), i))
                self.session.openWithCallback(selected_source,
                        ChoiceBox, _("Please select source"),
                        list = choices,
                        skin_name = ["ArchivCZSKVideoSourceSelection"])
            elif len(list_items) == 1:
                item = list_items[0]
                callback(item)
            else: # no video
                self.content_screen.workingFinished()
コード例 #23
0
        def open_item_success_cb(result):
            def continue_cb(res):
                list_items = []
                args = {}
                list_items.insert(0, PExit())
                self.content_screen.startLoading()
                if not self.content_screen.refreshing:
                    self.content_screen.save()
                else:
                    self.content_screen.refreshing = False

                if self.is_search(item):
                    parent_content = self.content_screen.getParent()
                    if parent_content:
                        parent_content['refresh'] = True

                content = {
                    'parent_it': item,
                    'lst_items': list_items,
                    'refresh': False,
                    'index': kwargs.get('position', 0)
                }
                self.content_screen.load(content)
                self.content_screen.stopLoading()
                self.content_screen.showList()
                self.content_screen.workingFinished()

            def pairTrakt_cb(res):
                import json
                import urllib2
                from Plugins.Extensions.archivCZSK.settings import USER_AGENT

                def post_json(url, data, headers={}):
                    postdata = json.dumps(data)
                    headers['Content-Type'] = 'application/json'
                    req = urllib2.Request(url, postdata, headers)
                    req.add_header('User-Agent', USER_AGENT)
                    response = urllib2.urlopen(req)
                    data = response.read()
                    response.close()
                    return data

                try:
                    data = json.loads(
                        post_json(params['trakt']['url'],
                                  data={
                                      'code':
                                      params['trakt']['code'],
                                      'client_id':
                                      params['trakt']['client_id'],
                                      'client_secret':
                                      params['trakt']['client_secret']
                                  },
                                  headers={'Content-Type':
                                           'application/json'}))
                    TOKEN = data['access_token']
                    REFRESH_TOKEN = data['refresh_token']
                    expire = data['expires_in']  #seconds
                    created = data['created_at']
                    EXPIRE = expire + created

                    log.logDebug(
                        "Get token return token=%s, rtoken=%s, exp=%s" %
                        (TOKEN, REFRESH_TOKEN, EXPIRE))

                    #update settings
                    self.content_provider.video_addon.set_setting(
                        params['settings']['token'], '%s' % TOKEN)
                    self.content_provider.video_addon.set_setting(
                        params['settings']['refreshToken'],
                        '%s' % REFRESH_TOKEN)
                    self.content_provider.video_addon.set_setting(
                        params['settings']['expire'], '%s' % EXPIRE)

                    return showInfoMessage(self.session,
                                           params['msg']['success'], 20,
                                           continue_cb)
                except:
                    log.logDebug("Pair trakt failed.\n%s" %
                                 traceback.format_exc())
                return showErrorMessage(self.session, params['msg']['fail'],
                                        20, continue_cb)

            def continue_cb_normal(res):
                if not list_items and screen_command is not None:
                    self.content_screen.resolveCommand(screen_command, args)
                else:
                    list_items.insert(0, PExit())
                    if screen_command is not None:
                        self.content_screen.resolveCommand(
                            screen_command, args)

                    if not self.content_screen.refreshing:
                        self.content_screen.save()
                    else:
                        self.content_screen.refreshing = False

                    if self.is_search(item):
                        parent_content = self.content_screen.getParent()
                        if parent_content:
                            parent_content['refresh'] = True

                    content = {
                        'parent_it': item,
                        'lst_items': list_items,
                        'refresh': False,
                        'index': kwargs.get('position', 0)
                    }
                    self.content_screen.load(content)
                    self.content_screen.stopLoading()
                    self.content_screen.showList()
                    self.content_screen.workingFinished()

            list_items, screen_command, args = result

            try:
                #client.add_operation("TRAKT_PAIR", {'trakt': {'url':self.tapi.API+'/token',
                #                                                      'code':self.code,
                #                                                      'client_id':self.tapi.CLIENT_ID,
                #                                                      'client_secret': self.tapi.CLIENT_SECRET},
                #                                    'msg': {'pair': msg, 'success':succ, 'fail':fail},
                #                                    'settings': {'token': 'trakt_token',
                #                                                 'refreshToken':'trakt_refresh_token',
                #                                                 'expire':'trakt_token_expire'}})
                #client.add_operation("SHOW_MSG", {'msg': 'some text'},
                #                                  'msgType': 'info|error|warning',     #optional
                #                                  'msgTimeout': 10,                    #optional
                #                                  'canClose': True                     #optional
                #                                 })

                if screen_command is not None:
                    cmd = ("%s" % screen_command).lower()
                    params = args
                    if cmd == "trakt_pair":
                        self.content_screen.stopLoading()
                        return showInfoMessage(self.session,
                                               args['msg']['pair'], -1,
                                               pairTrakt_cb)
                    if cmd == "show_msg":
                        #dialogStart = datetime.datetime.now()
                        self.content_screen.stopLoading()
                        msgType = 'info'
                        if 'msgType' in args:
                            msgType = ("%s" % args['msgType']).lower()
                        msgTimeout = 15
                        if 'msgTimeout' in args:
                            msgTimeout = int(args['msgTimeout'])
                        canClose = True
                        if 'canClose' in args:
                            canClose = args['canClose']
                        if msgType == 'error':
                            return showErrorMessage(self.session,
                                                    args['msg'],
                                                    msgTimeout,
                                                    continue_cb_normal,
                                                    enableInput=canClose)
                        if msgType == 'warning':
                            return showWarningMessage(self.session,
                                                      args['msg'],
                                                      msgTimeout,
                                                      continue_cb_normal,
                                                      enableInput=canClose)
                        return showInfoMessage(self.session,
                                               args['msg'],
                                               msgTimeout,
                                               continue_cb_normal,
                                               enableInput=canClose)
            except:
                log.logError("Execute HACK command failed.\n%s" %
                             traceback.format_exc())
                screen_command = None
                args = {}

            if not list_items and screen_command is not None:
                self.content_screen.resolveCommand(screen_command, args)
            else:
                list_items.insert(0, PExit())
                if screen_command is not None:
                    self.content_screen.resolveCommand(screen_command, args)

                if not self.content_screen.refreshing:
                    self.content_screen.save()
                else:
                    self.content_screen.refreshing = False

                if self.is_search(item):
                    parent_content = self.content_screen.getParent()
                    if parent_content:
                        parent_content['refresh'] = True

                content = {
                    'parent_it': item,
                    'lst_items': list_items,
                    'refresh': False,
                    'index': kwargs.get('position', 0)
                }
                self.content_screen.load(content)
                self.content_screen.stopLoading()
                self.content_screen.showList()
                self.content_screen.workingFinished()
コード例 #24
0
 def opened_first_time(self):
     os.remove(os.path.join(settings.PLUGIN_PATH, 'firsttime'))
     text = _("This is the first time you started archivyCZSK") + "\n\n"
     text += _("For optimal usage of this plugin, you need to check") + "\n"
     text += _("if you have all neccessary video plugins installed") + "."
     showInfoMessage(self.session, text, 0, self.open_player_info)