Beispiel #1
0
def IgnoreListMenu():
    ref_list = get_decision_list()
    include = ref_list.store == "include"
    list_title = _("Include list" if include else "Ignore list")
    oc = SubFolderObjectContainer(title2=list_title, replace_parent=True)
    for key in ref_list.key_order:
        values = ref_list[key]
        for value in values:
            add_incl_excl_options(oc, key, title=ref_list.get_title(key, value), rating_key=value,
                                  callback_menu=InclExclMenu)
    return oc
Beispiel #2
0
def IgnoreListMenu():
    ref_list = get_decision_list()
    include = ref_list.store == "include"
    list_title = _("Include list" if include else "Ignore list")
    oc = SubFolderObjectContainer(title2=list_title, replace_parent=True)
    for key in ref_list.key_order:
        values = ref_list[key]
        for value in values:
            add_incl_excl_options(oc,
                                  key,
                                  title=ref_list.get_title(key, value),
                                  rating_key=value,
                                  callback_menu=InclExclMenu)
    return oc
def add_incl_excl_options(oc,
                          kind,
                          callback_menu=None,
                          title=None,
                          rating_key=None,
                          add_kind=True):
    """

    :param oc: oc to add our options to
    :param kind: movie, show, episode ... - gets translated to the ignore key (sections, series, items)
    :param callback_menu: menu to inject
    :param title:
    :param rating_key:
    :return:
    """
    # try to translate kind to the ignore key
    use_kind = kind
    ref_list = get_decision_list()
    if kind not in ref_list:
        use_kind = ref_list.translate_key(kind)
    if not use_kind or use_kind not in ref_list:
        return

    in_list = rating_key in ref_list[use_kind]
    include = ref_list.store == "include"

    if include:
        t = u"Enable Sub-Zero for %(kind)s \"%(title)s\""
        if in_list:
            t = u"Disable Sub-Zero for %(kind)s \"%(title)s\""
    else:
        t = u"Ignore %(kind)s \"%(title)s\""
        if in_list:
            t = u"Un-ignore %(kind)s \"%(title)s\""

    oc.add(
        DirectoryObject(key=Callback(callback_menu,
                                     kind=use_kind,
                                     sure=False,
                                     todo="not_set",
                                     rating_key=str(rating_key),
                                     title=title),
                        title=_(
                            t,
                            kind=ref_list.verbose(kind) if add_kind else "",
                            title=unicode(title))))
Beispiel #4
0
def add_incl_excl_options(oc, kind, callback_menu=None, title=None, rating_key=None, add_kind=True):
    """

    :param oc: oc to add our options to
    :param kind: movie, show, episode ... - gets translated to the ignore key (sections, series, items)
    :param callback_menu: menu to inject
    :param title:
    :param rating_key:
    :return:
    """
    # try to translate kind to the ignore key
    use_kind = kind
    ref_list = get_decision_list()
    if kind not in ref_list:
        use_kind = ref_list.translate_key(kind)
    if not use_kind or use_kind not in ref_list:
        return

    in_list = rating_key in ref_list[use_kind]
    include = ref_list.store == "include"

    if include:
        t = u"Enable Sub-Zero for %(kind)s \"%(title)s\""
        if in_list:
            t = u"Disable Sub-Zero for %(kind)s \"%(title)s\""
    else:
        t = u"Ignore %(kind)s \"%(title)s\""
        if in_list:
            t = u"Un-ignore %(kind)s \"%(title)s\""

    oc.add(DirectoryObject(
        key=Callback(callback_menu, kind=use_kind, sure=False, todo="not_set", rating_key=str(rating_key), title=title),
        title=_(t,
                kind=ref_list.verbose(kind) if add_kind else "",
                title=unicode(title))
    )
    )
