Exemplo n.º 1
0
    def onPlayBackStopped(self):

        self.active=False
        self.show=False
        self.mustEND=1
        track_page_view('','event','5(Video*VideoStopped)',UATRACK=GATrack)
        tracker.track_event(Event('Video','Stopped'), session, visitor)
Exemplo n.º 2
0
def playid(params, play=False):


    try:
        f = open(adv_file, 'r')
        last_ad=f.readline()

    except:
        f = open(adv_file, 'w')
        last_ad=str(int(time.time()))
        f.write(last_ad)
        f.close()
    aplay=dig_player()
    aplay.init()
    aplay.lastad=last_ad
    aplay.pre_end=time.time()
    aplay.getData(params['id'])
    print "aplay:%s"%aplay.strt_file
    if aplay.strt_file!=None:
        print "Play file:%s"%aplay.strt_file
        print 'plfile'
        item = xbmcgui.ListItem(path=aplay.strt_file)
        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
        aplay.play_loop()
        aplay.stop
        aplay.active=False
    else:
        ShowMessage('ivi.ru', 'Forbidden', 2000)
        track_page_view(str(params['id']),'event','5(Video*VideoForbidden)',UATRACK=GATrack)
        tracker.track_event(Event('Video','Forbidden',str(params['id'])), session, visitor)
        aplay.stop
Exemplo n.º 3
0
def track_event(category=None, action=None, label=None, value=None, identifier=None, first_use=None, add=None,
                noninteraction=True):
    anonymousConfig = Config()
    anonymousConfig.anonimize_ip_address = True

    tracker = Tracker('UA-86466078-1', 'none', conf=anonymousConfig)
    visitor = Visitor()

    # convert the last 8 bytes of the machine identifier to an integer to get a "unique" user
    visitor.unique_id = struct.unpack("!I", binascii.unhexlify(identifier[32:]))[0]/2

    if add:
        # add visitor's ip address (will be anonymized)
        visitor.ip_address = add

    if first_use:
        visitor.first_visit_time = first_use

    session = Session()
    event = Event(category=category, action=action, label=label, value=value, noninteraction=noninteraction)
    path = u"/" + u"/".join([category, action, label])
    page = Page(path.lower())

    tracker.track_event(event, session, visitor)
    tracker.track_pageview(page, session, visitor)
Exemplo n.º 4
0
def alloc_ga_obj_by_name(name):
    """
    通过名字生成对应的obj
    """
    from pyga.requests import Tracker, Page, Session, Visitor, Transaction, Event, SocialInteraction, Campaign

    obj = None
    if name == 'tracker':
        obj = Tracker()
    elif name == 'campaign':
        obj = Campaign(Campaign.TYPE_REFERRAL)
    elif name == 'session':
        obj = Session()
    elif name == 'page':
        obj = Page(None)
    elif name == 'visitor':
        obj = Visitor()
    elif name == 'transaction':
        obj = Transaction()
    elif name == 'event':
        obj = Event()
    elif name == 'social_interaction':
        obj = SocialInteraction()

    return obj
Exemplo n.º 5
0
def track_event(*args, **kwargs):
    if not plugin.get_setting("ga_disable", bool) or kwargs.pop("force", False):
        try:
            from pyga.requests import Event
            tracker, session, visitor = get_ga()
            plugin.log.info("GA: Tracking event %s" % repr(args))
            tracker.track_event(Event(*args, **kwargs), session, visitor)
        except Exception, e:
            import traceback
            plugin.log.error("GA: Call failed.")
            plugin.log.error(traceback.format_exc())
Exemplo n.º 6
0
    def track_event(self, category=None, action=None, label=None, value=None):
        try:
            if self.account_id:
                if label is None:
                    label = self.caller_id

                self.tracker.track_event(Event(category, action, label, value),
                                         self.session, self.visitor)
        except:
            print('Uncaught exception in Analytics process: \n' +
                  unicode(traceback.format_exc(), 'utf8'))
Exemplo n.º 7
0
def track_event(category=None, action=None, label=None):
    if not settings.analytics.getboolean('enabled'):
        return

    anonymousConfig = Config()
    anonymousConfig.anonimize_ip_address = True

    tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig)

    try:
        if os.path.isfile(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat'))):
            with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'r') as handle:
                visitor_text = handle.read()
            visitor = pickle.loads(codecs.decode(visitor_text.encode(), "base64"))
            if visitor.user_agent is None:
                visitor.user_agent = os.environ.get("SZ_USER_AGENT")
            if visitor.unique_id > int(0x7fffffff):
                visitor.unique_id = random.randint(0, 0x7fffffff)
        else:
            visitor = Visitor()
            visitor.unique_id = random.randint(0, 0x7fffffff)
    except:
        visitor = Visitor()
        visitor.unique_id = random.randint(0, 0x7fffffff)

    session = Session()
    event = Event(category=category, action=action, label=label, value=1)

    tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion',
                                               value=os.environ["BAZARR_VERSION"].lstrip('v'), scope=1))
    tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1))
    if settings.general.getboolean('use_sonarr'):
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1))
    else:
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value='unused', scope=1))
    if settings.general.getboolean('use_radarr'):
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1))
    else:
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value='unused', scope=1))
    tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1))

    try:
        tracker.track_event(event, session, visitor)
    except:
        logging.debug("BAZARR unable to track event.")
        pass
    else:
        with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'w+') as handle:
            handle.write(codecs.encode(pickle.dumps(visitor), "base64").decode())
