def action(self, data):
     if self.scid is None:
         return
     url = "%s/Stats" % (sctop.BASE_URL)
     data.update({'est': self.estimateFinishTime})
     data.update({'se': self.se, 'ep': self.ep})
     data.update({'ver': sctop.addonInfo('version')})
     try:
         data.update(
             {'state': bool(xbmc.getCondVisibility("!Player.Paused"))})
         data.update({
             'ws': xbmcgui.Window(10000).getProperty('ws.ident'),
             'vip': xbmcgui.Window(10000).getProperty('ws.vip')
         })
         data.update({'vd': xbmcgui.Window(10000).getProperty('ws.days')})
         data.update({'skin': xbmc.getSkinDir()})
         if 'bitrate' in self.stream:
             util.debug("[SC] action bitrate")
             data.update({'bt': self.stream['bitrate']})
         else:
             util.debug("[SC] action no bitrate")
     except:
         pass
     try:
         if self.itemDuration > 0:
             data.update({'dur': self.itemDuration})
     except Exception:
         pass
     self.log("[SC] action: %s" % str(data))
     url = self.parent.provider._url(url)
     sctop.post_json(url, data, {'X-UID': sctop.uid})
예제 #2
0
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api.trakt.tv', url)

        headers = {'trakt-api-key': sctop.trCL, 'trakt-api-version': '2'}

        if getTraktCredentialsInfo() == False:
            util.debug("[SC] gt 1 data: %s %s" % (str(url), str(post)))
            if post is not None:
                result = util.post_json(url, post, headers)
            else:
                result = util.request(url, headers)
            util.debug("[SC] gt 1 result: %s" % str(result))
            return result

        headers['Authorization'] = 'Bearer %s' % sctop.getSetting(
            'trakt.token')
        #util.debug('[SC] token %s' % sctop.getSetting('trakt.token'))

        if post is not None:
            result, code = sctop.post_json(url, post, headers, "extend")
        else:
            result, code = sctop.request(url, headers, "extend")
        #util.debug("[SC] trakt gt result: %s %s" % (str(result), str(code)))
        if not (code == 401 or code == 405): return result

        oauth = 'http://api.trakt.tv/oauth/token'
        opost = {
            'client_id': sctop.trCL,
            'client_secret': sctop.trSC,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': sctop.getSetting('trakt.refresh')
        }

        result, code = sctop.post_json(oauth, opost, headers, "extend")
        if code == 401:
            authTrakt()
            result, code = sctop.post_json(oauth, opost, headers, "extend")
        result = json.loads(result)

        token, refresh = result['access_token'], result['refresh_token']

        sctop.setSetting(id='trakt.token', value=token)
        sctop.setSetting(id='trakt.refresh', value=refresh)

        headers['Authorization'] = 'Bearer %s' % token

        util.debug('[SC] token: %s' % token)

        result = sctop.post_json(url, post, headers)
        return result
    except Exception as e:
        util.error(e)
        pass
 def action(self, data):
     if self.scid is None:
         util.debug("[SC] nemame scid")
         return
     if data.get('action', None) is None:
         util.debug("[SC] nemame action")
         return
     url = "%s/Stats?action=%s" % (sctop.BASE_URL, data.get(
         'action', 'None'))
     data.update({'est': self.estimateFinishTime})
     data.update({'se': self.se, 'ep': self.ep})
     data.update({'ver': sctop.addonInfo('version')})
     lastAction = xbmcgui.Window(10000).getProperty('sc.lastAction')
     util.debug('[SC] lastAction: %s' % (str(lastAction)))
     if lastAction == "" or time() - float(lastAction) > 5:
         xbmcgui.Window(10000).setProperty('sc.lastAction', str(time()))
         try:
             data.update(
                 {'state': bool(xbmc.getCondVisibility("!Player.Paused"))})
             data.update({
                 'ws': xbmcgui.Window(10000).getProperty('ws.ident'),
                 'vip': xbmcgui.Window(10000).getProperty('ws.vip')
             })
             data.update(
                 {'vd': xbmcgui.Window(10000).getProperty('ws.days')})
             data.update({'skin': xbmc.getSkinDir()})
             if 'bitrate' in self.stream:
                 util.debug("[SC] action bitrate")
                 data.update({'bt': self.stream['bitrate']})
             else:
                 util.debug("[SC] action no bitrate")
         except:
             pass
         try:
             if self.itemDuration > 0:
                 data.update({'dur': self.itemDuration})
         except Exception:
             pass
         util.debug("[SC] action: %s" % str(data))
         url = self.parent.provider._url(url)
         try:
             sctop.post_json(url, data, {'X-UID': sctop.uid})
         except:
             pass
    def action(self, data):
        if self.scid is None:
            util.debug("[SC] nemame scid")
            return
        if data.get('action', None) is None:
            util.debug("[SC] nemame action")
            return

        if self.stream is None:
            try:
                stream = json.loads(
                    self.win.getProperty('%s.stream' % sctop.__scriptid__))
                util.debug("[SC] stream %s" % str(stream))
                self.stream = stream
            except:
                pass

        url = "%s/Stats?action=%s" % (sctop.BASE_URL, data.get(
            'action', 'None'))
        data.update({'est': self.estimateFinishTime})
        data.update({'se': self.se, 'ep': self.ep})
        data.update({'ver': sctop.addonInfo('version')})
        try:
            data.update(
                {'state': bool(xbmc.getCondVisibility("!Player.Paused"))})
            data.update({
                'ws': xbmcgui.Window(10000).getProperty('ws.ident'),
                'vip': xbmcgui.Window(10000).getProperty('ws.vip'),
                'vt': xbmcgui.Window(10000).getProperty('ws.viptyp')
            })
            data.update({'vd': xbmcgui.Window(10000).getProperty('ws.days')})
            data.update({'skin': xbmc.getSkinDir()})
            if self.stream is not None:
                if 'bitrate' in self.stream:
                    util.debug("[SC] action bitrate")
                    data.update({'bt': self.stream['bitrate']})
                else:
                    util.debug("[SC] action no bitrate")
                if 'sid' in self.stream:
                    util.info(
                        '[SC] mame sid <===================================================================================='
                    )
                    data.update({'sid': self.stream['sid']})
                else:
                    util.info(
                        '[SC] no sid in stream <==================================================================================== %s'
                        % str(self.stream))
        except Exception as e:
            util.info('[SC] problem s updatom dat: %s' %
                      str(traceback.format_exc()))
            pass
        try:
            if self.itemDuration > 0:
                data.update({'dur': self.itemDuration})
        except Exception:
            pass

        lastAction = xbmcgui.Window(10000).getProperty('sc.lastAction')
        util.debug('[SC] lastAction: %s' % (str(lastAction)))
        if lastAction == "" or time() - float(lastAction) > 5:
            xbmcgui.Window(10000).setProperty('sc.lastAction', str(time()))
            util.debug("[SC] action: %s" % str(data))
            url = self.parent.provider._url(url)
            try:
                sctop.post_json(url, data, {'X-UID': sctop.uid})
            except:
                pass
