Exemplo n.º 1
0
def getTrakt(url, post=None):

    try:

        url = urlparse.urljoin('http://api-v2launch.trakt.tv/', url);

        headers = {
            'Content-Type': 'application/json', 
            'trakt-api-key': '49e7f57ee0c22e6ca39649a9255f6097d10cbdb708a5f1c3dc196e615cce6549', 
            'trakt-api-version': '2'
        };

        if not post == None: 
            post = json.dumps(post);

        if getTraktCredentialsInfo() == False:
            
            result = client.request(url, post=post, headers=headers);

            return result;


        headers.update({'Authorization': 'Bearer %s' % utils.setting('trakt.token')});

        result = client.request(url, post=post, headers=headers, output='response', error=True);

        if not (result[0] == '401' or result[0] == '405'): 
            return result[1];


        oauth = 'http://api-v2launch.trakt.tv/oauth/token';

        opost = {
            'client_id': '49e7f57ee0c22e6ca39649a9255f6097d10cbdb708a5f1c3dc196e615cce6549', 
            'client_secret': '49288059527f042ac3e953419ecfd8c6783438ae966cd0b05982423e7fbb0259', 
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 
            'grant_type': 'refresh_token', 
            'refresh_token': utils.setting('trakt.refresh')
        };

        result = client.request(oauth, post=json.dumps(opost), headers=headers);
        result = json.loads(result);

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

        utils.setting('trakt.token', token);
        urils.setting('trakt.refresh', refresh);

        headers.update({'Authorization': 'Bearer %s' % token});

        result = client.request(url, post=post, headers=headers);

        return result;

    except:
        pass;
Exemplo n.º 2
0
def getTraktCredentialsInfo():

    user = utils.setting('trakt.user').strip();
    token = utils.setting('trakt.token');
    refresh = utils.setting('trakt.refresh');

    if (user == '' or token == '' or refresh == ''): 
        return False;

    return True;
    def convertValue(self, prop):

        if prop == 'content_type':
            return 'Subbed' if (int(utils.setting('fn.%s' % prop)) if not None else 0) == 0 else 'Dubbed';

        if prop == 'result_count':
            result_count = int(utils.setting('fn.%s' % prop)) if not None else 0;

            return 3000 if (result_count == 0) else result_count;

        return;
    def __init__(self):

        self.logger = logging.getLogger('funimationnow');

        self.uid = utils.setting('fn.uid');
        self.ut = utils.setting('fn.ut') if not None else 'FunimationUser';
        self.result_count = self.convertValue('result_count');
        self.content_type = self.convertValue('content_type');

        self.role = self.checkrole();

        if self.result_count == 0:
            self.result_count = 3000;
    def run(self, videourl, listitem):

        try:

            xbmc.sleep(200)

            self.totalTime = 0
            self.currentTime = 0
            self.offset = '0'
            self.item = listitem
            self.startPosition = self.item.getProperty('startPosition')
            self.usecurrentprogress = 1
            self.show_subtitles = utils.setting('fn.show_subtitles')

            if self.show_subtitles is None or self.show_subtitles in ('true',
                                                                      'True',
                                                                      True):
                self.show_subtitles = True

            else:
                self.show_subtitles = False

            if self.startPosition:

                try:

                    self.startPosition = int(self.startPosition)

                    if self.startPosition > 0:

                        self.usecurrentprogress = utils.requestContinueProgress(
                            self.startPosition)

                        if self.usecurrentprogress != 0:
                            self.startPosition = 0

                except:
                    self.startPosition = 0

            else:
                self.startPosition = 0

            if self.usecurrentprogress >= 0:

                videourl = re.sub(r'&', '&', videourl)
                videourl = utils.resolutionPicker(videourl)

                if videourl:

                    self.play(videourl, listitem, False)
                    self.keepPlaybackAlive()

        except Exception as inst:
            logger.error(inst)

            return
    def search(self, action, params):
        import animeshows;

        if 'ut' not in params:
            params.update({'ut': (utils.setting('fn.ut') if not None else 'FunimationUser')});

        if 'filterx' not in params:
            params.update({'filterx': 'FilterOption%sOnly' % ('Subbed' if (int(utils.setting('fn.content_type')) if not None else 0) == 0 else 'Dubbed')});

        if 'offset' not in params:
            params.update({'offset': 0});

        if 'limit' not in params:
            params.update({'limit': 3000});

        if 'filtertype' not in params:
            params.update({'filtertype': 'search'});

        self.filtered(action=action, params=params, filtertype='search');
Exemplo n.º 7
0
def confirmLogin():

    token = utils.getToken('funimationnow')
    userType = utils.setting('fn.userType')

    if userType and token:

        if userType.lower() == 'funimationsubscriptionuser':
            return True

        else:
            return False

    else:
        return False
