def stream(): item_id = args.get('file', '0') Utils.log('Getting stream URL for file id: '+item_id[0]) content = Api.getStreamUrl(item_id[0]) if content and content['result'] == True: player = xbmc.Player() Utils.log('Stream URL is: '+content['url']) content['url'] = content['url'] + '|User-Agent='+urllib.quote(Utils.getUserAgent())+'&' # Sending cookies with the query cookies = Api.getCookies() if len(cookies) > 0: content['url'] = content['url'] + 'Cookie=' for i in cookies: content['url'] = content['url'] + urllib.quote(i + '=' + cookies[i]+';') # Starting the playback player.play(content['url']) # If video doesn't work, raising an error time.sleep(3) if not player.isPlayingVideo(): xbmc.executebuiltin('Notification('+language(30019)+', '+language(30020)+',3000,' + addon_path + '/resources/images/error.png)') else: xbmc.executebuiltin('Notification('+language(30019)+', '+language(30020)+',3000,' + addon_path + '/resources/images/error.png)')
def __Call(self, url, params = {}): #xbmc.executebuiltin('Notification('+default.language(30015)+', '+language(30016)+',3000,' + default.addon_path +'/resources/images/success.png)') # Matching URL if not re.search('http(s)?://', url): url = self.api_url + '/' + url Utils.log('Requesting URL : '+url+'?'+urllib.urlencode(params)) # Running request try: # Setting cookies default policy policy = DefaultCookiePolicy(rfc2965=False, allowed_domains=self.allowed_domains) cj = cookielib.LWPCookieJar(policy=policy) # Starting the CookieJar handler opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) # Starting the request req = urllib2.Request(url) req.add_header('User-Agent', Utils.getUserAgent()) # Loading existing cookie(s) if applicable # Ignoring_discard = True otherwise session cookies aren't sent if os.path.isfile(self.cookiejar): Utils.log('Loading existing cookies') cj.load(self.cookiejar, ignore_discard=True) # Running query response = urllib2.urlopen(req, urllib.urlencode(params)) # Getting response content = response.read() # Getting response informations infos = response.info() # Checking the response content-type if infos['content-type']: # If response is a JSON, decoding JSON automatically if re.search('application/json', infos['content-type']): content = json.loads(content) # Saving private_key for later use for cookie in cj: self.cookies[cookie.name] = cookie.value # If unable to save the cookie jar file # Aborting execution, otherwise going into # An infinite loop if not os.path.isdir(self.cookiejar_dir): Utils.log('Warning: Cookiejar DIR does not exist') xbmcgui.Dialog().ok(default.language(30023), '', default.language(30024)) sys.exit() # Saving any cookie sent with the response # Ignoring_discard = True otherwise session cookies aren't saved cj.save(self.cookiejar, ignore_discard=True) response.close() return content except urllib2.HTTPError, e: # Authentication issue, resetting the private key if e.code == 403: Utils.log('Got a 403 Forbidden, trying to login now') if default.Auth.Login(): default.browse()