def _resolve(self, itm):
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' and itm.get(
                'params').get('cp') == 'webshare.cz':
            if sctop.getSetting('wsuser') == "":
                res = sctop.yesnoDialog(sctop.getString(30945),
                                        sctop.getString(30946), "")
                if res == True:
                    sctop.openSettings('201.101')
                    return None
            try:
                from myprovider.webshare import Webshare as wx
                self.ws = wx(sctop.getSetting('wsuser'),
                             sctop.getSetting('wspass'), self.cache)
                if not self.ws.login():
                    res = sctop.yesnoDialog(sctop.getString(30945),
                                            sctop.getString(30946), "")
                    if res == True:
                        sctop.openSettings('201.101')
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata == False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        sctop.infoDialog(sctop.getString(30948) % str(udata),
                                         icon="WARNING")
                        util.debug("[SC] VIP ucet konci")

                itm['url'] = self.ws.resolve(
                    itm.get('params').get('play').get('ident'))
                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2])
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception, e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except:
Esempio n. 2
0
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api.trakt.tv', url)

        headers = {'trakt-api-key': sctop.trCL, 'trakt-api-version': '2'}

        if getTraktCredentialsInfo() == False:
            util.debug("[SC] gt 1 data: %s %s" % (str(url), str(post)))
            if post is not None:
                result = util.post_json(url, post, headers)
            else:
                result = util.request(url, headers)
            util.debug("[SC] gt 1 result: %s" % str(result))
            return result

        headers['Authorization'] = 'Bearer %s' % sctop.getSetting(
            'trakt.token')
        #util.debug('[SC] token %s' % sctop.getSetting('trakt.token'))

        if post is not None:
            result, code = sctop.post_json(url, post, headers, "extend")
        else:
            result, code = sctop.request(url, headers, "extend")
        #util.debug("[SC] trakt gt result: %s %s" % (str(result), str(code)))
        if not (code == 401 or code == 405): return result

        oauth = 'http://api.trakt.tv/oauth/token'
        opost = {
            'client_id': sctop.trCL,
            'client_secret': sctop.trSC,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': sctop.getSetting('trakt.refresh')
        }

        result, code = sctop.post_json(oauth, opost, headers, "extend")
        if code == 401:
            authTrakt()
            result, code = sctop.post_json(oauth, opost, headers, "extend")
        result = json.loads(result)

        token, refresh = result['access_token'], result['refresh_token']

        sctop.setSetting(id='trakt.token', value=token)
        sctop.setSetting(id='trakt.refresh', value=refresh)

        headers['Authorization'] = 'Bearer %s' % token

        util.debug('[SC] token: %s' % token)

        result = sctop.post_json(url, post, headers)
        return result
    except Exception as e:
        util.error(e)
        pass
Esempio n. 3
0
 def selectAudio(self):
     apri = self.win.getProperty(
         'lang.1')  #sctop.getSetting('filter_lang.1')
     if apri == '':
         apri = sctop.getSetting('filter_lang.1')
     util.debug("[SC] skusam primary %s" % str(apri))
     if not self.tryALang(apri):
         asec = self.win.getProperty(
             'lang.2')  #sctop.getSetting('filter_lang.2')
         if asec == '':
             asec = sctop.getSetting('filter_lang.2')
         util.debug("[SC] skusam secondary %s" % str(asec))
         self.tryALang(asec)
     self.win.clearProperty('lang.1')
     self.win.clearProperty('lang.2')
Esempio n. 4
0
 def _url(self, url):
     if url.startswith('plugin://'):
         return url
     
     if url.startswith('cmd://'):
         if '__self__' in url:
             url.replace('__self__', sctop.__scriptid__)
         return url
     
     if url.startswith('/'):
         url = sctop.BASE_URL + url
     
     if not url.startswith('http'):
         util.debug('[SC] nemame http v URL %s' % url)
         o = urlparse(self.base_url)
     else:
         o = urlparse(url)
     q = parse_qs(o.query)
     q.update({'uid': self.uid, 'ver': sctop.API_VERSION, 'lang': sctop.KODI_LANG})
     if sctop.getSettingAsBool('filter_audio'):
         q.update({'l' : sctop.getSetting('filter_lang.1')})
     if not url.startswith('http'):
         n = [str(o[0]),str(o[1]),str(o[2]).rstrip('./') + '/' + url.lstrip('./'),str(o[3]), '']
     else:
         n = [str(o[0]),str(o[1]),str(o[2]),str(o[3]), '']
     n[3] = urllib.urlencode(q, True)
     nurl = urlunsplit(n)
     return nurl