Exemplo n.º 8
0
def authTrakt():

    try:

        if getTraktCredentialsInfo() == True:

            if control.yesnoDialog(control.lang(32700).encode('utf-8'), control.lang(32701).encode('utf-8'), '', 'Trakt'):

                utils.setting('trakt.user', '');
                utils.setting('trakt.token', '');
                utils.setting('trakt.refresh', '');

            raise Exception();

        result = getTrakt('/oauth/device/code', {'client_id': '49e7f57ee0c22e6ca39649a9255f6097d10cbdb708a5f1c3dc196e615cce6549'});
        result = json.loads(result);

        verification_url = (control.lang(32702) % result['verification_url']).encode('utf-8');
        user_code = (control.lang(32703) % result['user_code']).encode('utf-8');
        expires_in = int(result['expires_in']);
        device_code = result['device_code'];
        interval = result['interval'];

        progressDialog = control.progressDialog;
        progressDialog.create('Trakt', verification_url, user_code);

        for i in range(0, expires_in):

            try:

                if progressDialog.iscanceled(): 
                    break;

                time.sleep(1);

                if not float(i) % interval == 0: 
                    raise Exception();

                r = getTrakt('/oauth/device/token', {'client_id': '49e7f57ee0c22e6ca39649a9255f6097d10cbdb708a5f1c3dc196e615cce6549', 'client_secret': '49288059527f042ac3e953419ecfd8c6783438ae966cd0b05982423e7fbb0259', 'code': device_code});
                r = json.loads(r);

                if 'access_token' in r: 
                    break;
            
            except:
                pass;

        try: 
            progressDialog.close();
        
        except: 
            pass;


        token = r['access_token'];
        refresh = r['refresh_token'];

        headers = {
            'Content-Type': 'application/json', 
            'trakt-api-key': '49e7f57ee0c22e6ca39649a9255f6097d10cbdb708a5f1c3dc196e615cce6549', 
            'trakt-api-version': '2', 
            'Authorization': 'Bearer %s' % token
        };

        result = client.request('http://api-v2launch.trakt.tv/users/me', headers=headers);
        result = json.loads(result);

        user = result['username'];

        utils.setting('trakt.user', user);
        utils.setting('trakt.token', token);
        utils.setting('trakt.refresh', refresh);

        raise Exception();

    except:
        control.openSettings('3.1');
    def checkrole(self):

        utils.checkcookie();
        role = utils.setting('fn.user_role');

        return role;
Exemplo n.º 10
0
            return False

    else:
        return False


if len(sys.argv) > 1 and sys.argv[1] == 'cleanup':

    from resources.lib.modules import cleardata

    logger.debug('Running Cleanup Script')

    try:
        cleardata.cleanup()

    except:
        pass

elif (__name__ == '__main__'):

    splash_screen = utils.setting('fn.splash_screen')

    if splash_screen is None or splash_screen in ('true', 'True', True):
        splashscreen()

    if confirmLogin():
        mainGui()

    else:
        loginWindow()
    def formatItemSet(self, threads, itemset, mid, lid, qid):

        mcontrol = self.getControl(mid)
        lcontrol = self.getControl(lid)
        qcontrol = None

        try:

            qcontrol = self.getControl(qid)
            #qcontrol.setSelected(False);

        except Exception as inst:
            self.logger.warn(inst)

        #for item in itemset[1]:
        for sIdx, item in enumerate(itemset[1], 0):

            titles = []
            listitem = None
            thumbnail = item.get('thumbnail', '')

            if lid in SHOW_IDS:
                thumbnail = funimationnow.formatImgUrl(thumbnail, theme='show')

            else:
                thumbnail = funimationnow.formatImgUrl(thumbnail,
                                                       theme='episode')

            listitem = xbmcgui.ListItem(item.get('title', ''),
                                        item.get('subtitle', ''), thumbnail,
                                        thumbnail)

            if itemset[0] == 'episodes' or itemset[0] == 'history':

                titles = [item.get('title', ''),
                          item.get('subtitle', '')]

            else:
                titles = [item.get('title', '')]

            titleimg = utils.text2Title(list(titles), self.details_home_title,
                                        item.get('titleimg', ''))

            listitem.setProperty('showcaseimg',
                                 funimationnow.formatImgUrl(thumbnail))

            try:

                listitem.setProperty('viewtype', str(itemset[0]))

                for attr, val in item.items():

                    listitem.setProperty(attr, str(val))

            except Exception as inst:
                self.logger.error(inst)

            if 'progress' in item:

                cprogress = item.get('progress', 0)

                listitem.setProperty('cprogress', str(cprogress))

            if 'inQueue' in item:

                inQueue = item.get('inQueue', None)

                if inQueue is not None:

                    listitem.setProperty('qtexture', str(inQueue))

                elif qcontrol:
                    qcontrol.setVisible(False)

            if titleimg:
                listitem.setProperty('ctitle', titleimg)

            lcontrol.addItem(listitem)

            prefetch = utils.setting('fn.background_sync')

            if prefetch is None or prefetch in ('true', 'True', True):

                #http://stackoverflow.com/questions/1787397/how-do-i-limit-the-number-of-active-threads-in-python
                threads.append(
                    workers.DetailsThread(target=self.populateDetails,
                                          args=(
                                              lcontrol,
                                              listitem,
                                              sIdx,
                                              itemset[0],
                                              lid,
                                              False,
                                          )))

        if len(itemset) < 4:
            navmenu = itemset[2]

        else:
            navmenu = itemset[3]

        if navmenu:
            #self.logger.error(navmenu.get('width', '0'))
            mcontrol.setWidth(int(navmenu.get('width', '0')))