Beispiel #5
0
def InclExclMenu(kind, rating_key, title=None, sure=False, todo="not_set"):
    """
    displays the ignore options for a menu
    :param kind:
    :param rating_key:
    :param title:
    :param sure:
    :param todo:
    :return:
    """
    ref_list = get_decision_list()
    include = ref_list.store == "include"
    list_str_ref = "include" if include else "ignore"
    in_list = rating_key in ref_list[kind]

    if include:
        # shortcut
        sure = True
        todo = "add" if not in_list else "remove"

    if not sure:
        t = u"Add %(kind)s %(title)s to the ignore list"
        if in_list:
            t = u"Remove %(kind)s %(title)s from the ignore list"
        oc = SubFolderObjectContainer(no_history=True, replace_parent=True,
                                      title1=_(t,
                                               kind=ref_list.verbose(kind),
                                               title=title
                                               ),
                                      title2=_("Are you sure?"))
        oc.add(DirectoryObject(
            key=Callback(InclExclMenu, kind=kind, rating_key=rating_key, title=title, sure=True,
                         todo="add" if not in_list else "remove"),
            title=pad_title(_("Are you sure?")),
        ))
        return oc

    rel = ref_list[kind]
    dont_change = False
    state = None
    if todo == "remove":
        if not in_list:
            dont_change = True
        else:
            rel.remove(rating_key)
            Log.Info("Removed %s (%s) from the %s list", title, rating_key, list_str_ref)
            ref_list.remove_title(kind, rating_key)
            ref_list.save()
    elif todo == "add":
        if in_list:
            dont_change = True
        else:
            rel.append(rating_key)
            Log.Info("Added %s (%s) to the %s list", title, rating_key, list_str_ref)
            ref_list.add_title(kind, rating_key, title)
            ref_list.save()
    else:
        dont_change = True

    if dont_change:
        return fatality(force_title=" ", header=_("Didn't change the %(incl_excl_list_name)s",
                                                  incl_excl_list_name=_(list_str_ref)), no_history=True)

    if include:
        t = "%(title)s added to the include list"
        if todo == "remove":
            t = "%(title)s removed from the include list"
    else:
        t = "%(title)s added to the ignore list"
        if todo == "remove":
            t = "%(title)s removed from the ignore list"
    return fatality(force_title=" ", header=_(t, title=title,), no_history=True)