Esempio n. 5
0
    def system(self, data, cl=False):
        util.debug("[SC] SYSYEM CL: %s" % str(cl));
        if cl is False and "setContent" in data:
            xbmcplugin.setContent(int(sys.argv[1]), data["setContent"])
            '''
            view_mode=data["setContent"].lower()
            skin_name=xbmc.getSkinDir() # nacitame meno skinu
            util.debug("[SC] skin_name='"+skin_name+"'")
            try:
                util.debug("[SC] view mode is "+view_mode)
                view_codes=sctop.ALL_VIEW_CODES.get(view_mode)
                view_code=view_codes.get(skin_name)
                util.debug("[SC] view code for "+view_mode+" in "+skin_name+" is "+str(view_code))
                xbmc.executebuiltin("Container.SetViewMode("+str(view_code)+")")
                #xbmc.executebuiltin("Container.Refresh")
            except:
                util.debug("[SC] Unable to find view code for view mode "+str(view_mode)+" and skin "+skin_name)
            '''
                
        if cl is False and "setPluginCategory" in data:
            xbmcplugin.setPluginCategory(int(sys.argv[1]), data["setPluginCategory"])
        
        if cl is False and "addSortMethod" in data:
            xbmcplugin.addSortMethod(int(sys.argv[1]), sctop.sortmethod[int(data["addSortMethod"])])

        if cl is False and data.get('addSortMethods'):
            for m in data.get("addSortMethods"):
                xbmcplugin.addSortMethod(int(sys.argv[1]), sctop.sortmethod[int(m)])
        
        if cl is False and "setPluginFanart" in data:
            xbmcplugin.setPluginFanart(int(sys.argv[1]), data["setPluginFanart"])
        
        if cl is False and "version" in data:
            util.info("[SC] kontrola verzie: %s %s" % (str(sctop.addonInfo('version')), data["version"]))
            if sctop.addonInfo('version') != data["version"] and sctop.getSetting('ver') != data['version']:
                try:
                    sctop.dialog.ok(sctop.getString(30954), sctop.getString(30955) % str(data['version']))
                except:
                    pass
                xbmc.executebuiltin('UpdateAddonRepos')
                sctop.setSetting('ver', data['version'])
            if sctop.getSettingAsBool('cachemigrate') == '' or sctop.getSettingAsBool('cachemigrate') is False:
                self.parent.cacheMigrate()
                pass
            pass
        
        if cl is False and "focus" in data:
            self.parent.system = {"focus": data['focus']}
            
        if cl is True and "focus" in data:
            try:
                self.parent.endOfDirectory()
                util.debug("[SC] nastavujem focus na: %d" % int(data['focus']))
                xel = xbmcgui.Window(xbmcgui.getCurrentWindowId())
                ctr = xel.getControl(xel.getFocusId())
                ctr.selectItem(int(data['focus']))
            except Exception as e:
                util.debug("[SC] error focus :-( %s" % str(traceback.format_exc()))
                pass
    def __init__(self, username=None, password=None, filter=None, uid=None):
        ContentProvider.__init__(self,
                                 name='czsklib',
                                 base_url=sctop.BASE_URL,
                                 username=username,
                                 password=password,
                                 filter=filter)

        self.tr = tracker.TrackerInfo().getSystemInfo()
        self.uid = uid
        util.UA = self.tr['useragent'] + ' ver' + str(
            sctop.addonInfo('version'))
        #util.debug("[SC] tr: %s" % str(self.tr))
        self.cache = sctop.cache
        self.ws = wx(sctop.getSetting('wsuser'), sctop.getSetting('wspass'),
                     self.cache)
        util.debug("[SC] init cache %s" % self.cache.__class__.__name__)
        util.init_urllib(self.cache)
        cookies = self.cache.get('cookies')
        hasTrakt = str(sctop.getSetting('trakt.token') != '')
        util.debug('[SC] has trakt: %s' % hasTrakt)
        sctop.win.setProperty('sc.trakt', hasTrakt)
    def _url(self, url):
        if url.startswith('plugin://'):
            return url

        if url.startswith('cmd://'):
            if '__self__' in url:
                url.replace('__self__', sctop.__scriptid__)
            return url

        if url.startswith('/'):
            url = sctop.BASE_URL + url

        if not url.startswith('http'):
            util.debug('[SC] nemame http v URL %s' % url)
            o = urlparse(self.base_url)
        else:
            o = urlparse(url)
        q = parse_qs(o.query)
        q.update({
            'uid': self.uid,
            'ver': sctop.API_VERSION,
            'lang': sctop.KODI_LANG,
            'v': sctop.addonInfo('version')
        })

        util.debug(
            '[SC] providers [%s] [%s]' %
            (str(sctop.getSetting('kruser')), str(sctop.getSetting('wsuser'))))
        if sctop.getSetting('kruser') != '' and sctop.getSetting(
                'wsuser') != '':
            q.update({'pro': 'kraska,webshare'})
        elif sctop.getSetting('kruser') != '':
            q.update({'pro': 'kraska'})
        elif sctop.getSetting('wsuser') != '':
            q.update({'pro': 'webshare'})

        if sctop.getSettingAsBool('filter_audio'):
            q.update({'l': sctop.getSetting('filter_lang.1')})
        if not url.startswith('http'):
            n = [
                str(o[0]),
                str(o[1]),
                str(o[2]).rstrip('./') + '/' + url.lstrip('./'),
                str(o[3]), ''
            ]
        else:
            n = [str(o[0]), str(o[1]), str(o[2]), str(o[3]), '']
        n[3] = urllib.urlencode(q, True)
        nurl = urlunsplit(n)
        return nurl
