Exemple #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
 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