예제 #5
0
def getTrakt(url, post=None, output='content', method=None):
    try:
        use_ssl = sctop.getSettingAsBool('UseSSL')
        url = urlparse.urljoin(
            'http%s://api.trakt.tv' % ('s' if use_ssl else ''), url)

        headers = {'trakt-api-key': sctop.trCL, 'trakt-api-version': '2'}

        if getTraktCredentialsInfo() == False:
            util.debug("[SC] gt 1 data: %s %s" % (str(url), str(post)))
            if post is not None:
                result = util.post_json(url, post, headers)
            else:
                result = util.request(url, headers)
            util.debug("[SC] gt 1 result: %s" % str(result))
            return result

        headers[
            'Authorization'] = 'Bearer %s' % sctop.getSetting('trakt.token')
        #util.debug('[SC] token %s' % sctop.getSetting('trakt.token'))

        if post is not None:
            result, code = sctop.post_json(url, post, headers, "extend")
            info = None
        else:
            result, code, info = sctop.request(
                url, headers, "info", method=method)
        #util.debug("[SC] trakt gt result: %s %s" % (str(result), str(code)))
        if not (code == 401 or code == 405):
            if output == "content":
                return result
            else:
                return (result, code, info)

        oauth = 'http%s://api.trakt.tv/oauth/token' % ('s' if use_ssl else '')
        opost = {
            'client_id': sctop.trCL,
            'client_secret': sctop.trSC,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': sctop.getSetting('trakt.refresh')
        }

        result, code = sctop.post_json(oauth, opost, headers, "extend")
        if code == 401:
            authTrakt()
            result, code = sctop.post_json(oauth, opost, headers, "extend")
        result = json.loads(result)

        token, refresh = result['access_token'], result['refresh_token']

        sctop.setSetting(setting='trakt.token', value=token)
        sctop.setSetting(setting='trakt.refresh', value=refresh)

        headers['Authorization'] = 'Bearer %s' % token

        util.debug('[SC] token: %s' % token)

        result = sctop.post_json(url, post, headers)
        return result
    except Exception as e:
        util.error(e)
        pass