Пример #1
0
def kodi_get_auth():
    username = __addon__.getSetting('username')
    password = __addon__.getSetting('password')

    is_check = False
    while len(username) == 0 or len(password) == 0:
        is_check = True
        __addon__.openSettings()
        username = __addon__.getSetting('username')
        password = __addon__.getSetting('password')

    if is_check:
        if not SoapApi.check_login(username, password):
            message_error("Login or password are incorrect")
        else:
            message_ok("Auth is correct")

    return {"username": username, "password": password}
Пример #2
0
def kodi_get_auth():
    username = __addon__.getSetting('username')
    password = __addon__.getSetting('password')

    is_check = False
    while len(username) == 0 or len(password) == 0:
        is_check = True
        __addon__.openSettings()
        username = __addon__.getSetting('username')
        password = __addon__.getSetting('password')


    if is_check:
        if not SoapApi.check_login(username, password):
            message_error("Login or password are incorrect")
        else:
            message_ok("Auth is correct")

    return {
        "username": username,
        "password": password
    }
Пример #3
0
def addon_main():
    #print "Soap: sys.argv " + repr(sys.argv)
    setting_reverse = str(
        __addon__.getSetting('sorting')) == "1"  # 0 - down, 1 - up

    # 0 - all, 1 - SD, 2 - 720p
    setting_quality = lambda row: True
    if str(__addon__.getSetting('quality')) == "1":
        setting_quality = lambda row: row['quality'] == "SD"
    elif str(__addon__.getSetting('quality')) == "2":
        setting_quality = lambda row: row['quality'] == "720p"

    # 0 - all, 1 - subs, 2 - voice
    setting_translate = lambda row: True
    if str(__addon__.getSetting('translate')) == "1":
        setting_translate = lambda row: row['translate'].strip().encode(
            "utf-8") == "Субтитры"
    elif str(__addon__.getSetting('translate')) == "2":
        setting_translate = lambda row: row['translate'].strip().encode(
            "utf-8") != "Субтитры"

    s = SoapApi(os.path.join(profile, "soap4me"), auth=kodi_get_auth())

    parts = kodi_parse_uri()

    rows = list()

    if len(parts) == 1:
        rows = [("my", "Мои сериалы", "", None, True, False),
                ("all", "Все сериалы", "", None, True, False)]
        message_ok("Осталось {0} дней".format(s.get_till_days()))
    elif len(parts) == 2:
        if parts[-1] == "my":
            lines = s.list_my()
        else:
            lines = s.list_all()

        for row in lines:
            rows.append(
                (row['sid'], row['title'], row['description'].encode('utf-8'),
                 serial_img(row['sid']), True, False))

    elif 3 <= len(parts):
        lines = s.list_episodes(sid=parts[2])
        data = defaultdict(lambda: defaultdict(list))
        for row in lines:
            data[int(row['season'])][int(row['episode'])].append(row)

        # Filter by settings
        for season in data:
            for episode in data[season]:
                eps = data[season][episode]
                new_eps = [row for row in eps if setting_quality(row)]
                if len(new_eps) > 0:
                    eps = new_eps

                new_eps = [row for row in eps if setting_translate(row)]
                if len(new_eps) > 0:
                    eps = new_eps

                data[season][episode] = eps

        if len(parts) == 3:
            seasons = list(data.keys())
            seasons.sort()

            for season in seasons:
                season_dict = data[season]
                episode = season_dict.values()[0]
                row = episode[0]

                title = "Season {season}".format(season=season)

                rows.append((str(season), title, "",
                             season_img(row["season_id"]), True,
                             all(ep[0]['watched'] is not None
                                 for ep in season_dict.values())))

            if len(rows) == 1:
                rows = list()
                parts.append(str(data.keys()[0]))

        episodes_list = list()
        if len(parts) >= 4:
            season = int(parts[3])
            season_dict = data[season]
            episodes = season_dict.items()
            episodes.sort(key=lambda (episode, _): episode,
                          reverse=setting_reverse)

            map(episodes_list.extend, [ep_data for (_, ep_data) in episodes])

            for row in episodes_list:
                rows.append(
                    (row["eid"], title_episode(row), "",
                     season_img(row["season_id"]), False, row['watched']
                     is not None))

        if len(parts) >= 5:

            data = [row for row in episodes_list if row['eid'] == parts[4]]
            if len(data) >= 1:
                row = data[0]

                pos = s.time_position_get(row['eid'])

                if pos is not None:
                    dialog = xbmcgui.Dialog()
                    ret = dialog.select(
                        u'Воспроизвести',
                        [u'С {0}'.format(get_time(float(pos))), u'Сначала'])

                    if ret == -1:
                        pos = None
                    elif ret == 0:
                        pos = float(pos)
                    else:
                        pos = 0.
                else:
                    pos = 0.

                if pos is not None:
                    p = SoapPlayer()

                    def ontime_callback(watched_time):
                        s.time_position_save(row['eid'],
                                             "{0}".format(watched_time))

                    p.set_callback(
                        end_callback=lambda: s.mark_watched(row['eid']),
                        stop_callback=ontime_callback,
                        ontime_callback=ontime_callback)

                    url = s.get_video(row)
                    img = season_img(row['season_id'])
                    title = title_episode(row)

                    li = xbmcgui.ListItem(title,
                                          iconImage=img,
                                          thumbnailImage=img)
                    li.setProperty('StartOffset', str(pos))
                    p.play(url, li)
                    while p.is_soap_play() and not xbmc.abortRequested:
                        xbmc.sleep(1000)

                    return
            parts = parts[:4]

    kodi_draw_list(parts, rows)
