def SectionFirstLetterMenu(rating_key, title=None, base_title=None, section_title=None, ignore_options=True, section_items_key="all"): """ displays the contents of a section indexed by its first char (A-Z, 0-9...) :param ignore_options: ignored :param section_items_key: ignored :param rating_key: :param title: :param base_title: :param section_title: :return: """ from menu import FirstLetterMetadataMenu items = get_all_items(key="first_character", value=rating_key, base="library/sections") kind, deeper = get_items_info(items) title = unicode(title) oc = SubFolderObjectContainer(title2=section_title, no_cache=True, no_history=True) title = base_title + " > " + title add_incl_excl_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=InclExclMenu) oc.add(DirectoryObject( key=Callback(SectionMenu, title=_("All"), base_title=title, rating_key=rating_key, ignore_options=False), title="All" ) ) return dig_tree(oc, items, FirstLetterMetadataMenu, force_rating_key=rating_key, fill_args={"key": "key"}, pass_kwargs={"base_title": title, "display_items": deeper, "previous_rating_key": rating_key})
def SectionMenu(rating_key, title=None, base_title=None, section_title=None, ignore_options=True, section_items_key="all"): """ displays the contents of a section :param section_items_key: :param rating_key: :param title: :param base_title: :param section_title: :param ignore_options: :return: """ from menu import MetadataMenu items = get_all_items(key=section_items_key, value=rating_key, base="library/sections") kind, deeper = get_items_info(items) title = unicode(title) section_title = title title = base_title + " > " + title oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True) if ignore_options: add_incl_excl_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=InclExclMenu) return dig_tree(oc, items, MetadataMenu, pass_kwargs={"base_title": title, "display_items": deeper, "previous_item_type": "section", "previous_rating_key": rating_key})
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 SectionFirstLetterMenu(rating_key, title=None, base_title=None, section_title=None, ignore_options=True, section_items_key="all"): """ displays the contents of a section indexed by its first char (A-Z, 0-9...) :param ignore_options: ignored :param section_items_key: ignored :param rating_key: :param title: :param base_title: :param section_title: :return: """ from menu import FirstLetterMetadataMenu items = get_all_items(key="first_character", value=rating_key, base="library/sections") kind, deeper = get_items_info(items) title = unicode(title) oc = SubFolderObjectContainer(title2=section_title, no_cache=True, no_history=True) title = base_title + " > " + title add_incl_excl_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=InclExclMenu) oc.add( DirectoryObject(key=Callback(SectionMenu, title=_("All"), base_title=title, rating_key=rating_key, ignore_options=False), title="All")) return dig_tree(oc, items, FirstLetterMetadataMenu, force_rating_key=rating_key, fill_args={"key": "key"}, pass_kwargs={ "base_title": title, "display_items": deeper, "previous_rating_key": rating_key })
def SectionMenu(rating_key, title=None, base_title=None, section_title=None, ignore_options=True, section_items_key="all"): """ displays the contents of a section :param section_items_key: :param rating_key: :param title: :param base_title: :param section_title: :param ignore_options: :return: """ from menu import MetadataMenu items = get_all_items(key=section_items_key, value=rating_key, base="library/sections") kind, deeper = get_items_info(items) title = unicode(title) section_title = title title = base_title + " > " + title oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True) if ignore_options: add_incl_excl_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=InclExclMenu) return dig_tree(oc, items, MetadataMenu, pass_kwargs={ "base_title": title, "display_items": deeper, "previous_item_type": "section", "previous_rating_key": rating_key })
def MetadataMenu(rating_key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=None, message=None, header=None, randomize=None): """ displays the contents of a section based on whether it has a deeper tree or not (movies->movie (item) list; series->series list) :param rating_key: :param title: :param base_title: :param display_items: :param previous_item_type: :param previous_rating_key: :return: """ title = unicode(title) item_title = title title = base_title + " > " + title oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True, header=header, message=message, view_group="full_details") current_kind = get_item_kind_from_rating_key(rating_key) if display_items: timeout = 30 show = None # add back to series for season if current_kind == "season": timeout = 720 show = get_item(previous_rating_key) oc.add( DirectoryObject(key=Callback(MetadataMenu, rating_key=show.rating_key, title=show.title, base_title=show.section.title, previous_item_type="section", display_items=True, randomize=timestamp()), title=_(u"< Back to %s", show.title), thumb=show.thumb or default_thumb)) elif current_kind == "series": # it shouldn't take more than 6 minutes to scan all of a series' files and determine the force refresh timeout = 3600 items = get_all_items(key="children", value=rating_key, base="library/metadata") kind, deeper = get_items_info(items) dig_tree(oc, items, MetadataMenu, pass_kwargs={ "base_title": title, "display_items": deeper, "previous_item_type": kind, "previous_rating_key": rating_key }) # we don't know exactly where we are here, only add ignore option to series if current_kind in ("series", "season"): item = get_item(rating_key) sub_title = get_item_title(item) add_incl_excl_options(oc, current_kind, title=sub_title, rating_key=rating_key, callback_menu=InclExclMenu) # mass-extract embedded if current_kind == "season" and config.plex_transcoder: for lang in config.lang_list: oc.add( DirectoryObject( key=Callback(SeasonExtractEmbedded, rating_key=rating_key, language=lang, base_title=show.section.title, display_items=display_items, item_title=item_title, title=title, previous_item_type=previous_item_type, with_mods=True, previous_rating_key=previous_rating_key, randomize=timestamp()), title=_( u"Extract missing %(language)s embedded subtitles", language=display_language(lang)), summary= _("Extracts the not yet extracted embedded subtitles of all episodes for the current " "season with all configured default modifications"))) oc.add( DirectoryObject( key=Callback(SeasonExtractEmbedded, rating_key=rating_key, language=lang, base_title=show.section.title, display_items=display_items, item_title=item_title, title=title, force=True, previous_item_type=previous_item_type, with_mods=True, previous_rating_key=previous_rating_key, randomize=timestamp()), title= _(u"Extract and activate %(language)s embedded subtitles", language=display_language(lang)), summary=_( "Extracts embedded subtitles of all episodes for the current season " "with all configured default modifications"))) # add refresh oc.add( DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=title, refresh_kind=current_kind, previous_rating_key=previous_rating_key, timeout=timeout * 1000, randomize=timestamp()), title=_(u"Refresh: %s", item_title), summary=_( "Refreshes %(the_movie_series_season_episode)s, possibly searching for missing and picking up " "new subtitles on disk", the_movie_series_season_episode=_(u"the %s" % current_kind)))) oc.add( DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=title, force=True, refresh_kind=current_kind, previous_rating_key=previous_rating_key, timeout=timeout * 1000, randomize=timestamp()), title=_(u"Auto-Find subtitles: %s", item_title), summary= _("Issues a forced refresh, ignoring known subtitles and searching for new ones" ))) else: return ItemDetailsMenu(rating_key=rating_key, title=title, item_title=item_title) return oc
def ItemDetailsMenu(rating_key, title=None, base_title=None, item_title=None, randomize=None, header=None, message=None): """ displays the item details menu of an item that doesn't contain any deeper tree, such as a movie or an episode :param rating_key: :param title: :param base_title: :param item_title: :param randomize: :return: """ from interface.main import InclExclMenu title = unicode(base_title) + " > " + unicode(title) if base_title else unicode(title) item = plex_item = get_item(rating_key) current_kind = get_item_kind_from_rating_key(rating_key) timeout = 30 oc = SubFolderObjectContainer( title2=title, replace_parent=True, header=header, message=message) if not item: oc.add(DirectoryObject( key=Callback( ItemDetailsMenu, rating_key=rating_key, title=title, base_title=base_title, item_title=item_title, randomize=timestamp()), title=_(u"Item not found: %s!", item_title), summary=_("Plex didn't return any information about the item, please refresh it and come back later"), thumb=default_thumb )) return oc # add back to season for episode if current_kind == "episode": from interface.menu import MetadataMenu show = get_item(item.show.rating_key) season = get_item(item.season.rating_key) oc.add(DirectoryObject( key=Callback( MetadataMenu, rating_key=season.rating_key, title=season.title, base_title=show.title, previous_item_type="show", previous_rating_key=show.rating_key, display_items=True, randomize=timestamp()), title=_(u"< Back to %s", season.title), summary=_("Back to %s > %s", show.title, season.title), thumb=season.thumb or default_thumb )) oc.add(DirectoryObject( key=Callback( RefreshItem, rating_key=rating_key, item_title=item_title, randomize=timestamp(), timeout=timeout * 1000), title=_(u"Refresh: %s", item_title), summary=_("Refreshes %(the_movie_series_season_episode)s, possibly searching for missing and picking up " "new subtitles on disk", the_movie_series_season_episode=_(u"the %s" % current_kind)), thumb=item.thumb or default_thumb )) oc.add(DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=item_title, force=True, randomize=timestamp(), timeout=timeout * 1000), title=_(u"Force-find subtitles: %(item_title)s", item_title=item_title), summary=_("Issues a forced refresh, ignoring known subtitles and searching for new ones"), thumb=item.thumb or default_thumb )) # get stored subtitle info for item id subtitle_storage = get_subtitle_storage() stored_subs = subtitle_storage.load_or_new(item) # look for subtitles for all available media parts and all of their languages has_multiple_parts = len(plex_item.media) > 1 part_index = 0 for media in plex_item.media: for part in media.parts: filename = os.path.basename(part.file) if not os.path.exists(part.file): continue part_id = str(part.id) part_index += 1 part_index_addon = u"" part_summary_addon = u"" if has_multiple_parts: part_index_addon = _(u"File %(file_part_index)s: ", file_part_index=part_index) part_summary_addon = u"%s " % filename # iterate through all configured languages for lang in config.lang_list: # get corresponding stored subtitle data for that media part (physical media item), for language current_sub = stored_subs.get_any(part_id, lang) current_sub_id = None current_sub_provider_name = None summary = _(u"%(part_summary)sNo current subtitle in storage", part_summary=part_summary_addon) current_score = None if current_sub: current_sub_id = current_sub.id current_sub_provider_name = current_sub.provider_name current_score = current_sub.score summary = _(u"%(part_summary)sCurrent subtitle: %(provider_name)s (added: %(date_added)s, " u"%(mode)s), Language: %(language)s, Score: %(score)i, Storage: %(storage_type)s", part_summary=part_summary_addon, provider_name=_(current_sub.provider_name), date_added=df(current_sub.date_added), mode=_(current_sub.mode_verbose), language=display_language(lang), score=current_sub.score, storage_type=current_sub.storage_type) oc.add(DirectoryObject( key=Callback(SubtitleOptionsMenu, rating_key=rating_key, part_id=part_id, title=title, item_title=item_title, language=lang, language_name=display_language(lang), current_id=current_sub_id, item_type=plex_item.type, filename=filename, current_data=summary, randomize=timestamp(), current_provider=current_sub_provider_name, current_score=current_score), title=_(u"%(part_summary)sManage %(language)s subtitle", part_summary=part_index_addon, language=display_language(lang)), summary=summary )) else: oc.add(DirectoryObject( key=Callback(ListAvailableSubsForItemMenu, rating_key=rating_key, part_id=part_id, title=title, item_title=item_title, language=lang, language_name=display_language(lang), current_id=current_sub_id, item_type=plex_item.type, filename=filename, current_data=summary, randomize=timestamp(), current_provider=current_sub_provider_name, current_score=current_score), title=_(u"%(part_summary)sList %(language)s subtitles", part_summary=part_index_addon, language=display_language(lang)), summary=summary )) if config.plex_transcoder: # embedded subtitles embedded_count = 0 embedded_langs = [] for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: lang = get_language_from_stream(stream.language_code) is_forced = is_stream_forced(stream) if not lang and config.treat_und_as_first: lang = list(config.lang_list)[0] if lang: lang = Language.rebuild(lang, forced=is_forced) embedded_langs.append(lang) embedded_count += 1 if embedded_count: oc.add(DirectoryObject( key=Callback(ListEmbeddedSubsForItemMenu, rating_key=rating_key, part_id=part_id, title=title, item_type=plex_item.type, item_title=item_title, base_title=base_title, randomize=timestamp()), title=_(u"%(part_summary)sEmbedded subtitles (%(languages)s)", part_summary=part_index_addon, languages=", ".join(display_language(l) for l in list(OrderedDict.fromkeys(embedded_langs)))), summary=_(u"Extract embedded subtitle streams") )) ignore_title = item_title if current_kind == "episode": ignore_title = get_item_title(item) add_incl_excl_options(oc, "videos", title=ignore_title, rating_key=rating_key, callback_menu=InclExclMenu) subtitle_storage.destroy() return oc
def ItemDetailsMenu(rating_key, title=None, base_title=None, item_title=None, randomize=None, header=None, message=None): """ displays the item details menu of an item that doesn't contain any deeper tree, such as a movie or an episode :param rating_key: :param title: :param base_title: :param item_title: :param randomize: :return: """ from interface.main import InclExclMenu title = unicode(base_title) + " > " + unicode( title) if base_title else unicode(title) item = plex_item = get_item(rating_key) current_kind = get_item_kind_from_rating_key(rating_key) timeout = 30 oc = SubFolderObjectContainer(title2=title, replace_parent=True, header=header, message=message) if not item: oc.add( DirectoryObject( key=Callback(ItemDetailsMenu, rating_key=rating_key, title=title, base_title=base_title, item_title=item_title, randomize=timestamp()), title=_(u"Item not found: %s!", item_title), summary= _("Plex didn't return any information about the item, please refresh it and come back later" ), thumb=default_thumb)) return oc # add back to season for episode if current_kind == "episode": from interface.menu import MetadataMenu show = get_item(item.show.rating_key) season = get_item(item.season.rating_key) oc.add( DirectoryObject(key=Callback(MetadataMenu, rating_key=season.rating_key, title=season.title, base_title=show.title, previous_item_type="show", previous_rating_key=show.rating_key, display_items=True, randomize=timestamp()), title=_(u"< Back to %s", season.title), summary=_("Back to %s > %s", show.title, season.title), thumb=season.thumb or default_thumb)) oc.add( DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=item_title, randomize=timestamp(), timeout=timeout * 1000), title=_(u"Refresh: %s", item_title), summary=_( "Refreshes %(the_movie_series_season_episode)s, possibly searching for missing and picking up " "new subtitles on disk", the_movie_series_season_episode=_(u"the %s" % current_kind)), thumb=item.thumb or default_thumb)) oc.add( DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=item_title, force=True, randomize=timestamp(), timeout=timeout * 1000), title=_(u"Force-find subtitles: %(item_title)s", item_title=item_title), summary= _("Issues a forced refresh, ignoring known subtitles and searching for new ones" ), thumb=item.thumb or default_thumb)) # get stored subtitle info for item id subtitle_storage = get_subtitle_storage() stored_subs = subtitle_storage.load_or_new(item) # look for subtitles for all available media parts and all of their languages has_multiple_parts = len(plex_item.media) > 1 part_index = 0 for media in plex_item.media: for part in media.parts: filename = os.path.basename(part.file) if not os.path.exists(part.file): continue part_id = str(part.id) part_index += 1 part_index_addon = u"" part_summary_addon = u"" if has_multiple_parts: part_index_addon = _(u"File %(file_part_index)s: ", file_part_index=part_index) part_summary_addon = u"%s " % filename # iterate through all configured languages for lang in config.lang_list: # get corresponding stored subtitle data for that media part (physical media item), for language current_sub = stored_subs.get_any(part_id, lang) current_sub_id = None current_sub_provider_name = None summary = _(u"%(part_summary)sNo current subtitle in storage", part_summary=part_summary_addon) current_score = None if current_sub: current_sub_id = current_sub.id current_sub_provider_name = current_sub.provider_name current_score = current_sub.score summary = _( u"%(part_summary)sCurrent subtitle: %(provider_name)s (added: %(date_added)s, " u"%(mode)s), Language: %(language)s, Score: %(score)i, Storage: %(storage_type)s", part_summary=part_summary_addon, provider_name=_(current_sub.provider_name), date_added=df(current_sub.date_added), mode=_(current_sub.mode_verbose), language=display_language(lang), score=current_sub.score, storage_type=current_sub.storage_type) oc.add( DirectoryObject( key=Callback( SubtitleOptionsMenu, rating_key=rating_key, part_id=part_id, title=title, item_title=item_title, language=lang, language_name=display_language(lang), current_id=current_sub_id, item_type=plex_item.type, filename=filename, current_data=summary, randomize=timestamp(), current_provider=current_sub_provider_name, current_score=current_score), title=_( u"%(part_summary)sManage %(language)s subtitle", part_summary=part_index_addon, language=display_language(lang)), summary=summary)) else: oc.add( DirectoryObject( key=Callback( ListAvailableSubsForItemMenu, rating_key=rating_key, part_id=part_id, title=title, item_title=item_title, language=lang, language_name=display_language(lang), current_id=current_sub_id, item_type=plex_item.type, filename=filename, current_data=summary, randomize=timestamp(), current_provider=current_sub_provider_name, current_score=current_score), title=_( u"%(part_summary)sList %(language)s subtitles", part_summary=part_index_addon, language=display_language(lang)), summary=summary)) if config.plex_transcoder: # embedded subtitles embedded_count = 0 embedded_langs = [] for stream in part.streams: # subtitle stream if stream.stream_type == 3 and not stream.stream_key and stream.codec in TEXT_SUBTITLE_EXTS: lang = get_language_from_stream(stream.language_code) is_forced = is_stream_forced(stream) if not lang and config.treat_und_as_first: lang = list(config.lang_list)[0] if lang: lang = Language.rebuild(lang, forced=is_forced) embedded_langs.append(lang) embedded_count += 1 if embedded_count: oc.add( DirectoryObject( key=Callback(ListEmbeddedSubsForItemMenu, rating_key=rating_key, part_id=part_id, title=title, item_type=plex_item.type, item_title=item_title, base_title=base_title, randomize=timestamp()), title= _(u"%(part_summary)sEmbedded subtitles (%(languages)s)", part_summary=part_index_addon, languages=", ".join( display_language(l) for l in list( OrderedDict.fromkeys(embedded_langs)))), summary=_(u"Extract embedded subtitle streams"))) ignore_title = item_title if current_kind == "episode": ignore_title = get_item_title(item) add_incl_excl_options(oc, "videos", title=ignore_title, rating_key=rating_key, callback_menu=InclExclMenu) subtitle_storage.destroy() return oc
def MetadataMenu(rating_key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=None, message=None, header=None, randomize=None): """ displays the contents of a section based on whether it has a deeper tree or not (movies->movie (item) list; series->series list) :param rating_key: :param title: :param base_title: :param display_items: :param previous_item_type: :param previous_rating_key: :return: """ title = unicode(title) item_title = title title = base_title + " > " + title oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True, header=header, message=message, view_group="full_details") current_kind = get_item_kind_from_rating_key(rating_key) if display_items: timeout = 30 show = None # add back to series for season if current_kind == "season": timeout = 720 show = get_item(previous_rating_key) oc.add(DirectoryObject( key=Callback(MetadataMenu, rating_key=show.rating_key, title=show.title, base_title=show.section.title, previous_item_type="section", display_items=True, randomize=timestamp()), title=_(u"< Back to %s", show.title), thumb=show.thumb or default_thumb )) elif current_kind == "series": # it shouldn't take more than 6 minutes to scan all of a series' files and determine the force refresh timeout = 3600 items = get_all_items(key="children", value=rating_key, base="library/metadata") kind, deeper = get_items_info(items) dig_tree(oc, items, MetadataMenu, pass_kwargs={"base_title": title, "display_items": deeper, "previous_item_type": kind, "previous_rating_key": rating_key}) # we don't know exactly where we are here, only add ignore option to series if current_kind in ("series", "season"): item = get_item(rating_key) sub_title = get_item_title(item) add_incl_excl_options(oc, current_kind, title=sub_title, rating_key=rating_key, callback_menu=InclExclMenu) # mass-extract embedded if current_kind == "season" and config.plex_transcoder: for lang in config.lang_list: oc.add(DirectoryObject( key=Callback(SeasonExtractEmbedded, rating_key=rating_key, language=lang, base_title=show.section.title, display_items=display_items, item_title=item_title, title=title, previous_item_type=previous_item_type, with_mods=True, previous_rating_key=previous_rating_key, randomize=timestamp()), title=_(u"Extract missing %(language)s embedded subtitles", language=display_language(lang)), summary=_("Extracts the not yet extracted embedded subtitles of all episodes for the current " "season with all configured default modifications") )) oc.add(DirectoryObject( key=Callback(SeasonExtractEmbedded, rating_key=rating_key, language=lang, base_title=show.section.title, display_items=display_items, item_title=item_title, title=title, force=True, previous_item_type=previous_item_type, with_mods=True, previous_rating_key=previous_rating_key, randomize=timestamp()), title=_(u"Extract and activate %(language)s embedded subtitles", language=display_language(lang)), summary=_("Extracts embedded subtitles of all episodes for the current season " "with all configured default modifications") )) # add refresh oc.add(DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=title, refresh_kind=current_kind, previous_rating_key=previous_rating_key, timeout=timeout * 1000, randomize=timestamp()), title=_(u"Refresh: %s", item_title), summary=_("Refreshes %(the_movie_series_season_episode)s, possibly searching for missing and picking up " "new subtitles on disk", the_movie_series_season_episode=_(u"the %s" % current_kind)) )) oc.add(DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=title, force=True, refresh_kind=current_kind, previous_rating_key=previous_rating_key, timeout=timeout * 1000, randomize=timestamp()), title=_(u"Auto-Find subtitles: %s", item_title), summary=_("Issues a forced refresh, ignoring known subtitles and searching for new ones") )) else: return ItemDetailsMenu(rating_key=rating_key, title=title, item_title=item_title) return oc