def SectionFirstLetterMenu(rating_key, title=None, base_title=None, section_title=None): """ displays the contents of a section indexed by its first char (A-Z, 0-9...) :param rating_key: :param title: :param base_title: :param section_title: :return: """ items = get_all_items(key="first_character", value=rating_key, base="library/sections") kind, deeper = get_items_info(items) title = unicode(title) oc = ObjectContainer(title2=section_title, no_cache=True, no_history=True) title = base_title + " > " + title add_ignore_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=IgnoreMenu) 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 FirstLetterMetadataMenu(rating_key, key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=None): """ displays the contents of a section filtered by the first letter :param rating_key: actually is the section's key :param key: the firstLetter wanted :param title: the first letter, or # :param deeper: :return: """ title = base_title + " > " + unicode(title) oc = SubFolderObjectContainer(title2=title, no_cache=True, no_history=True) items = get_all_items(key="first_character", value=[rating_key, key], base="library/sections", flat=False) 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 }) 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_ignore_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=IgnoreMenu) 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 season_extract_embedded(rating_key, requested_language, with_mods=False, force=False): # get stored subtitle info for item id subtitle_storage = get_subtitle_storage() try: for data in get_all_items(key="children", value=rating_key, base="library/metadata"): item = get_item(data[MI_KEY]) if item: stored_subs = subtitle_storage.load_or_new(item) for part in get_all_parts(item): embedded_subs = stored_subs.get_by_provider(part.id, requested_language, "embedded") current = stored_subs.get_any(part.id, requested_language) if not embedded_subs or force: stream_data = get_embedded_subtitle_streams(part, requested_language=requested_language, get_forced=config.forced_only) if stream_data: stream = stream_data[0]["stream"] set_current = not current or force refresh = not current extract_embedded_sub(rating_key=item.rating_key, part_id=part.id, stream_index=str(stream.index), set_current=set_current, refresh=refresh, language=requested_language, with_mods=with_mods) finally: subtitle_storage.destroy()
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_ignore_options(oc, "sections", title=section_title, rating_key=rating_key, callback_menu=IgnoreMenu) return dig_tree(oc, items, MetadataMenu, pass_kwargs={"base_title": title, "display_items": deeper, "previous_item_type": "section", "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 season_extract_embedded(rating_key, requested_language, with_mods=False, force=False): # get stored subtitle info for item id subtitle_storage = get_subtitle_storage() try: for data in get_all_items(key="children", value=rating_key, base="library/metadata"): item = get_item(data[MI_KEY]) if item: stored_subs = subtitle_storage.load_or_new(item) for part in get_all_parts(item): embedded_subs = stored_subs.get_by_provider(part.id, requested_language, "embedded") current = stored_subs.get_any(part.id, requested_language) if not embedded_subs or force: stream_data = get_embedded_subtitle_streams(part, requested_language=requested_language) if stream_data: stream = stream_data[0]["stream"] set_current = not current or force refresh = not current extract_embedded_sub(rating_key=item.rating_key, part_id=part.id, stream_index=str(stream.index), set_current=set_current, refresh=refresh, language=requested_language, with_mods=with_mods, extract_mode="m") finally: subtitle_storage.destroy()
def SectionsMenu(): """ displays the menu for all sections :return: """ items = get_all_items("sections") return dig_tree(ObjectContainer(title2="Sections", no_cache=True, no_history=True), items, None, menu_determination_callback=determine_section_display, pass_kwargs={"base_title": "Sections"}, fill_args={"title": "section_title"})
def SectionsMenu(base_title="Sections", section_items_key="all", ignore_options=True): """ displays the menu for all sections :return: """ items = get_all_items("sections") return dig_tree(SubFolderObjectContainer(title2="Sections", no_cache=True, no_history=True), items, None, menu_determination_callback=determine_section_display, pass_kwargs={"base_title": base_title, "section_items_key": section_items_key, "ignore_options": ignore_options}, fill_args={"title": "section_title"})
def SectionsMenu(base_title=_("Sections"), section_items_key="all", ignore_options=True): """ displays the menu for all sections :return: """ items = get_all_items("sections") return dig_tree(SubFolderObjectContainer(title2=_("Sections"), no_cache=True, no_history=True), items, None, menu_determination_callback=determine_section_display, pass_kwargs={"base_title": base_title, "section_items_key": section_items_key, "ignore_options": ignore_options}, fill_args={"title": "section_title"})
def MetadataMenu(rating_key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=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) current_kind = get_item_kind_from_rating_key(rating_key) if display_items: 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 should_display_ignore(items, previous=previous_item_type): add_ignore_options(oc, "series", title=item_title, rating_key=rating_key, callback_menu=IgnoreMenu) timeout = 30 if current_kind == "season": timeout = 360 elif current_kind == "series": timeout = 1800 # 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 %s, possibly searching for missing and picking up new subtitles on disk" % 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 FirstLetterMetadataMenu(rating_key, key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=None): """ displays the contents of a section filtered by the first letter :param rating_key: actually is the section's key :param key: the firstLetter wanted :param title: the first letter, or # :param deeper: :return: """ title = base_title + " > " + unicode(title) oc = ObjectContainer(title2=title, no_cache=True, no_history=True) items = get_all_items(key="first_character", value=[rating_key, key], base="library/sections", flat=False) 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}) return oc
def MetadataMenu(rating_key, title=None, base_title=None, display_items=False, previous_item_type=None, previous_rating_key=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 = ObjectContainer(title2=title, no_cache=True, no_history=True) if display_items: 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 should_display_ignore(items, previous=previous_item_type): add_ignore_options(oc, "series", title=item_title, rating_key=rating_key, callback_menu=IgnoreMenu) # add refresh oc.add(DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=item_title, refresh_kind=kind, previous_rating_key=previous_rating_key, timeout=16000, randomize=timestamp()), title=u"Refresh: %s" % item_title, summary="Refreshes the item, possibly picking up new subtitles on disk" )) oc.add(DirectoryObject( key=Callback(RefreshItem, rating_key=rating_key, item_title=item_title, force=True, refresh_kind=kind, previous_rating_key=previous_rating_key, timeout=16000), title=u"Force-Refresh: %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 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_ignore_options(oc, current_kind, title=sub_title, rating_key=rating_key, callback_menu=IgnoreMenu) # 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 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