Пример #1
0
 def get_data_cached(self, url, post=False):
     try:
         url.index('/json/')
         self._oldapi()
     except Exception:
         pass
     headers = {
         'X-UID': self.uid,
         'X-LANG': self.tr['language'],
         'X-VER': sctop.API_VERSION,
         'Accept' : 'application/vnd.bbaron.kodi-plugin-v%s+json' % (sctop.API_VERSION),
     }
     url = self._url(url)
     code = None
     try:
         if post != False:
             util.debug("POST URL: %s %s" % (url, str(post)))
             (ret, code) = sctop.post(url, post, headers, "extend")
             self.handleHttpError(code)
             return ret
         util.info("GET x URL: %s" % url)
         ret = False
         if sctop.getSettingAsBool('usecache') is not False:
             util.debug("[SC] skusam cache")
             ret = self.cache.get(str(url))
         if not ret:
             util.debug("[SC] url BEZ cache %s" % str(url))
             (ret, code, info) = sctop.request(url, headers, "info")
             util.debug("[SC] code: %s %s" % (str(code), str(info)))
             self.handleHttpError(code, data=ret, i=info)
             if code == 200:
                 ttl = datetime.timedelta(hours=2)
                 try:
                     util.debug("[SC] info: %s " % str(info) )
                     if 'x-ttl' in info:
                         ttl = datetime.timedelta(seconds=int(info.get('x-ttl')))
                         util.debug("[SC] mame TTL: %s" % str(ttl))
                 except:
                     pass
                 try:
                     self.cache.cache.set(str(url), ret, expiration=ttl)
                 except:
                     self.cache.set(str(url), ret)
         else:
             util.debug("[SC] url z cache %s" % str(url))
         util.debug("[SC] return data")
         return ret
     except Exception as e:
         inet = sctop.getCondVisibility('System.InternetState')
         util.debug("[SC] inet scinema status: %s | %s" % (str(inet), str(e)))
         if inet is False or inet == 0:
             HANDLE = int(sys.argv[1])
             xbmcplugin.endOfDirectory(HANDLE, succeeded=False)
             sctop.dialog.ok("internet", 'Skontrolujte pripojenie na internet')
             return False
         util.error('[SC] ERROR URL: --------- %s --------' % str(traceback.format_exc()) )
         if code is None:
             sctop.dialog.ok("error", url)
         return False
Пример #2
0
 def get_data_cached(self, url, post=False):
     try:
         url.index('/json/')
         self._oldapi()
     except Exception:
         pass
     headers = {
         'X-UID':
         self.uid,
         'X-LANG':
         self.tr['language'],
         'X-VER':
         sctop.API_VERSION,
         'Accept':
         'application/vnd.bbaron.kodi-plugin-v%s+json' %
         (sctop.API_VERSION),
     }
     url = self._url(url)
     code = None
     try:
         if post != False:
             util.debug("POST URL: %s %s" % (url, str(post)))
             (ret, code) = sctop.post(url, post, headers, "extend")
             self.handleHttpError(code)
             return ret
         util.info("GET x URL: %s" % url)
         ret = False
         if sctop.getSettingAsBool('usecache') is not False:
             util.debug("[SC] skusam cache")
             ret = self.cache.get(str(url))
         if not ret:
             util.debug("[SC] url BEZ cache %s" % str(url))
             (ret, code, info) = sctop.request(url, headers, "info")
             util.debug("[SC] code: %s %s" % (str(code), str(info)))
             self.handleHttpError(code, data=ret, i=info)
             if code == 200:
                 ttl = datetime.timedelta(hours=2)
                 try:
                     util.debug("[SC] info: %s " % str(info))
                     if 'x-ttl' in info:
                         ttl = datetime.timedelta(
                             seconds=int(info.get('x-ttl')))
                         util.debug("[SC] mame TTL: %s" % str(ttl))
                 except:
                     pass
                 try:
                     self.cache.cache.set(str(url), ret, expiration=ttl)
                 except:
                     self.cache.set(str(url), ret)
         else:
             util.debug("[SC] url z cache %s" % str(url))
         util.debug("[SC] return data")
         return ret
     except Exception, e:
         util.error('[SC] ERROR URL: ' + str(e))
         if code is None:
             sctop.dialog.ok("error", url)
         return False
Пример #3
0
    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:
Пример #4
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
Пример #5
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
Пример #7
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