Exemplo n.º 8
0
    def ga_track(self, event={}):
        _req_list = []
        no_tracking = self.get_argument('no_tracking', None)
        is_prod = getattr(config, 'RUN_IN_PROD', False)
        if not no_tracking and is_prod and hasattr(config, "GA_ACCOUNT"):
            _req = self.request
            remote_ip = _req.headers.get("X-Real-Ip",
                        _req.headers.get("X-Forwarded-For",
                        _req.remote_ip))
            user_agent = _req.headers.get("User-Agent", None)
            visitor = Visitor()
            visitor.ip_address = remote_ip
            visitor.user_agent = user_agent
            #get visitor.locale
            visitor.extract_from_server_meta(
                {"HTTP_ACCEPT_LANGUAGE": _req.headers.get("Accept-Language", None)}
            )
            session = Session()
            page = Page(_req.path)
            tracker = Tracker(config.GA_ACCOUNT, 'MyVariant.info')
            # tracker.track_pageview(page, session, visitor)  #this is non-async request
            pvr = PageViewRequest(config=tracker.config,
                                  tracker=tracker,
                                  visitor=visitor,
                                  session=session,
                                  page=page)
            r = pvr.build_http_request()
            _req_list.append(HTTPRequest(r.get_full_url(),
                                         "POST" if (r.data) else "GET",
                                         headers=r.headers,
                                         body=r.data))
            if event:
                evt = Event(**event)
                #tracker.track_event(evt, session, visitor)  #this is non-async request
                er = EventRequest(config=tracker.config,
                                  tracker=tracker,
                                  visitor=visitor,
                                  session=session,
                                  event=evt)
                r = er.build_http_request()
                _req_list.append(HTTPRequest(r.get_full_url(),
                                             "POST" if (r.data) else "GET",
                                             headers=r.headers,
                                             body=r.data))

            #now send actual async requests
            http_client = AsyncHTTPClient()
            for _req in _req_list:
                http_client.fetch(_req)
Exemplo n.º 9
0
def track_event(category=None, action=None, label=None):
    if not settings.analytics.getboolean('enabled'):
        return

    anonymousConfig = Config()
    anonymousConfig.anonimize_ip_address = True

    tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig)

    try:
        visitor = pickle.loads(base64.b64decode(settings.analytics.visitor))
    except:
        visitor = Visitor()
        unique_id = long(random.getrandbits(32))
        visitor.unique_id = unique_id

    session = Session()
    event = Event(category=category, action=action, label=label, value=1)
    path = u"/" + u"/".join([category, action, label])
    page = Page(path.lower())

    tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion', value=os.environ["BAZARR_VERSION"], scope=1))
    tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1))
    if settings.general.getboolean('use_sonarr'):
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1))
    if settings.general.getboolean('use_radarr'):
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1))
    tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1))

    try:
        tracker.track_event(event, session, visitor)
        tracker.track_pageview(page, session, visitor)
    except:
        pass
    else:
        settings.analytics.visitor = base64.b64encode(pickle.dumps(visitor))
        with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
            settings.write(handle)
Exemplo n.º 10
0
    def getData    (self, vID):

        self.vID=vID
        self.watchid='%s_%s_%s'%(self.vID,uniq_id,str(int(time.time()*1000)))
        json0 = self.POSTAPI({'method':'da.content.get', 'params':[self.vID, {'contentid':self.vID,'watchid':self.watchid,'site':self.sID, 'uid':uniq_id} ]})
        try:
            vc = json0['result']
            self.content = self.find_best(vc)
        except: vc=None

        if self.content and vc:

            http = GET('http://www.ivi.ru/mobileapi/videoinfo/?subsite=15&id=%s' % self.vID)
            if http:
                data = get_video_data(json.loads(http))
                self.PosterImage = data['image']
                self.main_item = xbmcgui.ListItem(data['title'], iconImage = self.PosterImage, thumbnailImage = self.PosterImage)
                self.title=data['title']
                i = xbmcgui.ListItem(self.title, iconImage = self.PosterImage, thumbnailImage = self.PosterImage)
                iad = xbmcgui.ListItem(language(30011), iconImage = self.PosterImage, thumbnailImage = self.PosterImage)
            try:    self.content_percent_to_mark = int(vc['percent_to_mark'])
            except: self.content_percent_to_mark = 0
            try:    self.GA_id = int(vc['google_analytics_id'])
            except: self.GA_id = None
            try:    self.tns_id = int(vc['tns_id'])
            except: self.tns_id = None
            self.title=vc['title']
            try:    self.credits_begin_time = int(vc['credits_begin_time'])
            except: self.credits_begin_time = -1
            if self.credits_begin_time==0: self.credits_begin_time=-1
            try:    self.midroll = vc['midroll']
            except: self.midroll = []
            flname=self.content
            fio=i
            ind=0
            pre=self.getAds('preroll')
            #print pre
            if pre:
                self.adv_file=pre['url']
                self.advid=pre['id']
                self.state='preroll'
                self.send_ads=pre
                flname=self.adv_file
                fio=iad
            else: self.state='play'

            for na in self.midroll:
                try:
                    self.ads.append({
                        'type':'midroll',
                        'ind':ind,
                        'time':na})
                    ind=ind+1
                except: pass
            self.ads.append({
                    'type':'postroll',
                    'ind':ind,
                    'time':self.credits_begin_time
                })
            track_page_view('','event','5(Video*Videostart)')
            track_page_view('','event','5(Video*Videostart)',UATRACK=GATrack)
            tracker.track_event(Event('Video','Start',vID), session, visitor)
            self.active=True
            json1 = self.POSTAPI({'params':[self.vID, {'contentid':self.vID,'site':self.sID, 'watchid':self.watchid ,'uid':uniq_id} ],'method':'da.content.watched' })
            self.playing=False
            self.strt_file=flname