def listClone(user, list_id):
    src = json.loads(getTrakt('/users/%s/lists/%s' % (user, list_id)))
    dst = {
        'name': '%s (%s)' % (src['name'], _getUserName(src['user'])),
        'privacy': 'private',
        'display_numbers': False
    }

    if not sctop.yesnoDialog(
            sctop.getString(30970).encode("utf-8"), "[B]%s[/B]?" % dst['name'],
            ""):
        return False

    for key in ['description', 'sort_by', 'sort_how']:
        dst[key] = src[key]

    dst = json.loads(getTrakt('/users/me/lists', post=dst))
    dst_items = _getListItemsForImport(user, list_id)
    result, code, info = getTrakt('/users/me/lists/%s/items' %
                                  dst['ids']['slug'],
                                  post=dst_items,
                                  output="info")
    if code == 201:
        sctop.infoDialog('%s' % dst['name'],
                         sctop.getString(30976).encode("utf-8"))
    else:
        util.debug('[SC] List %s/%s: %d, %s' % (user, list_id, code, result))
def listLike(title, user, list_id):
    result, code, info = getTrakt(
        '/users/%s/lists/%s/like' % (user, list_id), post={}, output="info")
    if code == 204:
        sctop.infoDialog("%s" % title, sctop.getString(30975).encode("utf-8"))
    else:
        util.debug("[SC] List like: %s %d" % result, code)
def listClone(user, list_id):
    src = json.loads(getTrakt('/users/%s/lists/%s' % (user, list_id)))
    dst = {
        'name': '%s (%s)' % (src['name'], _getUserName(src['user'])),
        'privacy': 'private',
        'display_numbers': False
    }

    if not sctop.yesnoDialog(
            sctop.getString(30970).encode("utf-8"), "[B]%s[/B]?" % dst['name'],
            ""):
        return False

    for key in ['description', 'sort_by', 'sort_how']:
        dst[key] = src[key]

    dst = json.loads(getTrakt('/users/me/lists', post=dst))
    dst_items = _getListItemsForImport(user, list_id)
    result, code, info = getTrakt(
        '/users/me/lists/%s/items' % dst['ids']['slug'],
        post=dst_items,
        output="info")
    if code == 201:
        sctop.cache.set('trakt.lists', None, expiration=timedelta())
        sctop.infoDialog('%s' % dst['name'],
                         sctop.getString(30976).encode("utf-8"))
    else:
        util.debug('[SC] List %s/%s: %d, %s' % (user, list_id, code, result))
def listUnlike(title, user, list_id):
    result, code, info = getTrakt('/users/%s/lists/%s/like' % (user, list_id),
                                  output="info",
                                  method="DELETE")
    if code == 204:
        sctop.infoDialog("%s" % title, sctop.getString(30974).encode("utf-8"))
    else:
        util.debug("[SC] List unlike: %s %d" % result, code)
def listLike(title, user, list_id):
    result, code, info = getTrakt('/users/%s/lists/%s/like' % (user, list_id),
                                  post={},
                                  output="info")
    if code == 204:
        sctop.infoDialog("%s" % title, sctop.getString(30975).encode("utf-8"))
    else:
        util.debug("[SC] List like: %s %d" % result, code)
    def _resolve(self, itm):
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' and itm.get(
                'params').get('cp') == 'webshare.cz':
            if sctop.getSetting('wsuser') == "":
                res = sctop.yesnoDialog(sctop.getString(30945),
                                        sctop.getString(30946), "")
                if res == True:
                    sctop.openSettings('201.101')
                    return None
            try:
                from myprovider.webshare import Webshare as wx
                self.ws = wx(sctop.getSetting('wsuser'),
                             sctop.getSetting('wspass'), self.cache)
                if not self.ws.login():
                    res = sctop.yesnoDialog(sctop.getString(30945),
                                            sctop.getString(30946), "")
                    if res == True:
                        sctop.openSettings('201.101')
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata == False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        sctop.infoDialog(sctop.getString(30948) % str(udata),
                                         icon="WARNING")
                        util.debug("[SC] VIP ucet konci")

                itm['url'] = self.ws.resolve(
                    itm.get('params').get('play').get('ident'))
                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2])
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception, e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except:
def listUnlike(title, user, list_id):
    result, code, info = getTrakt(
        '/users/%s/lists/%s/like' % (user, list_id),
        output="info",
        method="DELETE")
    if code == 204:
        sctop.infoDialog("%s" % title, sctop.getString(30974).encode("utf-8"))
    else:
        util.debug("[SC] List unlike: %s %d" % result, code)