Beispiel #6
0
def fatality(randomize=None, force_title=None, header=None, message=None, only_refresh=False, no_history=False,
             replace_parent=False):
    """
    subzero main menu
    """
    from interface.advanced import PinMenu, ClearPin, AdvancedMenu
    from interface.menu import RefreshMissing, IgnoreListMenu, HistoryMenu

    title = config.full_version  # force_title if force_title is not None else config.full_version
    oc = ObjectContainer(title1=title, title2=title, header=unicode(header) if header else title, message=message,
                         no_history=no_history,
                         replace_parent=replace_parent, no_cache=True)

    # always re-check permissions
    config.refresh_permissions_status()

    # always re-check enabled sections
    config.refresh_enabled_sections()

    if config.lock_menu and not config.pin_correct:
        oc.add(DirectoryObject(
            key=Callback(PinMenu, randomize=timestamp()),
            title=pad_title(_("Enter PIN")),
            summary=_("The owner has restricted the access to this menu. Please enter the correct pin"),
        ))
        return oc

    if not config.permissions_ok and config.missing_permissions:
        if not isinstance(config.missing_permissions, list):
            oc.add(DirectoryObject(
                key=Callback(fatality, randomize=timestamp()),
                title=pad_title(_("Insufficient permissions")),
                summary=config.missing_permissions,
            ))
        else:
            for title, path in config.missing_permissions:
                oc.add(DirectoryObject(
                    key=Callback(fatality, randomize=timestamp()),
                    title=pad_title(_("Insufficient permissions")),
                    summary=_("Insufficient permissions on library %(title)s, folder: %(path)s",
                              title=title,
                              path=path),
                ))
        return oc

    if not config.enabled_sections:
        oc.add(DirectoryObject(
            key=Callback(fatality, randomize=timestamp()),
            title=pad_title(_("I'm not enabled!")),
            summary=_("Please enable me for some of your libraries in your server settings; currently I do nothing"),
        ))
        return oc

    if not only_refresh:
        if Dict["current_refresh_state"]:
            oc.add(DirectoryObject(
                key=Callback(fatality, force_title=" ", randomize=timestamp()),
                title=pad_title(_("Working ... refresh here")),
                summary=_("Current state: %s; Last state: %s",
                    (Dict["current_refresh_state"] or _("Idle")) if "current_refresh_state" in Dict else _("Idle"),
                    (Dict["last_refresh_state"] or _("None")) if "last_refresh_state" in Dict else _("None")
                )
            ))

        oc.add(DirectoryObject(
            key=Callback(OnDeckMenu),
            title=_("On-deck items"),
            summary=_("Shows the current on deck items and allows you to individually (force-) refresh their metadata/subtitles."),
            thumb=R("icon-ondeck.jpg")
        ))
        if "last_played_items" in Dict and Dict["last_played_items"]:
            oc.add(DirectoryObject(
                key=Callback(RecentlyPlayedMenu),
                title=pad_title(_("Recently played items")),
                summary=_("Shows the %s recently played items and allows you to individually (force-) refresh their metadata/subtitles.", config.store_recently_played_amount),
                thumb=R("icon-played.jpg")
            ))
        oc.add(DirectoryObject(
            key=Callback(RecentlyAddedMenu),
            title=_("Recently-added items"),
            summary=_("Shows the recently added items per section."),
            thumb=R("icon-added.jpg")
        ))
        oc.add(DirectoryObject(
            key=Callback(RecentMissingSubtitlesMenu, randomize=timestamp()),
            title=_("Show recently added items with missing subtitles"),
            summary=_("Lists items with missing subtitles. Click on \"Find recent items with missing subs\" to update list"),
            thumb=R("icon-missing.jpg")
        ))
        oc.add(DirectoryObject(
            key=Callback(SectionsMenu),
            title=_("Browse all items"),
            summary=_("Go through your whole library and manage your ignore list. You can also (force-) refresh the metadata/subtitles of individual items."),
            thumb=R("icon-browse.jpg")
        ))

        task_name = "SearchAllRecentlyAddedMissing"
        task = scheduler.task(task_name)

        if task.ready_for_display:
            task_state = _("Running: %(items_done)s/%(items_searching)s (%(percentage)s%%)",
                           items_done=task.items_done,
                           items_searching=task.items_searching,
                           percentage=task.percentage)
        else:
            lr = scheduler.last_run(task_name)
            nr = scheduler.next_run(task_name)
            task_state = _("Last run: %s; Next scheduled run: %s; Last runtime: %s",
                df(scheduler.last_run(task_name)) if lr else "never",
                df(scheduler.next_run(task_name)) if nr else "never",
                str(task.last_run_time).split(".")[0])

        oc.add(DirectoryObject(
            key=Callback(RefreshMissing, randomize=timestamp()),
            title=_("Search for missing subtitles (in recently-added items, max-age: %s)", Prefs[
                "scheduler.item_is_recent_age"]),
            summary=_("Automatically run periodically by the scheduler, if configured. %s", task_state),
            thumb=R("icon-search.jpg")
        ))

        ref_list = get_decision_list()
        incl_excl_ref = _("include list") if ref_list.store == "include" else _("ignore list")

        oc.add(DirectoryObject(
            key=Callback(IgnoreListMenu),
            title=_("Display %(incl_excl_list_name)s (%(count)d)",
                    incl_excl_list_name=incl_excl_ref, count=len(ref_list)),
            summary=_("Show the current %(incl_excl_list_name)s (mainly used for the automatic tasks)",
                      incl_excl_list_name=incl_excl_ref),
            thumb=R("icon-ignore.jpg")
        ))

        oc.add(DirectoryObject(
            key=Callback(HistoryMenu),
            title=_("History"),
            summary=_("Show the last %i downloaded subtitles", int(Prefs["history_size"])),
            thumb=R("icon-history.jpg")
        ))

    oc.add(DirectoryObject(
        key=Callback(fatality, force_title=" ", randomize=timestamp()),
        title=pad_title(_("Refresh")),
        summary=_("Current state: %s; Last state: %s",
            (Dict["current_refresh_state"] or _("Idle")) if "current_refresh_state" in Dict else _("Idle"),
            (Dict["last_refresh_state"] or _("None")) if "last_refresh_state" in Dict else _("None")
        ),
        thumb=R("icon-refresh.jpg")
    ))

    # add re-lock after pin unlock
    if config.pin:
        oc.add(DirectoryObject(
            key=Callback(ClearPin, randomize=timestamp()),
            title=pad_title(_("Re-lock menu(s)")),
            summary=_("Enabled the PIN again for menu(s)")
        ))

    if not only_refresh:
        if "provider_throttle" in Dict and Dict["provider_throttle"].keys():
            summary_data = []
            for provider, data in Dict["provider_throttle"].iteritems():
                reason, until, desc = data
                summary_data.append(unicode(_("%(throttled_provider)s until %(until_date)s (%(reason)s)",
                                              throttled_provider=provider,
                                              until_date=until.strftime("%y/%m/%d %H:%M"),
                                              reason=reason)))

            oc.add(DirectoryObject(
                key=Callback(fatality, force_title=" ", randomize=timestamp()),
                title=pad_title(_("Throttled providers: %s", ", ".join(Dict["provider_throttle"].keys()))),
                summary=", ".join(summary_data),
                thumb=R("icon-throttled.jpg")
            ))

        oc.add(DirectoryObject(
            key=Callback(AdvancedMenu),
            title=pad_title(_("Advanced functions")),
            summary=_("Use at your own risk"),
            thumb=R("icon-advanced.jpg")
        ))

    return oc
