def search_query(row_id, perpetual_range_start, dir_update_listing): """Perform the research""" # Get item from database search_item = G.LOCAL_DB.get_search_item(row_id) if not search_item: ui.show_error_info('Search error', 'Item not found in the database.') return False # Update the last access data (move on top last used items) if not perpetual_range_start: G.LOCAL_DB.update_search_item_last_access(row_id) # Perform the path call menu_data = G.MAIN_MENU_ITEMS['search'] search_type = search_item['Type'] if search_type == 'text': call_args = { 'menu_data': menu_data, 'search_term': search_item['Value'], 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start } list_data, extra_data = common.make_call('get_video_list_search', call_args) elif search_type == 'audio_lang': call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'spokenAudio', 'context_id': common.convert_from_string(search_item['Parameters'], dict)['lang_code'] } list_data, extra_data = common.make_call('get_video_list_sorted_sp', call_args) elif search_type == 'subtitles_lang': call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'subtitles', 'context_id': common.convert_from_string(search_item['Parameters'], dict)['lang_code'] } list_data, extra_data = common.make_call('get_video_list_sorted_sp', call_args) elif search_type == 'genre_id': call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'genres', 'context_id': common.convert_from_string(search_item['Parameters'], dict)['genre_id'] } list_data, extra_data = common.make_call('get_video_list_sorted_sp', call_args) else: raise NotImplementedError('Search type {} not implemented'.format(search_type)) # Show the results if not list_data: ui.show_notification(common.get_local_string(30407)) return False _search_results_directory(search_item['Value'], menu_data, list_data, extra_data, dir_update_listing) return True
def get_value(self, key, default_value=None, table=db_utils.TABLE_APP_CONF, data_type=None): """ Get a single value from database :param key: The key to get the value :param default_value: When key do not exist return this default value :param table: Table map :param data_type: OPTIONAL Used to set data type conversion only when default_value is None :return: The value, with data type of default_value or if none, of data_type specified """ table_name = table[0] table_columns = table[1] query = 'SELECT {} FROM {} WHERE {} = ?'.format( table_columns[1], table_name, table_columns[0]) cur = self._execute_query(query, (key, )) result = cur.fetchone() if default_value is not None: data_type = type(default_value) elif data_type is None: data_type = str return common.convert_from_string(result[0], data_type) \ if result is not None else default_value
def get_profile_config(self, key, default_value=None, guid=None, data_type=None): """Get a value from a profile, if guid is not specified, is obtained from active profile""" if guid is None: query = ( 'SELECT Value FROM profiles_config ' 'INNER JOIN profiles ON profiles_config.Guid = profiles.Guid ' 'WHERE ' 'profiles.IsActive = 1 AND ' 'profiles_config.Name = ?') cur = self._execute_query(query, (key, )) else: query = ('SELECT Value FROM profiles_config ' 'WHERE ' 'profiles_config.Guid = ? AND ' 'profiles_config.Name = ?') cur = self._execute_query(query, (guid, key)) result = cur.fetchone() if default_value is not None: data_type = type(default_value) elif data_type is None: data_type = str return common.convert_from_string(result[0], data_type) \ if result is not None else default_value
def get_stream_continuity(self, profile_guid, videoid, default_value=None, data_type=None): """Get stream continuity value of a given id stored to current profile""" query = 'SELECT Value FROM stream_continuity WHERE ProfileGuid = ? AND VideoID = ?' cur = self._execute_query(query, (profile_guid, videoid)) result = cur.fetchone() if default_value is not None: data_type = type(default_value) elif data_type is None: data_type = str return common.convert_from_string(result[0], data_type) \ if result is not None else default_value
def get_tvshow_property(self, tvshowid, enum_vid_prop, default_value=None, data_type=None): """ Read the value of the specified property :param tvshowid: id of tvshow :param enum_vid_prop: Use a enum value of db_utils.VidLibProp :param default_value: When key do not exist return this default value :param data_type: OPTIONAL Used to set data type conversion only when default_value is None :return: the property value """ query = 'SELECT ' + enum_vid_prop.value + ' FROM video_lib_tvshows WHERE TvShowID = ?' cur = self._execute_query(query, (tvshowid,)) result = cur.fetchone() if default_value is not None: data_type = type(default_value) elif data_type is None: data_type = str return common.convert_from_string(result[0], data_type) \ if result is not None else default_value
def exec_query(row_id, search_type, search_params, search_value, perpetual_range_start, dir_update_listing, path_params=None): menu_data = deepcopy(G.MAIN_MENU_ITEMS['search']) if search_type == 'text': call_args = { 'menu_data': menu_data, 'search_term': search_value, 'pathitems': ['search', 'search', row_id] if row_id else ['search', 'search'], 'path_params': path_params, 'perpetual_range_start': perpetual_range_start } dir_items, extra_data = common.make_call('get_video_list_search', call_args) elif search_type == 'audio_lang': menu_data['query_without_reference'] = True call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'spokenAudio', 'context_id': common.convert_from_string(search_params, dict)['lang_code'] } dir_items, extra_data = common.make_call('get_video_list_sorted_sp', call_args) elif search_type == 'subtitles_lang': menu_data['query_without_reference'] = True call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'subtitles', 'context_id': common.convert_from_string(search_params, dict)['lang_code'] } dir_items, extra_data = common.make_call('get_video_list_sorted_sp', call_args) elif search_type == 'genre_id': call_args = { 'menu_data': menu_data, 'pathitems': ['search', 'search', row_id], 'perpetual_range_start': perpetual_range_start, 'context_name': 'genres', 'context_id': common.convert_from_string(search_params, dict)['genre_id'] } dir_items, extra_data = common.make_call('get_video_list_sorted_sp', call_args) else: raise NotImplementedError(f'Search type {search_type} not implemented') # Show the results if not dir_items: ui.show_notification(common.get_local_string(30407)) return False _search_results_directory(search_value, menu_data, dir_items, extra_data, dir_update_listing) return True