Esempio n. 8
0
    def _resolve(self, itm):
        util.debug("[SC] _resolve")
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files':
            if sctop.getSetting('wsuser') == "":
                res = sctop.yesnoDialog(sctop.getString(30945),
                                        sctop.getString(30946), "")
                if res == True:
                    sctop.openSettings('201.101')
                    return None
            try:
                from myprovider.webshare import Webshare as wx
                self.ws = wx(sctop.getSetting('wsuser'),
                             sctop.getSetting('wspass'), self.cache)
                if not self.ws.login():
                    res = sctop.yesnoDialog(sctop.getString(30945),
                                            sctop.getString(30946), "")
                    if res == True:
                        sctop.openSettings('201.101')
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata == False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        sctop.infoDialog(sctop.getString(30948) % str(udata),
                                         icon="WARNING")
                        util.debug("[SC] VIP ucet konci")

                try:
                    util.debug('[SC] ideme pre ident ')
                    ident = self._json(self._url(itm['url']))['ident']
                except:
                    ident = '6d8359zW1u'
                    pass

                try:
                    jsdata = json.loads(sctop.request(
                        self._url('/Stats/file')))
                    if 'ident' in jsdata:
                        sctop.request(self.ws.resolve(jsdata['ident']))
                except Exception as e:
                    pass

                itm['url'] = self.ws.resolve(ident)
                try:
                    data = {
                        'scid': itm['id'],
                        'action': 'start',
                    }
                    util.debug("[SC] prehravanie %s" % str(data))
                    sctop.player.scid = itm['id']
                    sctop.player.action(data)
                except Exception as e:
                    util.debug(
                        '[SC] nepodarilo sa vykonat akciu "start" %s | %s' %
                        (str(e), str(traceback.format_exc())))

                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2])
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except Exception as e:
                util.debug("[SC] chyba.... %s %s" %
                           (str(e), str(traceback.format_exc())))
                bug.onExceptionRaised()
                pass
        itm['title'] = self.parent.encode(itm['title'])

        return itm
    def _resolve(self, itm):
        util.debug("[SC] _resolve")
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' or itm.get(
                'provider') == 'webshare':
            if sctop.getSetting('wsuser') == "":
                sctop.infoDialog(sctop.getString(30945),
                                 sctop.getString(30946))
                return None
            try:
                if not self.ws.login():
                    sctop.infoDialog(sctop.getString(30945),
                                     sctop.getString(30946))
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata is False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        try:
                            if sctop.getSetting('ws_notify') != '' and int(
                                    sctop.getSetting('ws_notify')
                            ) > int(datetime.datetime.now().strftime("%s")):
                                sctop.infoDialog(sctop.getString(30948) %
                                                 str(udata),
                                                 icon="WARNING")
                            else:
                                sctop.setSetting(
                                    "ws_notify",
                                    str(
                                        int(datetime.datetime.now().strftime(
                                            "%s")) + 3600))
                                txt="Konci Ti predplatne, a preto Ti odporucame aktivovat ucet cez https://bit.ly/sc-kra " \
                                + "za zvyhodnene ceny. " \
                                + "Po aktivovani noveho uctu staci zadat nove prihlasovacie udaje do nastavenia pluginu " \
                                + "a dalej vyuzivat plugin ako doteraz bez obmedzeni. "
                                sctop.dialog.ok("Upozornenie...", txt)
                        except:
                            util.debug('[SC] notify error %s' %
                                       str(traceback.format_exc()))
                        util.debug("[SC] VIP ucet konci")

                try:
                    util.debug('[SC] ideme pre webshare ident %s' % itm['url'])
                    ident = self._json(self._url(itm['url']))['ident']
                except:
                    ident = '6d8359zW1u'
                    pass

                try:
                    jsdata = json.loads(sctop.request(
                        self._url('/Stats/file')))
                    if 'ident' in jsdata:
                        sctop.request(self.ws.resolve(jsdata['ident']))
                except Exception as e:
                    pass

                itm['url'] = self.ws.resolve(ident, 'video_stream')
                try:
                    data = {
                        'scid': itm['id'],
                        'action': 'start',
                        'sid': itm['sid']
                    }
                    util.debug("[SC] prehravanie %s" % str(data))
                    sctop.player.scid = itm['id']
                    sctop.player.action(data)
                except Exception as e:
                    util.debug(
                        '[SC] nepodarilo sa vykonat akciu "start" %s | %s' %
                        (str(e), str(traceback.format_exc())))

                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2], 'file_download')
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except Exception as e:
                util.debug("[SC] chyba.... %s %s" %
                           (str(e), str(traceback.format_exc())))
                bug.onExceptionRaised()
                pass
        elif itm.get('provider') == 'kraska':
            try:
                kra = Kraska(sctop.getSetting('kruser'),
                             sctop.getSetting('krpass'), self.cache)

                try:
                    util.debug('[SC] ideme pre kra ident %s' % itm['url'])
                    ident = self._json(self._url(itm['url']))['ident']
                except Exception as e:
                    util.debug('[SC] error get ident: %s' %
                               str(traceback.format_exc()))
                    return

                itm['url'] = kra.resolve(ident)
                itm['headers'] = {'User-Agent': util.UA}
                try:
                    if itm['subs'] is not None:
                        if "kra.sk" in itm['subs']:
                            import urlparse
                            import re
                            o = urlparse(itm['subs'])
                            g = re.split('/', o[2] if o[5] == '' else o[5])
                            util.debug("[SC] kra.sk titulky: %s | %s" %
                                       (str(g[2]), itm['subs']))
                            url = self.kr.resolve(g[2])
                            itm['subs'] = url
                            content = sctop.request(url)
                            itm['subs'] = self.parent.saveSubtitle(
                                content, 'cs', False)
                            util.debug("[SC] posielam URL na titulky: %s" %
                                       itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba KRA titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
            except Exception as e:
                util.debug('[SC] kra error')
                pass
        itm['title'] = self.parent.encode(itm['title'])

        return itm
Esempio n. 10
0
def getTraktCredentialsInfo():
    user = sctop.getSetting('trakt.user').strip()
    token = sctop.getSetting('trakt.token')
    refresh = sctop.getSetting('trakt.refresh')
    if (user == '' or token == '' or refresh == ''): return False
    return True
Esempio n. 11
0
def getTrakt(url, post=None, output='content', method=None):
    try:
        use_ssl = sctop.getSettingAsBool('UseSSL')
        url = urlparse.urljoin(
            'http%s://api.trakt.tv' % ('s' if use_ssl else ''), url)

        headers = {'trakt-api-key': sctop.trCL, 'trakt-api-version': '2'}

        if getTraktCredentialsInfo() == False:
            util.debug("[SC] gt 1 data: %s %s" % (str(url), str(post)))
            if post is not None:
                result = util.post_json(url, post, headers)
            else:
                result = util.request(url, headers)
            util.debug("[SC] gt 1 result: %s" % str(result))
            return result

        headers[
            'Authorization'] = 'Bearer %s' % sctop.getSetting('trakt.token')
        #util.debug('[SC] token %s' % sctop.getSetting('trakt.token'))

        if post is not None:
            result, code = sctop.post_json(url, post, headers, "extend")
            info = None
        else:
            result, code, info = sctop.request(
                url, headers, "info", method=method)
        #util.debug("[SC] trakt gt result: %s %s" % (str(result), str(code)))
        if not (code == 401 or code == 405):
            if output == "content":
                return result
            else:
                return (result, code, info)

        oauth = 'http%s://api.trakt.tv/oauth/token' % ('s' if use_ssl else '')
        opost = {
            'client_id': sctop.trCL,
            'client_secret': sctop.trSC,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': sctop.getSetting('trakt.refresh')
        }

        result, code = sctop.post_json(oauth, opost, headers, "extend")
        if code == 401:
            authTrakt()
            result, code = sctop.post_json(oauth, opost, headers, "extend")
        result = json.loads(result)

        token, refresh = result['access_token'], result['refresh_token']

        sctop.setSetting(setting='trakt.token', value=token)
        sctop.setSetting(setting='trakt.refresh', value=refresh)

        headers['Authorization'] = 'Bearer %s' % token

        util.debug('[SC] token: %s' % token)

        result = sctop.post_json(url, post, headers)
        return result
    except Exception as e:
        util.error(e)
        pass
Esempio n. 12
0
def getTraktCredentialsInfo():
    user = sctop.getSetting('trakt.user').strip()
    token = sctop.getSetting('trakt.token')
    refresh = sctop.getSetting('trakt.refresh')
    if (user == '' or token == '' or refresh == ''): return False
    return True