Beispiel #7
0
def InclExclMenu(kind, rating_key, title=None, sure=False, todo="not_set"):
    """
    displays the ignore options for a menu
    :param kind:
    :param rating_key:
    :param title:
    :param sure:
    :param todo:
    :return:
    """
    ref_list = get_decision_list()
    include = ref_list.store == "include"
    list_str_ref = "include" if include else "ignore"
    in_list = rating_key in ref_list[kind]

    if include:
        # shortcut
        sure = True
        todo = "add" if not in_list else "remove"

    if not sure:
        t = u"Add %(kind)s %(title)s to the ignore list"
        if in_list:
            t = u"Remove %(kind)s %(title)s from the ignore list"
        oc = SubFolderObjectContainer(no_history=True,
                                      replace_parent=True,
                                      title1=_(t,
                                               kind=ref_list.verbose(kind),
                                               title=title),
                                      title2=_("Are you sure?"))
        oc.add(
            DirectoryObject(
                key=Callback(InclExclMenu,
                             kind=kind,
                             rating_key=rating_key,
                             title=title,
                             sure=True,
                             todo="add" if not in_list else "remove"),
                title=pad_title(_("Are you sure?")),
            ))
        return oc

    rel = ref_list[kind]
    dont_change = False
    state = None
    if todo == "remove":
        if not in_list:
            dont_change = True
        else:
            rel.remove(rating_key)
            Log.Info("Removed %s (%s) from the %s list", title, rating_key,
                     list_str_ref)
            ref_list.remove_title(kind, rating_key)
            ref_list.save()
    elif todo == "add":
        if in_list:
            dont_change = True
        else:
            rel.append(rating_key)
            Log.Info("Added %s (%s) to the %s list", title, rating_key,
                     list_str_ref)
            ref_list.add_title(kind, rating_key, title)
            ref_list.save()
    else:
        dont_change = True

    if dont_change:
        return fatality(force_title=" ",
                        header=_("Didn't change the %(incl_excl_list_name)s",
                                 incl_excl_list_name=_(list_str_ref)),
                        no_history=True)

    if include:
        t = "%(title)s added to the include list"
        if todo == "remove":
            t = "%(title)s removed from the include list"
    else:
        t = "%(title)s added to the ignore list"
        if todo == "remove":
            t = "%(title)s removed from the ignore list"
    return fatality(force_title=" ",
                    header=_(
                        t,
                        title=title,
                    ),
                    no_history=True)
