def _request(self, cmd, params, inauth=None): if self.AUTH_OK == False: if inauth == None: self._auth(self.login, self.password) url = IPTV_API % cmd if inauth: postparams = params else: url = url + "?" + params postparams = None # log.info('Requesting %s' % url) xbmc.log("[Kartina.TV] REQUESTING: %s" % url) ua = self.genUa() req = urllib2.Request( url, postparams, { "User-agent": ua, "Connection": "Close", "Accept": "application/json, text/javascript, */*", "X-Requested-With": "XMLHttpRequest", }, ) if inauth == None and getattr(xbmc, "nonXBMC", None) is not None: from ga import track_page_view from ga import get_visitor_id path = cmd + "?" + params extra = {} extra["screen"] = xbmc.getInfoLabel("System.ScreenMode") track_page_view(get_visitor_id(self.login, None), path, ua, extra) if COOKIEJAR == None and (self.SID != None): req.add_header("Cookie", self.SID_NAME + "=" + self.SID + ";") rez = urllib2.urlopen(req).read() xbmc.log("[Kartina.TV] Got %s" % rez, level=xbmc.LOGDEBUG) try: res = JSONDECODE(rez) except: xbmc.log("[Kartina.TV] Error.. :(") # xbmc.log('[Kartina.TV] Got JSON: %s' % res) self._errors_check(res) if COOKIEJAR != None: xbmc.log("[Kartina.TV] Saving cookies: %s" % COOKIEFILE) COOKIEJAR.save(COOKIEFILE) return res
def _request(self, cmd, params, inauth = None): if self.AUTH_OK == False: if inauth == None: self._auth(self.login, self.password) url = IPTV_API % cmd if inauth: postparams = params else: url = url + '?' + params postparams = None #log.info('Requesting %s' % url) xbmc.log('[Kartina.TV] REQUESTING: %s' % url) ua = self.genUa() req = urllib2.Request(url, postparams, {'User-agent': ua, 'Connection': 'Close', 'Accept': 'application/json, text/javascript, */*', 'X-Requested-With': 'XMLHttpRequest'}) if inauth == None and getattr(xbmc, "nonXBMC", None) is not None: from ga import track_page_view from ga import get_visitor_id path = cmd+"?"+params extra = {} extra['screen'] = xbmc.getInfoLabel('System.ScreenMode') track_page_view(get_visitor_id(self.login, None), path, ua, extra) if COOKIEJAR == None and (self.SID != None): req.add_header("Cookie", self.SID_NAME + "=" + self.SID + ";") rez = urllib2.urlopen(req).read() xbmc.log('[Kartina.TV] Got %s' % rez, level=xbmc.LOGDEBUG) try: res = JSONDECODE(rez) except: xbmc.log('[Kartina.TV] Error.. :(') #xbmc.log('[Kartina.TV] Got JSON: %s' % res) self._errors_check(res) if COOKIEJAR != None: xbmc.log('[Kartina.TV] Saving cookies: %s' % COOKIEFILE) COOKIEJAR.save(COOKIEFILE) return res
else: SID = None SID_NAME = None PLUGIN_CORE = iptv.kartina(USERNAME, USERPASS, PLUGIN_ID, SID, SID_NAME) if PLUGIN_CORE.testAuth() == False: dialog = xbmcgui.Dialog() dialog.ok(__language__(30023), __language__(30024)) __settings__.openSettings() else: if not __settings__.getSetting('ga_uid'): from random import randint from ga import get_visitor_id ga_uid = get_visitor_id( str(randint(0, 0x7fffffff)) + PLUGIN_NAME + PLUGIN_ID, None) __settings__.setSetting('ga_uid', ga_uid) xbmc.log('[%s] GA uid set to %s' % (PLUGIN_NAME, __settings__.getSetting('ga_uid'))) #xbmc.executebuiltin( "Container.SetViewMode(51)") #TRANSSID = '&_s=%s&_sn=%s' % (PLUGIN_CORE.SID, PLUGIN_CORE.SID_NAME) if 'mode' in params: mode = params['mode'] else: if __settings__.getSetting('start_with_tv') == 'false': mode = None else: mode = 'TV'
def track(request): """ Track a page view, updates all the cookies and campaign tracker, makes a server side request to Google Analytics and writes the transparent gif byte data to the response. """ response = HttpResponse() time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE) # set some useful items in environ: x_utmac = request.GET.get('x_utmac', None) domain = request.META.get('HTTP_HOST', '') # Get the referrer from the utmr parameter, this is the referrer to the # page that contains the tracking pixel, not the referrer for tracking # pixel. document_referer = request.GET.get("utmr", "") if not document_referer or document_referer == "0": document_referer = "-" else: document_referer = unquote(document_referer) document_path = request.GET.get('utmp', "") if document_path: document_path = unquote(document_path) account = request.GET.get('utmac', '') user_agent = request.META.get("HTTP_USER_AGENT", '') # Try and get visitor cookie from the request. cookie = request.COOKIES.get(COOKIE_NAME, None) visitor_id = get_visitor_id(request.META.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie) utm_gif_location = "http://www.google-analytics.com/__utm.gif" for utmac in [account, x_utmac]: if not utmac: continue # ignore empty utmacs # Construct the gif hit url. utm_url = utm_gif_location + "?" + \ "utmwv=" + VERSION + \ "&utmn=" + get_random_number() + \ "&utmhn=" + quote(domain) + \ "&utmsr=" + request.GET.get('utmsr', '') + \ "&utme=" + request.GET.get('utme', '') + \ "&utmr=" + quote(document_referer) + \ "&utmp=" + quote(document_path) + \ "&utmac=" + utmac + \ "&utmcc=__utma%3D999.999.999.999.999.1%3B" + \ "&utmvid=" + visitor_id + \ "&utmip=" + get_ip(request.META.get("REMOTE_ADDR",'')) send_request_to_google_analytics(utm_url, request.META) # add the cookie to the response. response.set_cookie(COOKIE_NAME, value=visitor_id, path=COOKIE_PATH) # If the debug parameter is on, add a header to the response that contains # the url that was used to contact Google Analytics. if request.GET.get('utmdebug', False): response['X-GA-MOBILE-URL'] = utm_url response_headers = [ ('Content-Type', 'image/gif'), ('Cache-Control', 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate'), ('Pragma', 'no-cache'), ('Expires', 'Wed, 17 Sep 1975 21:32:10 GMT') ] for header in response_headers: key, value = header response[key] = value response.content = GIF_DATA return response
def track(request): """ Track a page view, updates all the cookies and campaign tracker, makes a server side request to Google Analytics and writes the transparent gif byte data to the response. """ response = HttpResponse() time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE) # set some useful items in environ: x_utmac = request.GET.get('x_utmac', None) domain = request.META.get('HTTP_HOST', '') # Get the referrer from the utmr parameter, this is the referrer to the # page that contains the tracking pixel, not the referrer for tracking # pixel. document_referer = request.GET.get("utmr", "") if not document_referer or document_referer == "0": document_referer = "-" else: document_referer = unquote(document_referer) document_path = request.GET.get('utmp', "") if document_path: document_path = unquote(document_path) account = request.GET.get('utmac', '') user_agent = request.META.get("HTTP_USER_AGENT", '') # Try and get visitor cookie from the request. cookie = request.COOKIES.get(COOKIE_NAME, None) visitor_id = get_visitor_id(request.META.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie) utm_gif_location = "http://www.google-analytics.com/__utm.gif" for utmac in [account, x_utmac]: if not utmac: continue # ignore empty utmacs # Construct the gif hit url. utm_url = utm_gif_location + "?" + \ "utmwv=" + VERSION + \ "&utmn=" + get_random_number() + \ "&utmhn=" + quote(domain) + \ "&utmsr=" + request.GET.get('utmsr', '') + \ "&utme=" + request.GET.get('utme', '') + \ "&utmr=" + quote(document_referer) + \ "&utmp=" + quote(document_path) + \ "&utmac=" + utmac + \ "&utmcc=__utma%3D999.999.999.999.999.1%3B" + \ "&utmvid=" + visitor_id + \ "&utmip=" + get_ip(request.META.get("REMOTE_ADDR",'')) send_request_to_google_analytics(utm_url, request.META) # add the cookie to the response. response.set_cookie(COOKIE_NAME, value=visitor_id, path=COOKIE_PATH) # If the debug parameter is on, add a header to the response that contains # the url that was used to contact Google Analytics. if request.GET.get('utmdebug', False): response['X-GA-MOBILE-URL'] = utm_url response_headers =[('Content-Type', 'image/gif'), ('Cache-Control', 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate'), ('Pragma', 'no-cache'), ('Expires', 'Wed, 17 Sep 1975 21:32:10 GMT')] for header in response_headers: key, value = header response[key] = value response.content = GIF_DATA return response
else: SID = None SID_NAME = None PLUGIN_CORE = iptv.tvover(USERNAME, USERPASS, PLUGIN_ID, SID, SID_NAME) if PLUGIN_CORE.testAuth() == False: dialog = xbmcgui.Dialog() dialog.ok( __language__(30023), __language__(30024)) __settings__.openSettings() else: if not __settings__.getSetting('ga_uid'): from random import randint from ga import get_visitor_id ga_uid = get_visitor_id(str(randint(0, 0x7fffffff)) + PLUGIN_NAME + PLUGIN_ID, None) __settings__.setSetting('ga_uid', ga_uid) xbmc.log('[%s] GA uid set to %s' % (PLUGIN_NAME, __settings__.getSetting('ga_uid'))) PLUGIN_CORE.auto_timezone = (__settings__.getSetting('auto_timezone') == 'true') if 'mode' in params: mode = params['mode'] else: if __settings__.getSetting('start_with_tv') == 'true': mode = 'TV' else: mode = None if 'channel' in params: channel = params['channel']
def track_page_view(environ): """ // Track a page view, updates all the cookies and campaign tracker, // makes a server side request to Google Analytics and writes the transparent // gif byte data to the response. """ time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE) # set some useful items in environ: environ['COOKIES'] = parse_cookie(environ.get('HTTP_COOKIE', '')) environ['GET'] = {} for key, value in parse_qsl(environ.get('QUERY_STRING', ''), True): environ['GET'][ key] = value # we only have one value per key name, right? :) x_utmac = environ['GET'].get('x_utmac', None) domain = environ.get('HTTP_HOST', '') # Get the referrer from the utmr parameter, this is the referrer to the # page that contains the tracking pixel, not the referrer for tracking # pixel. document_referer = environ['GET'].get("utmr", "") if not document_referer or document_referer == "0": document_referer = "-" else: document_referer = unquote(document_referer) document_path = environ['GET'].get('utmp', "") if document_path: document_path = unquote(document_path) account = environ['GET'].get('utmac', '') user_agent = environ.get("HTTP_USER_AGENT", '') # // Try and get visitor cookie from the request. cookie = environ['COOKIES'].get(COOKIE_NAME) visitor_id = get_visitor_id(environ.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie) # // Always try and add the cookie to the response. cookie = SimpleCookie() cookie[COOKIE_NAME] = visitor_id morsel = cookie[COOKIE_NAME] morsel['expires'] = time.strftime('%a, %d-%b-%Y %H:%M:%S %Z', time_tup) morsel['path'] = COOKIE_PATH utm_gif_location = "http://www.google-analytics.com/__utm.gif" for utmac in [account, x_utmac]: if not utmac: continue # ignore empty utmacs # // Construct the gif hit url. utm_url = utm_gif_location + "?" + \ "utmwv=" + VERSION + \ "&utmn=" + get_random_number() + \ "&utmhn=" + quote(domain) + \ "&utmsr=" + environ['GET'].get('utmsr', '') + \ "&utme=" + environ['GET'].get('utme', '') + \ "&utmr=" + quote(document_referer) + \ "&utmp=" + quote(document_path) + \ "&utmac=" + utmac + \ "&utmcc=__utma%3D999.999.999.999.999.1%3B" + \ "&utmvid=" + visitor_id + \ "&utmip=" + get_ip(environ.get("REMOTE_ADDR",'')) # dbgMsg("utm_url: " + utm_url) send_request_to_google_analytics(utm_url, environ) # // If the debug parameter is on, add a header to the response that contains # // the url that was used to contact Google Analytics. headers = [('Set-Cookie', str(cookie).split(': ')[1])] if environ['GET'].get('utmdebug', False): headers.append(('X-GA-MOBILE-URL', utm_url)) # Finally write the gif data to the response response = write_gif_data() response_headers = response['response_headers'] response_headers.extend(headers) return response
def track_page_view(environ): """ // Track a page view, updates all the cookies and campaign tracker, // makes a server side request to Google Analytics and writes the transparent // gif byte data to the response. """ time_tup = time.localtime(time.time() + COOKIE_USER_PERSISTENCE) # set some useful items in environ: environ['COOKIES'] = parse_cookie(environ.get('HTTP_COOKIE', '')) environ['GET'] = {} for key, value in parse_qsl(environ.get('QUERY_STRING', ''), True): environ['GET'][key] = value # we only have one value per key name, right? :) x_utmac = environ['GET'].get('x_utmac', None) domain = environ.get('HTTP_HOST', '') # Get the referrer from the utmr parameter, this is the referrer to the # page that contains the tracking pixel, not the referrer for tracking # pixel. document_referer = environ['GET'].get("utmr", "") if not document_referer or document_referer == "0": document_referer = "-" else: document_referer = unquote(document_referer) document_path = environ['GET'].get('utmp', "") if document_path: document_path = unquote(document_path) account = environ['GET'].get('utmac', '') user_agent = environ.get("HTTP_USER_AGENT", '') # // Try and get visitor cookie from the request. cookie = environ['COOKIES'].get(COOKIE_NAME) visitor_id = get_visitor_id(environ.get("HTTP_X_DCMGUID", ''), account, user_agent, cookie) # // Always try and add the cookie to the response. cookie = SimpleCookie() cookie[COOKIE_NAME] = visitor_id morsel = cookie[COOKIE_NAME] morsel['expires'] = time.strftime('%a, %d-%b-%Y %H:%M:%S %Z', time_tup) morsel['path'] = COOKIE_PATH utm_gif_location = "http://www.google-analytics.com/__utm.gif" for utmac in [account, x_utmac]: if not utmac: continue # ignore empty utmacs # // Construct the gif hit url. utm_url = utm_gif_location + "?" + \ "utmwv=" + VERSION + \ "&utmn=" + get_random_number() + \ "&utmhn=" + quote(domain) + \ "&utmsr=" + environ['GET'].get('utmsr', '') + \ "&utme=" + environ['GET'].get('utme', '') + \ "&utmr=" + quote(document_referer) + \ "&utmp=" + quote(document_path) + \ "&utmac=" + utmac + \ "&utmcc=__utma%3D999.999.999.999.999.1%3B" + \ "&utmvid=" + visitor_id + \ "&utmip=" + get_ip(environ.get("REMOTE_ADDR",'')) # dbgMsg("utm_url: " + utm_url) send_request_to_google_analytics(utm_url, environ) # // If the debug parameter is on, add a header to the response that contains # // the url that was used to contact Google Analytics. headers = [('Set-Cookie', str(cookie).split(': ')[1])] if environ['GET'].get('utmdebug', False): headers.append(('X-GA-MOBILE-URL', utm_url)) # Finally write the gif data to the response response = write_gif_data() response_headers = response['response_headers'] response_headers.extend(headers) return response