def Get_JSON_response(url, cache_days=7): xbmc.log('[%s]: Trying to get %s' % (addon_name, url)) now = time.time() # Language correction if url.find('lang=') == -1: if url.find('?') > 0: url = "%s&lang=%s" % (url, get_ui_language()) else: url = "%s?lang=%s" % (url, get_ui_language()) hashed_url = hashlib.md5(url).hexdigest() cache_seconds = int(cache_days * 86400) response = a.get_page_from_db(hashed_url, cache_seconds) # xbmc.log('[%s]: JSON response - %s' % (addon_name, response.encode('utf-8'))) if not response: xbmc.log("[%s]: %s is not in cache, trying download data" % (addon_name, url)) response = GET(url) try: result = simplejson.loads(response) xbmc.log("[%s]: %s download in %f seconds" % (addon_name, url, time.time() - now)) a.set_page_to_db(hashed_url, int(time.time()), response) except Exception as e: xbmc.log("[%s]: Get_JSON_response ERROR! Response - %s.\n %s" % (addon_name, response, e)) result = {'result': 'error'} else: result = simplejson.loads(response) xbmc.log("[%s]: %s loaded from cache in %f seconds" % (addon_name, url, time.time() - now)) #xbmc.log('[%s]: JSON responce - %s' % (addon_name, result)) return result
def Get_JSON_response(url, cache_days=7): xbmc.log("[%s]: Trying to get %s" % (addon_name, url)) now = time.time() # Language correction if url.find("lang=") == -1: if url.find("?") > 0: url = "%s&lang=%s" % (url, get_ui_language()) else: url = "%s?lang=%s" % (url, get_ui_language()) hashed_url = hashlib.md5(url).hexdigest() cache_seconds = int(cache_days * 86400) response = a.get_page_from_db(hashed_url, cache_seconds) # xbmc.log('[%s]: JSON response - %s' % (addon_name, response.encode('utf-8'))) if not response: xbmc.log("[%s]: %s is not in cache, trying download data" % (addon_name, url)) response = GET(url) try: result = simplejson.loads(response) xbmc.log("[%s]: %s download in %f seconds" % (addon_name, url, time.time() - now)) a.set_page_to_db(hashed_url, int(time.time()), response) except Exception as e: xbmc.log("[%s]: Get_JSON_response ERROR! Response - %s.\n %s" % (addon_name, response, e)) result = {"result": "error"} else: result = simplejson.loads(response) xbmc.log("[%s]: %s loaded from cache in %f seconds" % (addon_name, url, time.time() - now)) # xbmc.log('[%s]: JSON responce - %s' % (addon_name, result)) return result
def GET(url, old_url=None, login=False, post=False, post_data=None): try: dicParams = {} linkParams = [] hashParams = [] dic = a.get_login_from_db() if dic['cookie']: cookie = simplejson.loads(base64.b64decode(dic['cookie'])) else: cookie = None usr = dic['login'] pwd = dic['password'] # Language correction if url.find('lang=') == -1 and not post and not url.startswith( 'auth/') and not url.startswith('search'): if url.find('?') > 0: url = "%s&lang=%s" % (url, get_ui_language()) else: url = "%s?lang=%s" % (url, get_ui_language()) page, _, params = url.partition('?') if params: params = params.split('&') for param in params: key, _, value = param.partition('=') dicParams[key] = value for keys in dicParams: linkParams.append('%s=%s' % (keys, urllib.quote_plus(dicParams[keys]))) hashParams.append('%s=%s' % (keys, dicParams[keys])) linkParams = '&'.join(reversed(linkParams)) hashParams = ''.join(reversed(hashParams)) else: hashParams = '' linkParams = '' m = hashlib.md5() m.update('%s%s' % (hashParams, API_Private_Key_MEGOGO)) if not post: target = '%s/%s?%s&sign=%s' % ( API_URL, page, linkParams, '%s%s' % (m.hexdigest(), API_Public_Key_MEGOGO)) else: target = '%s/%s?%s&sign=%s' % ( PAY_URL, page, linkParams, '%s%s' % (m.hexdigest(), API_Public_Key_MEGOGO)) xbmc.log('[%s]: GET Target:\n%s' % (addon_name, target)) # xbmc.log('[%s]: GET\nUSR - %s\nPASS - %s\nCookie - %s\nTarget - %s' % (addon_name, usr, pwd, cookie, target)) if cookie and not old_url and not post: request = requests.get(target, cookies=cookie, headers={'User-Agent': UA}, timeout=8) # xbmc.log('[%s]: GET cookie and not old_url, request - %s' % (addon_name, request)) http = request.text # xbmc.log('[%s]: GET cookie and not old_url, http - %s' % (addon_name, http.encode('utf-8'))) return http.encode('utf-8') # log in account in megogo.net elif usr and pwd and login and not post: # xbmc.log('[%s]: GET elif usr and pwd and login, url - %s' % (addon_name, url)) if not url.startswith('auth/login?login='******'auth/login?login=%s&password=%s&remember=1' % (usr, pwd), old_url=url, login=True) else: session = requests.session() request = session.get(target, headers={'User-Agent': UA}, timeout=8) http = request.text if http.startswith('{"result":"ok"'): cookies = requests.utils.dict_from_cookiejar( session.cookies) # xbmc.log('[%s]: NEW COOKIE - %s' % (addon_name, cookies)) a.cookie_to_db( base64.b64encode(str(cookies).replace("'", '"'))) if old_url: # xbmc.log('[%s]: GET elif usr and pwd, old_url - %s' % (addon_name, old_url)) GET(old_url) else: # xbmc.log('[%s]: return GET elif usr and pwd, http - %s' % (addon_name, http.encode('utf-8'))) return http.encode('utf-8') else: return None else: if post_data: post_data = urllib.urlencode(post_data) request = urllib2.Request(url=target, data=post_data, headers={'User-Agent': UA}) request = urllib2.urlopen(request) http = request.read() request.close() # xbmc.log('[%s]: GET else, http - %s' % (addon_name, http)) return http except Exception as e: xbmc.log('[%s]: Cannot get data from %s.\n%s' % (addon_name, target, e)) return None
addon_author = addon.getAddonInfo('author') addon_name = addon.getAddonInfo('name') addon_version = addon.getAddonInfo('version') unknown_person = os.path.join(addon_path, 'resources', 'skins', 'Default', 'media', 'unknown_person.png') platform_version = xbmc.getInfoLabel('System.BuildVersion').split(" ")[0] if int(platform_version.split(".")[0]) >= 14: name = 'Kodi' else: name = 'Xbmc' API_Private_Key_MEGOGO = '63ee38849d' API_Public_Key_MEGOGO = '_kodi_j1' API_URL = 'https://api.megogo.net/v1' MEGOGO_URL = 'http://megogo.net' PAY_URL = 'https://megogo.net/%s/billing/payu' % get_ui_language() PAY_VENDOR = 'kodi-device' try: UA = '%s/%s-%s' % (name, platform_version, platform.platform(aliased=0, terse=0)[:40]) except: data = os.uname() UA = '%s/%s-%s-%s-%s' % (name, platform_version, data[0], data[2], data[-1]) UA = UA[:50] xbmc.log('[%s]: UA - %s' % (addon_name, UA)) slider_images_resolution = [ 'image_1920x300', 'image_1600x520', 'image_1350x510' ]
def GET(url, old_url=None, login=False, post=False, post_data=None): try: dicParams = {} linkParams = [] hashParams = [] dic = a.get_login_from_db() if dic["cookie"]: cookie = simplejson.loads(base64.b64decode(dic["cookie"])) else: cookie = None usr = dic["login"] pwd = dic["password"] # Language correction if url.find("lang=") == -1 and not post and not url.startswith("auth/") and not url.startswith("search"): if url.find("?") > 0: url = "%s&lang=%s" % (url, get_ui_language()) else: url = "%s?lang=%s" % (url, get_ui_language()) page, _, params = url.partition("?") if params: params = params.split("&") for param in params: key, _, value = param.partition("=") dicParams[key] = value for keys in dicParams: linkParams.append("%s=%s" % (keys, urllib.quote_plus(dicParams[keys]))) hashParams.append("%s=%s" % (keys, dicParams[keys])) linkParams = "&".join(reversed(linkParams)) hashParams = "".join(reversed(hashParams)) else: hashParams = "" linkParams = "" m = hashlib.md5() m.update("%s%s" % (hashParams, API_Private_Key_MEGOGO)) if not post: target = "%s/%s?%s&sign=%s" % (API_URL, page, linkParams, "%s%s" % (m.hexdigest(), API_Public_Key_MEGOGO)) else: target = "%s/%s?%s&sign=%s" % (PAY_URL, page, linkParams, "%s%s" % (m.hexdigest(), API_Public_Key_MEGOGO)) xbmc.log("[%s]: GET Target:\n%s" % (addon_name, target)) # xbmc.log('[%s]: GET\nUSR - %s\nPASS - %s\nCookie - %s\nTarget - %s' % (addon_name, usr, pwd, cookie, target)) if cookie and not old_url and not post: request = requests.get(target, cookies=cookie, headers={"User-Agent": UA}, timeout=8) # xbmc.log('[%s]: GET cookie and not old_url, request - %s' % (addon_name, request)) http = request.text # xbmc.log('[%s]: GET cookie and not old_url, http - %s' % (addon_name, http.encode('utf-8'))) return http.encode("utf-8") # log in account in megogo.net elif usr and pwd and login and not post: # xbmc.log('[%s]: GET elif usr and pwd and login, url - %s' % (addon_name, url)) if not url.startswith("auth/login?login="******"auth/login?login=%s&password=%s&remember=1" % (usr, pwd), old_url=url, login=True) else: session = requests.session() request = session.get(target, headers={"User-Agent": UA}, timeout=8) http = request.text if http.startswith('{"result":"ok"'): cookies = requests.utils.dict_from_cookiejar(session.cookies) # xbmc.log('[%s]: NEW COOKIE - %s' % (addon_name, cookies)) a.cookie_to_db(base64.b64encode(str(cookies).replace("'", '"'))) if old_url: # xbmc.log('[%s]: GET elif usr and pwd, old_url - %s' % (addon_name, old_url)) GET(old_url) else: # xbmc.log('[%s]: return GET elif usr and pwd, http - %s' % (addon_name, http.encode('utf-8'))) return http.encode("utf-8") else: return None else: if post_data: post_data = urllib.urlencode(post_data) request = urllib2.Request(url=target, data=post_data, headers={"User-Agent": UA}) request = urllib2.urlopen(request) http = request.read() request.close() # xbmc.log('[%s]: GET else, http - %s' % (addon_name, http)) return http except Exception as e: xbmc.log("[%s]: Cannot get data from %s.\n%s" % (addon_name, target, e)) return None
addon_id = addon.getAddonInfo("id") addon_author = addon.getAddonInfo("author") addon_name = addon.getAddonInfo("name") addon_version = addon.getAddonInfo("version") unknown_person = os.path.join(addon_path, "resources", "skins", "Default", "media", "unknown_person.png") platform_version = xbmc.getInfoLabel("System.BuildVersion").split(" ")[0] if int(platform_version.split(".")[0]) >= 14: name = "Kodi" else: name = "Xbmc" API_Private_Key_MEGOGO = "63ee38849d" API_Public_Key_MEGOGO = "_kodi_j1" API_URL = "https://api.megogo.net/v1" MEGOGO_URL = "http://megogo.net" PAY_URL = "https://megogo.net/%s/billing/payu" % get_ui_language() PAY_VENDOR = "kodi-device" try: UA = "%s/%s-%s" % (name, platform_version, platform.platform(aliased=0, terse=0)[:40]) except: data = os.uname() UA = "%s/%s-%s-%s-%s" % (name, platform_version, data[0], data[2], data[-1]) UA = UA[:50] xbmc.log("[%s]: UA - %s" % (addon_name, UA)) slider_images_resolution = ["image_1920x300", "image_1600x520", "image_1350x510"] a = DB() # Function to get cached JSON response from db or