Пример #4
0
def addon_main():
    #print "Soap: sys.argv " + repr(sys.argv)
    setting_reverse = str(__addon__.getSetting('sorting')) == "1" # 0 - down, 1 - up

    # 0 - all, 1 - SD, 2 - 720p
    setting_quality = lambda row: True
    if str(__addon__.getSetting('quality')) == "1":
        setting_quality = lambda row: row['quality'] == "SD"
    elif str(__addon__.getSetting('quality')) == "2":
        setting_quality = lambda row: row['quality'] == "720p"

    # 0 - all, 1 - subs, 2 - voice
    setting_translate = lambda row: True
    if str(__addon__.getSetting('translate')) == "1":
        setting_translate = lambda row: row['translate'].strip().encode("utf-8") == "Субтитры"
    elif str(__addon__.getSetting('translate')) == "2":
        setting_translate = lambda row: row['translate'].strip().encode("utf-8") != "Субтитры"


    s = SoapApi(os.path.join(profile, "soap4me"), auth=kodi_get_auth())

    parts = kodi_parse_uri()

    rows = list()

    if len(parts) == 1:
        rows = [
            ("my", "Мои сериалы", "", None, True, False),
            ("all", "Все сериалы", "", None, True, False)
        ]
        message_ok("Осталось {0} дней".format(s.get_till_days()))
    elif len(parts) == 2:
        if parts[-1] == "my":
            lines = s.list_my()
        else:
            lines = s.list_all()

        for row in lines:
            rows.append((
                row['sid'],
                row['title'],
                row['description'].encode('utf-8'),
                serial_img(row['sid']),
                True,
                False

            ))

    elif 3 <= len(parts):
        lines = s.list_episodes(sid=parts[2])
        data = defaultdict(lambda: defaultdict(list))
        for row in lines:
            data[int(row['season'])][int(row['episode'])].append(row)

        # Filter by settings
        for season in data:
            for episode in data[season]:
                eps = data[season][episode]
                new_eps = [row for row in eps if setting_quality(row)]
                if len(new_eps) > 0:
                    eps = new_eps

                new_eps = [row for row in eps if setting_translate(row)]
                if len(new_eps) > 0:
                    eps = new_eps

                data[season][episode] = eps

        if len(parts) == 3:
            seasons = list(data.keys())
            seasons.sort()

            for season in seasons:
                season_dict = data[season]
                episode = season_dict.values()[0]
                row = episode[0]

                title = "Season {season}".format(
                    season=season
                )

                rows.append((
                    str(season),
                    title,
                    "",
                    season_img(row["season_id"]),
                    True,
                    all(ep[0]['watched'] is not None for ep in season_dict.values())
                ))

            if len(rows) == 1:
                rows =  list()
                parts.append(str(data.keys()[0]))

        episodes_list = list()
        if len(parts) >= 4:
            season = int(parts[3])
            season_dict = data[season]
            episodes = season_dict.items()
            episodes.sort(key=lambda (episode, _): episode, reverse=setting_reverse)

            map(episodes_list.extend, [ep_data for (_, ep_data) in episodes])

            for row in episodes_list:
                rows.append((
                    row["eid"],
                    title_episode(row),
                    "",
                    season_img(row["season_id"]),
                    False,
                    row['watched'] is not None
                ))

        if len(parts) >= 5:

            data = [row for row in episodes_list if row['eid'] == parts[4]]
            if len(data) >= 1:
                row = data[0]

                pos = s.time_position_get(row['eid'])

                if pos is not None:
                    dialog = xbmcgui.Dialog()
                    ret = dialog.select(u'Воспроизвести', [u'С {0}'.format(get_time(float(pos))), u'Сначала'])

                    if ret == -1:
                        pos = None
                    elif ret == 0:
                        pos = float(pos)
                    else:
                        pos = 0.
                else:
                    pos = 0.

                if pos is not None:
                    p = SoapPlayer()

                    def ontime_callback(watched_time):
                        s.time_position_save(row['eid'], "{0}".format(watched_time))


                    p.set_callback(
                        end_callback=lambda: s.mark_watched(row['eid']),
                        stop_callback=ontime_callback,
                        ontime_callback=ontime_callback
                    )

                    url = s.get_video(row)
                    img = season_img(row['season_id'])
                    title = title_episode(row)


                    li = xbmcgui.ListItem(title, iconImage=img, thumbnailImage=img)
                    li.setProperty('StartOffset', str(pos))
                    p.play(url, li)
                    while p.is_soap_play() and not xbmc.abortRequested:
                        xbmc.sleep(1000)

                    return
            parts = parts[:4]

    kodi_draw_list(parts, rows)