def search_add(): """Perform actions to add and execute a new research""" # Ask to user the type of research search_types_desc = [SEARCH_TYPES_DESC.get(stype, 'Unknown') for stype in SEARCH_TYPES] type_index = ui.show_dlg_select(common.get_local_string(30401), search_types_desc) if type_index == -1: # Cancelled return False # If needed ask to user other info, then save the research to the database search_type = SEARCH_TYPES[type_index] row_id = None if search_type == 'text': search_term = ui.ask_for_search_term() if search_term and search_term.strip(): row_id = G.LOCAL_DB.insert_search_item(SEARCH_TYPES[type_index], search_term.strip()) elif search_type == 'audio_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_audio_languages()) elif search_type == 'subtitles_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_subtitles_languages()) elif search_type == 'genre_id': genre_id = ui.show_dlg_input_numeric(search_types_desc[type_index], mask_input=False) if genre_id: row_id = _search_add_bygenreid(SEARCH_TYPES[type_index], genre_id) else: raise NotImplementedError('Search type index {} not implemented'.format(type_index)) # Execute the research if row_id is None: return False return search_query(row_id, None, False)
def search_add(): """Perform actions to add and execute a new research""" # Ask to user the type of research search_types_desc = [SEARCH_TYPES_DESC.get(stype, 'Unknown') for stype in SEARCH_TYPES] type_index = ui.show_dlg_select(common.get_local_string(30401), search_types_desc) if type_index == -1: # Cancelled return False # If needed ask to user other info, then save the research to the database search_type = SEARCH_TYPES[type_index] row_id = None if search_type == 'text': search_term = ui.ask_for_search_term() if search_term and search_term.strip(): row_id = G.LOCAL_DB.insert_search_item(SEARCH_TYPES[type_index], search_term.strip()) elif search_type == 'audio_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_audio_languages()) elif search_type == 'subtitles_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_subtitles_languages()) elif search_type == 'genre_id': genre_id = ui.show_dlg_input_numeric(search_types_desc[type_index], mask_input=False) if genre_id: row_id = _search_add_bygenreid(SEARCH_TYPES[type_index], genre_id) else: raise NotImplementedError('Search type index {} not implemented'.format(type_index)) # Execute the research if row_id is None: return False # Redirect to "search" endpoint (otherwise causes problems with Container.Refresh used by context menus) end_of_directory(False) url = common.build_url(['search', 'search', row_id], mode=G.MODE_DIRECTORY) common.container_update(url, False) return True
def search_add(): """Perform actions to add and execute a new research""" # Ask to user the type of research search_types_desc = [ SEARCH_TYPES_DESC.get(stype, 'Unknown') for stype in SEARCH_TYPES ] type_index = ui.show_dlg_select(common.get_local_string(30401), search_types_desc) if type_index == -1: # Cancelled return False # If needed ask to user other info, then save the research to the database search_type = SEARCH_TYPES[type_index] row_id = None if search_type == 'text': search_term = ui.ask_for_search_term() if search_term and search_term.strip(): row_id = G.LOCAL_DB.insert_search_item(SEARCH_TYPES[type_index], search_term.strip()) elif search_type == 'audio_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_audio_languages()) elif search_type == 'subtitles_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_subtitles_languages()) elif search_type == 'genre_id': genre_id = ui.show_dlg_input_numeric(search_types_desc[type_index], mask_input=False) if genre_id: row_id = _search_add_bygenreid(SEARCH_TYPES[type_index], genre_id) else: raise NotImplementedError( 'Search type index {} not implemented'.format(type_index)) # Redirect to "search" endpoint (otherwise no results in JSON-RPC) # Rewrite path history using dir_update_listing + container_update # (otherwise will retrigger input dialog on Back or Container.Refresh) if row_id is not None and search_query(row_id, 0, False): url = common.build_url(['search', 'search', row_id], mode=G.MODE_DIRECTORY, params={'dir_update_listing': True}) common.container_update(url, False) return True return False