def set_refresh_menu_state(state_or_media, media_type="movies"):
    """

    :param state_or_media: string, None, or Media argument from Agent.update()
    :param media_type: movies or series
    :return:
    """
    if not state_or_media:
        # store it in last state and remove the current
        Dict["last_refresh_state"] = Dict["current_refresh_state"]
        Dict["current_refresh_state"] = None
        return

    if isinstance(state_or_media, types.StringTypes):
        Dict["current_refresh_state"] = state_or_media
        return

    media = state_or_media
    media_id = media.id
    title = None
    if media_type == "series":
        for season in media.seasons:
            for episode in media.seasons[season].episodes:
                ep = media.seasons[season].episodes[episode]
                media_id = ep.id
                title = format_video("show", ep.title, parent_title=media.title, season=int(season), episode=int(episode))
    else:
        title = format_video("movie", media.title)
    force_refresh = intent.get("force", media_id)

    Dict["current_refresh_state"] = "%sRefreshing %s" % ("Force-" if force_refresh else "", title)
def itemDiscoverMissing(rating_key, kind="episode", internal=False, external=True, languages=[], section_blacklist=[], series_blacklist=[],
                        item_blacklist=[]):
    existing_subs = {"internal": [], "external": [], "count": 0}

    item_id = int(rating_key)
    item_container = Plex["library"].metadata(item_id)

    # don't process blacklisted sections
    if item_container.section.key in section_blacklist:
        return

    item = list(item_container)[0]

    if kind == "episode":
        item_title = format_video(item, kind, parent=item.season, parentTitle=item.show.title)
    else:
        item_title = format_video(item, kind)

    if kind == "episode" and item.show.rating_key in series_blacklist:
        Log.Info("Skipping show %s in blacklist", item.show.key)
        return
    elif item.rating_key in item_blacklist:
        Log.Info("Skipping item %s in blacklist", item.key)
        return

    video = item.media

    for part in video.parts:
        for stream in part.streams:
            if stream.stream_type == 3:
                if stream.index:
                    key = "internal"
                else:
                    key = "external"

                existing_subs[key].append(Locale.Language.Match(stream.language_code or ""))
                existing_subs["count"] = existing_subs["count"] + 1

    missing = languages
    if existing_subs["count"]:
        existing_flat = (existing_subs["internal"] if internal else []) + (existing_subs["external"] if external else [])
        languages_set = set(languages)
        if languages_set.issubset(existing_flat):
            # all subs found
            Log.Info(u"All subtitles exist for '%s'", item_title)
            return

        missing = languages_set - set(existing_flat)
        Log.Info(u"Subs still missing for '%s': %s", item_title, missing)

    if missing:
        return item_id, item_title
def set_refresh_menu_state(state_or_media, media_type="movies"):
    """

    :param state_or_media: string, None, or Media argument from Agent.update()
    :param media_type: movies or series
    :return:
    """
    if not state_or_media:
        # store it in last state and remove the current
        Dict["last_refresh_state"] = Dict["current_refresh_state"]
        Dict["current_refresh_state"] = None
        return

    if isinstance(state_or_media, types.StringTypes):
        Dict["current_refresh_state"] = state_or_media
        return

    media = state_or_media
    media_id = media.id
    title = None
    if media_type == "series":
        for season in media.seasons:
            for episode in media.seasons[season].episodes:
                ep = media.seasons[season].episodes[episode]
                media_id = ep.id
                title = format_video("show",
                                     ep.title,
                                     parent_title=media.title,
                                     season=int(season),
                                     episode=int(episode))
    else:
        title = format_video("movie", media.title)
    force_refresh = intent.get("force", media_id)

    Dict["current_refresh_state"] = "%sRefreshing %s" % (
        "Force-" if force_refresh else "", title)
Exemple #4
0
def itemDiscoverMissing(rating_key,
                        kind="episode",
                        internal=False,
                        external=True,
                        languages=[],
                        section_blacklist=[],
                        series_blacklist=[],
                        item_blacklist=[]):
    existing_subs = {"internal": [], "external": [], "count": 0}

    item_id = int(rating_key)
    item_container = Plex["library"].metadata(item_id)

    # don't process blacklisted sections
    if item_container.section.key in section_blacklist:
        return

    item = list(item_container)[0]

    if kind == "episode":
        item_title = format_video(item,
                                  kind,
                                  parent=item.season,
                                  parentTitle=item.show.title)
    else:
        item_title = format_video(item, kind)

    if kind == "episode" and item.show.rating_key in series_blacklist:
        Log.Info("Skipping show %s in blacklist", item.show.key)
        return
    elif item.rating_key in item_blacklist:
        Log.Info("Skipping item %s in blacklist", item.key)
        return

    video = item.media

    for part in video.parts:
        for stream in part.streams:
            if stream.stream_type == 3:
                if stream.index:
                    key = "internal"
                else:
                    key = "external"

                existing_subs[key].append(
                    Locale.Language.Match(stream.language_code or ""))
                existing_subs["count"] = existing_subs["count"] + 1

    missing = languages
    if existing_subs["count"]:
        existing_flat = (existing_subs["internal"] if internal else
                         []) + (existing_subs["external"] if external else [])
        languages_set = set(languages)
        if languages_set.issubset(existing_flat):
            # all subs found
            Log.Info(u"All subtitles exist for '%s'", item_title)
            return

        missing = languages_set - set(existing_flat)
        Log.Info(u"Subs still missing for '%s': %s", item_title, missing)

    if missing:
        return item_id, item_title