def listCustomRemove(title, list_id):
    if not sctop.yesnoDialog(
            sctop.getString(30972).encode("utf-8"), "[B]%s[/B]?" % title, ""):
        return False

    result, code, info = getTrakt('/users/me/lists/%s' % list_id,
                                  output="info",
                                  method="DELETE")

    if code == 204:
        sctop.infoDialog("%s" % title, sctop.getString(30973).encode("utf-8"))
    else:
        util.debug("[SC] List remove: code %d" % code)
def listCustomRemove(title, list_id):
    if not sctop.yesnoDialog(
            sctop.getString(30972).encode("utf-8"), "[B]%s[/B]?" % title, ""):
        return False

    result, code, info = getTrakt(
        '/users/me/lists/%s' % list_id, output="info", method="DELETE")

    if code == 204:
        sctop.cache.set('trakt.lists', None, expiration=timedelta())
        sctop.infoDialog("%s" % title, sctop.getString(30973).encode("utf-8"))
    else:
        util.debug("[SC] List remove: code %d" % code)
def manager(name, imdb, tvdb, content):
    try:
        icon = sctop.infoLabel('ListItem.Icon')
        post = {"movies": [{"ids": {"imdb": imdb}}]} if content == 'movie' else {"shows": [{"ids": {"tvdb": tvdb}}]}

        items = [(sctop.getString(30934).encode('utf-8'), '/sync/collection')]
        items += [(sctop.getString(30935).encode('utf-8'), '/sync/collection/remove')]
        items += [(sctop.getString(30936).encode('utf-8'), '/sync/watchlist')]
        items += [(sctop.getString(30937).encode('utf-8'), '/sync/watchlist/remove')]
        items += [(sctop.getString(30938).encode('utf-8'), '/users/me/lists/%s/items')]

        result = getTrakt('/users/me/lists')
        result = json.loads(result)
        lists = [(i['name'], i['ids']['slug']) for i in result]
        lists = [lists[i // 2] for i in range(len(lists) * 2)]
        util.debug("[SC] string %s" % sctop.getString(30939))
        for i in range(0, len(lists), 2):
            lists[i] = (
                (sctop.getString(30939) % lists[i][0]).encode('utf-8'), 
                '/users/me/lists/%s/items' % lists[i][1])
        for i in range(1, len(lists), 2):
            lists[i] = (
                (sctop.getString(30940) % lists[i][0]).encode('utf-8'), 
                '/users/me/lists/%s/items/remove' % lists[i][1])
        items += lists

        select = sctop.selectDialog([i[0] for i in items], sctop.getString(30941).encode('utf-8'))

        if select == -1:
            return
        elif select == 4:
            t = sctop.getString(30938).encode('utf-8')
            k = sctop.keyboard('', t); k.doModal()
            new = k.getText() if k.isConfirmed() else None
            if (new == None or new == ''): return
            result = getTrakt('/users/me/lists', post={"name": new, "privacy": "private"})

            try: slug = json.loads(result)['ids']['slug']
            except: return sctop.infoDialog(sctop.getString(30941).encode('utf-8'), heading=str(name), sound=True, icon='ERROR')
            result = getTrakt(items[select][1] % slug, post=post)
        else:
            result = getTrakt(items[select][1], post=post)

        icon = icon if not result == None else 'ERROR'

        sctop.infoDialog(sctop.getString(30941).encode('utf-8'), heading=str(name), sound=True, icon=icon)
    except Exception, e:
        util.debug("[SC] trakt error: %s" % str(traceback.format_exc()))
        return
def listAppendToCustom(user, list_id):
    lists = json.loads(getTrakt('/users/me/lists'))
    lists = [(i['ids']['slug'], i['name']) for i in lists]
    select = sctop.selectDialog([i[1] for i in lists],
                                sctop.getString(30968).encode("utf-8"))
    if select == -1: return

    dst_list = lists[select][0]
    dst_items = _getListItemsForImport(user, list_id)
    result, code, info = getTrakt('/users/me/lists/%s/items' % dst_list,
                                  post=dst_items,
                                  output="info")
    if code == 201:
        sctop.infoDialog("%s" % lists[select][1],
                         sctop.getString(30969).encode("utf-8"))
    else:
        util.debug('[SC] import to %s failed. %d, %s' %
                   (dst_list, code, result))
def listAppendToCustom(user, list_id):
    lists = json.loads(getTrakt('/users/me/lists'))
    lists = [(i['ids']['slug'], i['name'], i['ids']['trakt']) for i in lists]
    select = sctop.selectDialog([i[1] for i in lists],
                                sctop.getString(30968).encode("utf-8"))
    if select == -1: return

    dst_list = lists[select]
    dst_items = _getListItemsForImport(user, list_id)
    result, code, info = getTrakt('/users/me/lists/%s/items' % dst_list[0],
                                  post=dst_items,
                                  output="info")
    if code == 201:
        sctop.infoDialog("%s" % dst_list[1],
                         sctop.getString(30969).encode("utf-8"))
        for c in ['shows', 'movies']:
            sctop.cache.set('trakt.lists.%s.%s' % (dst_list[2], c),
                            None,
                            expiration=timedelta())
    else:
        util.debug('[SC] import to %s failed. %d, %s' %
                   (dst_list[0], code, result))
def listAppendToCustom(user, list_id):
    lists = json.loads(getTrakt('/users/me/lists'))
    lists = [(i['ids']['slug'], i['name'], i['ids']['trakt']) for i in lists]
    select = sctop.selectDialog([i[1] for i in lists],
                                sctop.getString(30968).encode("utf-8"))
    if select == -1: return

    dst_list = lists[select]
    dst_items = _getListItemsForImport(user, list_id)
    result, code, info = getTrakt(
        '/users/me/lists/%s/items' % dst_list[0],
        post=dst_items,
        output="info")
    if code == 201:
        sctop.infoDialog("%s" % dst_list[1],
                         sctop.getString(30969).encode("utf-8"))
        for c in ['shows', 'movies']:
            sctop.cache.set(
                'trakt.lists.%s.%s' % (dst_list[2], c),
                None,
                expiration=timedelta())
    else:
        util.debug(
            '[SC] import to %s failed. %d, %s' % (dst_list[0], code, result))
示例#14
0
    def _resolve(self, itm):
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' and itm.get(
                'params').get('cp') == 'webshare.cz':
            if self.parent.getSetting('wsuser') != "":
                try:
                    from myprovider.webshare import Webshare as wx
                    self.ws = wx(self.parent.getSetting('wsuser'),
                                 self.parent.getSetting('wspass'))
                    if not self.ws.login():
                        res = sctop.yesnoDialog(sctop.getString(30945),
                                                sctop.getString(30946), "")
                        if res == True:
                            sctop.openSettings('201.101')
                        return None
                    else:
                        udata = self.ws.userData()
                        util.debug("[SC] udata: %s" % str(udata))
                        if udata == False:
                            util.debug("[SC] NIEJE VIP ucet")
                            sctop.infoDialog(sctop.getString(30947),
                                             icon="WARNING")
                            sctop.sleep(5000)
                        elif int(udata) <= 14:
                            sctop.infoDialog(sctop.getString(30948) %
                                             str(udata),
                                             icon="WARNING")
                            util.debug("[SC] VIP ucet konci")

                    itm['url'] = self.ws.resolve(
                        itm.get('params').get('play').get('ident'))
                except:
                    buggalo.onExceptionRaised()
                    pass
            else:
                sctop.infoDialog(sctop.getString(30945), icon="WARNING")
                #sctop.openSettings('0.1')

        else:
            try:
                raise ResolveException('zatial nic...')
                hmf = urlresolver.HostedMediaFile(url=itm['url'],
                                                  include_disabled=False,
                                                  include_universal=False)
                if hmf.valid_url() is True:
                    try:
                        itm['url'] = hmf.resolve()
                    except:
                        pass
            except:
                pass
        itm['title'] = self.parent.encode(itm['title'])
        return itm
def manager(name, trakt, content):
    try:
        icon = sctop.infoLabel('ListItem.Icon')
        message = sctop.getString(30941).encode('utf-8')
        content = "movies" if content == 'movie' else "shows"
        post = {content: [{"ids": {"trakt": trakt}}]}
        trakt = int(trakt)
        relevant = sctop.getSettingAsBool('trakt.relevant_menu')

        items = []
        if sctop.getSettingAsBool('trakt.collections'):
            key = 'trakt.collection.%s.ids' % content
            if relevant:
                ids = _get_cached_ids(key, '/users/me/collection/%s' % content)

            if not relevant or trakt not in ids:
                items = [(sctop.getString(30934).encode('utf-8'),
                          '/sync/collection', key)]
            if not relevant or trakt in ids:
                items += [(sctop.getString(30935).encode('utf-8'),
                           '/sync/collection/remove', key)]

        if sctop.getSettingAsBool('trakt.watchlist'):
            key = 'trakt.watchlist.%s.ids' % content
            if relevant:
                ids = _get_cached_ids(key, '/users/me/watchlist/%s' % content)

            if not relevant or trakt not in ids:
                items += [(sctop.getString(30936).encode('utf-8'),
                           '/sync/watchlist', key)]
            if not relevant or trakt in ids:
                items += [(sctop.getString(30937).encode('utf-8'),
                           '/sync/watchlist/remove', key)]

        items += [(sctop.getString(30989), 'rating')]

        lists = sctop.cache.get('trakt.lists')
        if not relevant or not lists:
            result = getTrakt('/users/me/lists')
            lists = json.loads(result)
            sctop.cache.set('trakt.lists', lists)

        util.debug("[SC] string %s" % sctop.getString(30939))

        for lst in lists:
            key = 'trakt.lists.%s.%s.ids' % (lst['ids']['trakt'], content)
            if relevant:
                ids = _get_cached_ids(
                    key, '/users/me/lists/%s/items/%s' %
                    (lst['ids']['slug'], content))
            if not relevant or trakt not in ids:
                items.append(
                    ((sctop.getString(30939) % lst['name']).encode('utf-8'),
                     '/users/me/lists/%s/items' % lst['ids']['slug'], key))

            if not relevant or trakt in ids:
                items.append(
                    ((sctop.getString(30940) % lst['name']).encode('utf-8'),
                     '/users/me/lists/%s/items/remove' % lst['ids']['slug'],
                     key))

        items += [(sctop.getString(30938).encode('utf-8'),
                   '/users/me/lists/%s/items')]

        if relevant:
            items.append(
                (sctop.getString(30811).encode('utf-8'), 'clear_cache'))

        select = sctop.selectDialog([i[0] for i in items],
                                    sctop.getString(30941).encode('utf-8'))

        if select == -1:
            return
        elif items[select][1] == 'rating':
            ratings = [(sctop.getString(i + 30990).encode('utf-8'), i)
                       for i in range(10, -1, -1)]
            select = sctop.selectDialog([i[0] for i in ratings], str(name))
            url = "/sync/ratings/remove"
            if select == -1:
                return
            elif ratings[select][1] != 0:
                url = "/sync/ratings"
                post[content][0]['rating'] = ratings[select][1]
            try:
                result = getTrakt(url, post=post)
                result = json.loads(result)
            except:
                return sctop.infoDialog(sctop.getString(30941).encode('utf-8'),
                                        heading=str(name),
                                        sound=True,
                                        icon='ERROR')

            if 'added' in result:
                if result['added'][content]:
                    message = sctop.getString(30987).encode(
                        'utf-8') % ratings[select][1]
                else:
                    return

            if 'deleted' in result:
                if result['deleted'][content]:
                    message = sctop.getString(30988).encode('utf-8')
                else:
                    return

        elif items[select][1] == '/users/me/lists/%s/items':
            t = sctop.getString(30938).encode('utf-8')
            k = sctop.keyboard('', t)
            k.doModal()
            new = k.getText() if k.isConfirmed() else None
            if (new == None or new == ''): return
            result = getTrakt('/users/me/lists',
                              post={
                                  "name": new,
                                  "privacy": "private"
                              })
            sctop.cache.set('trakt.lists', None, expiration=timedelta())
            try:
                slug = json.loads(result)['ids']['slug']
            except:
                return sctop.infoDialog(sctop.getString(30941).encode('utf-8'),
                                        heading=str(name),
                                        sound=True,
                                        icon='ERROR')
            result = getTrakt(items[select][1] % slug, post=post)
        elif items[select][1] == 'clear_cache':
            ttl = timedelta()
            sctop.cache.set('trakt.lists', None, expiration=ttl)

            contents = ['shows', 'movies']
            for l in ['watchlist', 'collection']:
                for c in contents:
                    key = 'trakt.%s.%s.ids' % (l, c)
                    sctop.cache.set(key, None, expiration=ttl)

            result = getTrakt('/users/me/lists')
            lists = json.loads(result)
            for l in lists:
                for c in contents:
                    key = 'trakt.lists.%s.%s.ids' % (l['ids']['trakt'], c)
                    sctop.cache.set(key, None, expiration=ttl)

            message = sctop.getString(30812).encode('utf-8')
            name = sctop.getString(30941).encode('utf-8')
        else:
            result = getTrakt(items[select][1], post=post)
            key = items[select][2]
            if result and relevant:
                ids = sctop.cache.get(key)
                if type(ids) is list:
                    if items[select][1][-7:] == '/remove':
                        ids = [i for i in ids if i != trakt]
                    else:
                        ids.append(trakt)
                    sctop.cache.set(key, ids)

        icon = icon if not result == None else 'ERROR'

        sctop.infoDialog(message, heading=str(name), sound=True, icon=icon)
    except Exception as e:
        util.debug("[SC] trakt error: %s" % str(traceback.format_exc()))
        return
def manager(name, trakt, content):
    try:
        icon = sctop.infoLabel('ListItem.Icon')
        message = sctop.getString(30941).encode('utf-8')
        content = "movies" if content == 'movie' else "shows"
        post = {content: [{"ids": {"trakt": trakt}}]}

        items = []
        if sctop.getSettingAsBool('trakt.collections'):
            items = [(sctop.getString(30934).encode('utf-8'),
                      '/sync/collection')]
            items += [(sctop.getString(30935).encode('utf-8'),
                       '/sync/collection/remove')]
        if sctop.getSettingAsBool('trakt.watchlist'):
            items += [(sctop.getString(30936).encode('utf-8'),
                       '/sync/watchlist')]
            items += [(sctop.getString(30937).encode('utf-8'),
                       '/sync/watchlist/remove')]
        items += [(sctop.getString(30989), 'rating')]
        items += [(sctop.getString(30938).encode('utf-8'),
                   '/users/me/lists/%s/items')]

        result = getTrakt('/users/me/lists')
        result = json.loads(result)
        lists = [(i['name'], i['ids']['slug']) for i in result]
        lists = [lists[i // 2] for i in range(len(lists) * 2)]
        util.debug("[SC] string %s" % sctop.getString(30939))
        for i in range(0, len(lists), 2):
            lists[i] = ((sctop.getString(30939) % lists[i][0]).encode('utf-8'),
                        '/users/me/lists/%s/items' % lists[i][1])
        for i in range(1, len(lists), 2):
            lists[i] = ((sctop.getString(30940) % lists[i][0]).encode('utf-8'),
                        '/users/me/lists/%s/items/remove' % lists[i][1])
        items += lists

        select = sctop.selectDialog([i[0] for i in items],
                                    sctop.getString(30941).encode('utf-8'))

        if select == -1:
            return
        elif items[select][1] == 'rating':
            ratings = [(sctop.getString(i + 30990).encode('utf-8'), i)
                       for i in range(10, -1, -1)]
            select = sctop.selectDialog([i[0] for i in ratings], str(name))
            url = "/sync/ratings/remove"
            if select == -1:
                return
            elif ratings[select][1] != 0:
                url = "/sync/ratings"
                post[content][0]['rating'] = ratings[select][1]
            try:
                result = getTrakt(url, post=post)
                result = json.loads(result)
            except:
                return sctop.infoDialog(sctop.getString(30941).encode('utf-8'),
                                        heading=str(name),
                                        sound=True,
                                        icon='ERROR')

            if 'added' in result:
                if result['added'][content]:
                    message = sctop.getString(30987).encode(
                        'utf-8') % ratings[select][1]
                else:
                    return

            if 'deleted' in result:
                if result['deleted'][content]:
                    message = sctop.getString(30988).encode('utf-8')
                else:
                    return

        elif items[select][1] == '/users/me/lists/%s/items':
            t = sctop.getString(30938).encode('utf-8')
            k = sctop.keyboard('', t)
            k.doModal()
            new = k.getText() if k.isConfirmed() else None
            if (new == None or new == ''): return
            result = getTrakt('/users/me/lists',
                              post={
                                  "name": new,
                                  "privacy": "private"
                              })

            try:
                slug = json.loads(result)['ids']['slug']
            except:
                return sctop.infoDialog(sctop.getString(30941).encode('utf-8'),
                                        heading=str(name),
                                        sound=True,
                                        icon='ERROR')
            result = getTrakt(items[select][1] % slug, post=post)
        else:
            result = getTrakt(items[select][1], post=post)

        icon = icon if not result == None else 'ERROR'

        sctop.infoDialog(message, heading=str(name), sound=True, icon=icon)
    except Exception as e:
        util.debug("[SC] trakt error: %s" % str(traceback.format_exc()))
        return
    def _resolve(self, itm):
        util.debug("[SC] _resolve")
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files' or itm.get(
                'provider') == 'webshare':
            if sctop.getSetting('wsuser') == "":
                sctop.infoDialog(sctop.getString(30945),
                                 sctop.getString(30946))
                return None
            try:
                if not self.ws.login():
                    sctop.infoDialog(sctop.getString(30945),
                                     sctop.getString(30946))
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata is False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        try:
                            if sctop.getSetting('ws_notify') != '' and int(
                                    sctop.getSetting('ws_notify')
                            ) > int(datetime.datetime.now().strftime("%s")):
                                sctop.infoDialog(sctop.getString(30948) %
                                                 str(udata),
                                                 icon="WARNING")
                            else:
                                sctop.setSetting(
                                    "ws_notify",
                                    str(
                                        int(datetime.datetime.now().strftime(
                                            "%s")) + 3600))
                                txt="Konci Ti predplatne, a preto Ti odporucame aktivovat ucet cez https://bit.ly/sc-kra " \
                                + "za zvyhodnene ceny. " \
                                + "Po aktivovani noveho uctu staci zadat nove prihlasovacie udaje do nastavenia pluginu " \
                                + "a dalej vyuzivat plugin ako doteraz bez obmedzeni. "
                                sctop.dialog.ok("Upozornenie...", txt)
                        except:
                            util.debug('[SC] notify error %s' %
                                       str(traceback.format_exc()))
                        util.debug("[SC] VIP ucet konci")

                try:
                    util.debug('[SC] ideme pre webshare ident %s' % itm['url'])
                    ident = self._json(self._url(itm['url']))['ident']
                except:
                    ident = '6d8359zW1u'
                    pass

                try:
                    jsdata = json.loads(sctop.request(
                        self._url('/Stats/file')))
                    if 'ident' in jsdata:
                        sctop.request(self.ws.resolve(jsdata['ident']))
                except Exception as e:
                    pass

                itm['url'] = self.ws.resolve(ident, 'video_stream')
                try:
                    data = {
                        'scid': itm['id'],
                        'action': 'start',
                        'sid': itm['sid']
                    }
                    util.debug("[SC] prehravanie %s" % str(data))
                    sctop.player.scid = itm['id']
                    sctop.player.action(data)
                except Exception as e:
                    util.debug(
                        '[SC] nepodarilo sa vykonat akciu "start" %s | %s' %
                        (str(e), str(traceback.format_exc())))

                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2], 'file_download')
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except Exception as e:
                util.debug("[SC] chyba.... %s %s" %
                           (str(e), str(traceback.format_exc())))
                bug.onExceptionRaised()
                pass
        elif itm.get('provider') == 'kraska':
            try:
                kra = Kraska(sctop.getSetting('kruser'),
                             sctop.getSetting('krpass'), self.cache)

                try:
                    util.debug('[SC] ideme pre kra ident %s' % itm['url'])
                    ident = self._json(self._url(itm['url']))['ident']
                except Exception as e:
                    util.debug('[SC] error get ident: %s' %
                               str(traceback.format_exc()))
                    return

                itm['url'] = kra.resolve(ident)
                itm['headers'] = {'User-Agent': util.UA}
                try:
                    if itm['subs'] is not None:
                        if "kra.sk" in itm['subs']:
                            import urlparse
                            import re
                            o = urlparse(itm['subs'])
                            g = re.split('/', o[2] if o[5] == '' else o[5])
                            util.debug("[SC] kra.sk titulky: %s | %s" %
                                       (str(g[2]), itm['subs']))
                            url = self.kr.resolve(g[2])
                            itm['subs'] = url
                            content = sctop.request(url)
                            itm['subs'] = self.parent.saveSubtitle(
                                content, 'cs', False)
                            util.debug("[SC] posielam URL na titulky: %s" %
                                       itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba KRA titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
            except Exception as e:
                util.debug('[SC] kra error')
                pass
        itm['title'] = self.parent.encode(itm['title'])

        return itm
示例#18
0
    def _resolve(self, itm):
        util.debug("[SC] _resolve")
        if itm is None:
            return None
        if itm.get('provider') == 'plugin.video.online-files':
            if sctop.getSetting('wsuser') == "":
                res = sctop.yesnoDialog(sctop.getString(30945),
                                        sctop.getString(30946), "")
                if res == True:
                    sctop.openSettings('201.101')
                    return None
            try:
                from myprovider.webshare import Webshare as wx
                self.ws = wx(sctop.getSetting('wsuser'),
                             sctop.getSetting('wspass'), self.cache)
                if not self.ws.login():
                    res = sctop.yesnoDialog(sctop.getString(30945),
                                            sctop.getString(30946), "")
                    if res == True:
                        sctop.openSettings('201.101')
                    return None
                else:
                    udata = self.ws.userData()
                    util.debug("[SC] udata: %s" % str(udata))
                    if udata == False:
                        util.debug("[SC] NIEJE VIP ucet")
                        sctop.infoDialog(sctop.getString(30947),
                                         icon="WARNING")
                        sctop.sleep(5000)
                    elif int(udata) <= 14:
                        sctop.infoDialog(sctop.getString(30948) % str(udata),
                                         icon="WARNING")
                        util.debug("[SC] VIP ucet konci")

                try:
                    util.debug('[SC] ideme pre ident ')
                    ident = self._json(self._url(itm['url']))['ident']
                except:
                    ident = '6d8359zW1u'
                    pass

                try:
                    jsdata = json.loads(sctop.request(
                        self._url('/Stats/file')))
                    if 'ident' in jsdata:
                        sctop.request(self.ws.resolve(jsdata['ident']))
                except Exception as e:
                    pass

                itm['url'] = self.ws.resolve(ident)
                try:
                    data = {
                        'scid': itm['id'],
                        'action': 'start',
                    }
                    util.debug("[SC] prehravanie %s" % str(data))
                    sctop.player.scid = itm['id']
                    sctop.player.action(data)
                except Exception as e:
                    util.debug(
                        '[SC] nepodarilo sa vykonat akciu "start" %s | %s' %
                        (str(e), str(traceback.format_exc())))

                try:
                    if itm['subs'] is not None and "webshare.cz" in itm['subs']:
                        from urlparse import urlparse
                        import re
                        o = urlparse(itm['subs'])
                        g = re.split('/', o[2] if o[5] == '' else o[5])
                        util.debug("[SC] webshare titulky: %s | %s" %
                                   (str(g[2]), itm['subs']))
                        url = self.ws.resolve(g[2])
                        itm['subs'] = url
                        content = sctop.request(url)
                        itm['subs'] = self.parent.saveSubtitle(
                            content, 'cs', False)
                        util.debug("[SC] posielam URL na titulky: %s" %
                                   itm['subs'])
                except Exception as e:
                    util.debug("[SC] chyba WS titlkov... %s | %s" %
                               (str(e), str(traceback.format_exc())))
                    pass
                itm['headers'] = {'User-Agent': util.UA}
            except Exception as e:
                util.debug("[SC] chyba.... %s %s" %
                           (str(e), str(traceback.format_exc())))
                bug.onExceptionRaised()
                pass
        itm['title'] = self.parent.encode(itm['title'])

        return itm
def manager(name, trakt, content):
    try:
        icon = sctop.infoLabel('ListItem.Icon')
        message = sctop.getString(30941).encode('utf-8')
        content = "movies" if content == 'movie' else "shows"
        post = {content: [{"ids": {"trakt": trakt}}]}
        trakt = int(trakt)
        relevant = sctop.getSettingAsBool('trakt.relevant_menu')

        items = []
        if sctop.getSettingAsBool('trakt.collections'):
            key = 'trakt.collection.%s.ids' % content
            if relevant:
                ids = _get_cached_ids(key, '/uses/me/collection/%s' % content)

            if not relevant or trakt not in ids:
                items = [(sctop.getString(30934).encode('utf-8'),
                          '/sync/collection', key)]
            if not relevant or trakt in ids:
                items += [(sctop.getString(30935).encode('utf-8'),
                           '/sync/collection/remove', key)]

        if sctop.getSettingAsBool('trakt.watchlist'):
            key = 'trakt.watchlist.%s.ids' % content
            if relevant:
                ids = _get_cached_ids(key, '/users/me/watchlist/%s' % content)

            if not relevant or trakt not in ids:
                items += [(sctop.getString(30936).encode('utf-8'),
                           '/sync/watchlist', key)]
            if not relevant or trakt in ids:
                items += [(sctop.getString(30937).encode('utf-8'),
                           '/sync/watchlist/remove', key)]

        items += [(sctop.getString(30989), 'rating')]

        lists = sctop.cache.get('trakt.lists')
        if not relevant or not lists:
            result = getTrakt('/users/me/lists')
            lists = json.loads(result)
            sctop.cache.set('trakt.lists', lists)

        util.debug("[SC] string %s" % sctop.getString(30939))

        for lst in lists:
            key = 'trakt.lists.%s.%s.ids' % (lst['ids']['trakt'], content)
            if relevant:
                ids = _get_cached_ids(
                    key, '/users/me/lists/%s/items/%s' % (lst['ids']['slug'],
                                                          content))
            if not relevant or trakt not in ids:
                items.append(
                    ((sctop.getString(30939) % lst['name']).encode('utf-8'),
                     '/users/me/lists/%s/items' % lst['ids']['slug'], key))

            if not relevant or trakt in ids:
                items.append(
                    ((sctop.getString(30940) % lst['name']).encode('utf-8'),
                     '/users/me/lists/%s/items/remove' % lst['ids']['slug'],
                     key))

        items += [(sctop.getString(30938).encode('utf-8'),
                   '/users/me/lists/%s/items')]

        if relevant:
            items.append((sctop.getString(30811).encode('utf-8'),
                          'clear_cache'))

        select = sctop.selectDialog([i[0] for i in items],
                                    sctop.getString(30941).encode('utf-8'))

        if select == -1:
            return
        elif items[select][1] == 'rating':
            ratings = [(sctop.getString(i + 30990).encode('utf-8'), i)
                       for i in range(10, -1, -1)]
            select = sctop.selectDialog([i[0] for i in ratings], str(name))
            url = "/sync/ratings/remove"
            if select == -1:
                return
            elif ratings[select][1] != 0:
                url = "/sync/ratings"
                post[content][0]['rating'] = ratings[select][1]
            try:
                result = getTrakt(url, post=post)
                result = json.loads(result)
            except:
                return sctop.infoDialog(
                    sctop.getString(30941).encode('utf-8'),
                    heading=str(name),
                    sound=True,
                    icon='ERROR')

            if 'added' in result:
                if result['added'][content]:
                    message = sctop.getString(30987).encode(
                        'utf-8') % ratings[select][1]
                else:
                    return

            if 'deleted' in result:
                if result['deleted'][content]:
                    message = sctop.getString(30988).encode('utf-8')
                else:
                    return

        elif items[select][1] == '/users/me/lists/%s/items':
            t = sctop.getString(30938).encode('utf-8')
            k = sctop.keyboard('', t)
            k.doModal()
            new = k.getText() if k.isConfirmed() else None
            if (new == None or new == ''): return
            result = getTrakt(
                '/users/me/lists', post={
                    "name": new,
                    "privacy": "private"
                })
            sctop.cache.set('trakt.lists', None, expiration=timedelta())
            try:
                slug = json.loads(result)['ids']['slug']
            except:
                return sctop.infoDialog(
                    sctop.getString(30941).encode('utf-8'),
                    heading=str(name),
                    sound=True,
                    icon='ERROR')
            result = getTrakt(items[select][1] % slug, post=post)
        elif items[select][1] == 'clear_cache':
            ttl = timedelta()
            sctop.cache.set('trakt.lists', None, expiration=ttl)

            contents = ['shows', 'movies']
            for l in ['watchlist', 'collection']:
                for c in contents:
                    key = 'trakt.%s.%s.ids' % (l, c)
                    sctop.cache.set(key, None, expiration=ttl)

            result = getTrakt('/users/me/lists')
            lists = json.loads(result)
            for l in lists:
                for c in contents:
                    key = 'trakt.lists.%s.%s.ids' % (l['ids']['trakt'], c)
                    sctop.cache.set(key, None, expiration=ttl)

            message = sctop.getString(30812).encode('utf-8')
            name = sctop.getString(30941).encode('utf-8')
        else:
            result = getTrakt(items[select][1], post=post)
            key = items[select][2]
            if result and relevant:
                ids = sctop.cache.get(key)
                if type(ids) is list:
                    if items[select][1][-7:] == '/remove':
                        ids = [i for i in ids if i != trakt]
                    else:
                        ids.append(trakt)
                    sctop.cache.set(key, ids)

        icon = icon if not result == None else 'ERROR'

        sctop.infoDialog(message, heading=str(name), sound=True, icon=icon)
    except Exception as e:
        util.debug("[SC] trakt error: %s" % str(traceback.format_exc()))
        return