Beispiel #8
0
def fatality(randomize=None,
             force_title=None,
             header=None,
             message=None,
             only_refresh=False,
             no_history=False,
             replace_parent=False):
    """
    subzero main menu
    """
    from interface.advanced import PinMenu, ClearPin, AdvancedMenu
    from interface.menu import RefreshMissing, IgnoreListMenu, HistoryMenu

    title = config.full_version  # force_title if force_title is not None else config.full_version
    oc = ObjectContainer(title1=title,
                         title2=title,
                         header=unicode(header) if header else title,
                         message=message,
                         no_history=no_history,
                         replace_parent=replace_parent,
                         no_cache=True)

    # always re-check permissions
    config.refresh_permissions_status()

    # always re-check enabled sections
    config.refresh_enabled_sections()

    if config.lock_menu and not config.pin_correct:
        oc.add(
            DirectoryObject(
                key=Callback(PinMenu, randomize=timestamp()),
                title=pad_title(_("Enter PIN")),
                summary=
                _("The owner has restricted the access to this menu. Please enter the correct pin"
                  ),
            ))
        return oc

    if not config.permissions_ok and config.missing_permissions:
        if not isinstance(config.missing_permissions, list):
            oc.add(
                DirectoryObject(
                    key=Callback(fatality, randomize=timestamp()),
                    title=pad_title(_("Insufficient permissions")),
                    summary=config.missing_permissions,
                ))
        else:
            for title, path in config.missing_permissions:
                oc.add(
                    DirectoryObject(
                        key=Callback(fatality, randomize=timestamp()),
                        title=pad_title(_("Insufficient permissions")),
                        summary=
                        _("Insufficient permissions on library %(title)s, folder: %(path)s",
                          title=title,
                          path=path),
                    ))
        return oc

    if not config.enabled_sections:
        oc.add(
            DirectoryObject(
                key=Callback(fatality, randomize=timestamp()),
                title=pad_title(_("I'm not enabled!")),
                summary=
                _("Please enable me for some of your libraries in your server settings; currently I do nothing"
                  ),
            ))
        return oc

    if not only_refresh:
        if Dict["current_refresh_state"]:
            oc.add(
                DirectoryObject(
                    key=Callback(fatality,
                                 force_title=" ",
                                 randomize=timestamp()),
                    title=pad_title(_("Working ... refresh here")),
                    summary=_("Current state: %s; Last state: %s",
                              (Dict["current_refresh_state"] or _("Idle")) if
                              "current_refresh_state" in Dict else _("Idle"),
                              (Dict["last_refresh_state"] or _("None"))
                              if "last_refresh_state" in Dict else _("None"))))

        oc.add(
            DirectoryObject(
                key=Callback(OnDeckMenu),
                title=_("On-deck items"),
                summary=
                _("Shows the current on deck items and allows you to individually (force-) refresh their metadata/subtitles."
                  ),
                thumb=R("icon-ondeck.jpg")))
        if "last_played_items" in Dict and Dict["last_played_items"]:
            oc.add(
                DirectoryObject(
                    key=Callback(RecentlyPlayedMenu),
                    title=pad_title(_("Recently played items")),
                    summary=_(
                        "Shows the %s recently played items and allows you to individually (force-) refresh their metadata/subtitles.",
                        config.store_recently_played_amount),
                    thumb=R("icon-played.jpg")))
        oc.add(
            DirectoryObject(
                key=Callback(RecentlyAddedMenu),
                title=_("Recently-added items"),
                summary=_("Shows the recently added items per section."),
                thumb=R("icon-added.jpg")))
        oc.add(
            DirectoryObject(
                key=Callback(RecentMissingSubtitlesMenu,
                             randomize=timestamp()),
                title=_("Show recently added items with missing subtitles"),
                summary=
                _("Lists items with missing subtitles. Click on \"Find recent items with missing subs\" to update list"
                  ),
                thumb=R("icon-missing.jpg")))
        oc.add(
            DirectoryObject(
                key=Callback(SectionsMenu),
                title=_("Browse all items"),
                summary=
                _("Go through your whole library and manage your ignore list. You can also (force-) refresh the metadata/subtitles of individual items."
                  ),
                thumb=R("icon-browse.jpg")))

        task_name = "SearchAllRecentlyAddedMissing"
        task = scheduler.task(task_name)

        if task.ready_for_display:
            task_state = _(
                "Running: %(items_done)s/%(items_searching)s (%(percentage)s%%)",
                items_done=task.items_done,
                items_searching=task.items_searching,
                percentage=task.percentage)
        else:
            lr = scheduler.last_run(task_name)
            nr = scheduler.next_run(task_name)
            task_state = _(
                "Last run: %s; Next scheduled run: %s; Last runtime: %s",
                df(scheduler.last_run(task_name)) if lr else "never",
                df(scheduler.next_run(task_name)) if nr else "never",
                str(task.last_run_time).split(".")[0])

        oc.add(
            DirectoryObject(
                key=Callback(RefreshMissing, randomize=timestamp()),
                title=_(
                    "Search for missing subtitles (in recently-added items, max-age: %s)",
                    Prefs["scheduler.item_is_recent_age"]),
                summary=_(
                    "Automatically run periodically by the scheduler, if configured. %s",
                    task_state),
                thumb=R("icon-search.jpg")))

        ref_list = get_decision_list()
        incl_excl_ref = _(
            "include list") if ref_list.store == "include" else _(
                "ignore list")

        oc.add(
            DirectoryObject(
                key=Callback(IgnoreListMenu),
                title=_("Display %(incl_excl_list_name)s (%(count)d)",
                        incl_excl_list_name=incl_excl_ref,
                        count=len(ref_list)),
                summary=
                _("Show the current %(incl_excl_list_name)s (mainly used for the automatic tasks)",
                  incl_excl_list_name=incl_excl_ref),
                thumb=R("icon-ignore.jpg")))

        oc.add(
            DirectoryObject(key=Callback(HistoryMenu),
                            title=_("History"),
                            summary=_("Show the last %i downloaded subtitles",
                                      int(Prefs["history_size"])),
                            thumb=R("icon-history.jpg")))

    oc.add(
        DirectoryObject(
            key=Callback(fatality, force_title=" ", randomize=timestamp()),
            title=pad_title(_("Refresh")),
            summary=_("Current state: %s; Last state: %s",
                      (Dict["current_refresh_state"] or _("Idle"))
                      if "current_refresh_state" in Dict else _("Idle"),
                      (Dict["last_refresh_state"] or _("None"))
                      if "last_refresh_state" in Dict else _("None")),
            thumb=R("icon-refresh.jpg")))

    # add re-lock after pin unlock
    if config.pin:
        oc.add(
            DirectoryObject(key=Callback(ClearPin, randomize=timestamp()),
                            title=pad_title(_("Re-lock menu(s)")),
                            summary=_("Enabled the PIN again for menu(s)")))

    if not only_refresh:
        if "provider_throttle" in Dict and Dict["provider_throttle"].keys():
            summary_data = []
            for provider, data in Dict["provider_throttle"].iteritems():
                reason, until, desc = data
                summary_data.append(
                    unicode(
                        _("%(throttled_provider)s until %(until_date)s (%(reason)s)",
                          throttled_provider=provider,
                          until_date=until.strftime("%y/%m/%d %H:%M"),
                          reason=reason)))

            oc.add(
                DirectoryObject(
                    key=Callback(fatality,
                                 force_title=" ",
                                 randomize=timestamp()),
                    title=pad_title(
                        _("Throttled providers: %s",
                          ", ".join(Dict["provider_throttle"].keys()))),
                    summary=", ".join(summary_data),
                    thumb=R("icon-throttled.jpg")))

        oc.add(
            DirectoryObject(key=Callback(AdvancedMenu),
                            title=pad_title(_("Advanced functions")),
                            summary=_("Use at your own risk"),
                            thumb=R("icon-advanced.jpg")))

    return oc