Esempio n. 1
0
def RecentMissingSubtitlesMenu(force=False, randomize=None):
    title = "Items with missing subtitles"
    oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True)

    running = scheduler.is_task_running("MissingSubtitles")
    task_data = scheduler.get_task_data("MissingSubtitles")
    missing_items = task_data["missing_subtitles"] if task_data else None

    if ((missing_items is None) or force) and not running:
        scheduler.dispatch_task("MissingSubtitles")
        running = True

    if not running:
        oc.add(
            DirectoryObject(key=Callback(RecentMissingSubtitlesMenu,
                                         force=True,
                                         randomize=timestamp()),
                            title=u"Get items with missing subtitles",
                            thumb=default_thumb))
    else:
        oc.add(
            DirectoryObject(key=Callback(RecentMissingSubtitlesMenu,
                                         force=False,
                                         randomize=timestamp()),
                            title=u"Updating, refresh here ...",
                            thumb=default_thumb))

    if missing_items is not None:
        for added_at, item_id, item_title, item, missing_languages in missing_items:
            oc.add(
                DirectoryObject(key=Callback(ItemDetailsMenu,
                                             title=title + " > " + item_title,
                                             item_title=item_title,
                                             rating_key=item_id),
                                title=item_title,
                                summary="Missing: %s" %
                                ", ".join(l.name for l in missing_languages),
                                thumb=get_item_thumb(item) or default_thumb))

        scheduler.clear_task_data("MissingSubtitles")

    return oc
Esempio n. 2
0
def ListAvailableSubsForItemMenu(rating_key=None,
                                 part_id=None,
                                 title=None,
                                 item_title=None,
                                 filename=None,
                                 item_type="episode",
                                 language=None,
                                 force=False,
                                 current_id=None,
                                 current_data=None,
                                 current_provider=None,
                                 current_score=None,
                                 randomize=None):
    assert rating_key, part_id

    running = scheduler.is_task_running("AvailableSubsForItem")
    search_results = get_item_task_data("AvailableSubsForItem", rating_key,
                                        language)

    if (search_results is None or force) and not running:
        scheduler.dispatch_task("AvailableSubsForItem",
                                rating_key=rating_key,
                                item_type=item_type,
                                part_id=part_id,
                                language=language)
        running = True

    oc = SubFolderObjectContainer(title2=unicode(title), replace_parent=True)
    oc.add(
        DirectoryObject(key=Callback(ItemDetailsMenu,
                                     rating_key=rating_key,
                                     item_title=item_title,
                                     title=title,
                                     randomize=timestamp()),
                        title=u"Back to: %s" % title,
                        summary=current_data,
                        thumb=default_thumb))

    metadata = get_plex_metadata(rating_key, part_id, item_type)
    scanned_parts = scan_videos(
        [metadata],
        kind="series" if item_type == "episode" else "movie",
        ignore_all=True)

    if not scanned_parts:
        Log.Error("Couldn't list available subtitles for %s", rating_key)
        return oc

    video, plex_part = scanned_parts.items()[0]

    video_display_data = [video.format] if video.format else []
    if video.release_group:
        video_display_data.append(u"by %s" % video.release_group)
    video_display_data = " ".join(video_display_data)

    current_display = (u"Current: %s (%s) " % (current_provider, current_score)
                       if current_provider else "")
    if not running:
        oc.add(
            DirectoryObject(key=Callback(ListAvailableSubsForItemMenu,
                                         rating_key=rating_key,
                                         item_title=item_title,
                                         language=language,
                                         filename=filename,
                                         part_id=part_id,
                                         title=title,
                                         current_id=current_id,
                                         force=True,
                                         current_provider=current_provider,
                                         current_score=current_score,
                                         current_data=current_data,
                                         item_type=item_type,
                                         randomize=timestamp()),
                            title=u"Search for %s subs (%s)" %
                            (get_language(language).name, video_display_data),
                            summary=u"%sFilename: %s" %
                            (current_display, filename),
                            thumb=default_thumb))
    else:
        oc.add(
            DirectoryObject(
                key=Callback(ListAvailableSubsForItemMenu,
                             rating_key=rating_key,
                             item_title=item_title,
                             language=language,
                             filename=filename,
                             current_data=current_data,
                             part_id=part_id,
                             title=title,
                             current_id=current_id,
                             item_type=item_type,
                             current_provider=current_provider,
                             current_score=current_score,
                             randomize=timestamp()),
                title=u"Searching for %s subs (%s), refresh here ..." %
                (get_language(language).name, video_display_data),
                summary=u"%sFilename: %s" % (current_display, filename),
                thumb=default_thumb))

    if not search_results:
        return oc

    for subtitle in search_results:
        oc.add(
            DirectoryObject(
                key=Callback(TriggerDownloadSubtitle,
                             rating_key=rating_key,
                             randomize=timestamp(),
                             item_title=item_title,
                             subtitle_id=str(subtitle.id),
                             language=language),
                title=u"%s: %s, score: %s" %
                ("Available" if current_id != subtitle.id else "Current",
                 subtitle.provider_name, subtitle.score),
                summary=u"Release: %s, Matches: %s" %
                (subtitle.release_info, ", ".join(subtitle.matches)),
                thumb=default_thumb))

    return oc