def browse(self, object_id, browse_flag, filter, starting_index, requested_count, sort_criteria="dc:title"): """ Browses media servers. @param object_id: object id @param browse_flag: BrowseDirectChildren or BrowseMetadata @param filter: a filter to indicate which metadata properties are to be returned. Usually "*". @param starting_index: starting index to consider the requested count @param requested_count: requested number of entries @param sort_criteria: sorting criteria @type object_id: string @type browse_flag: string @type filter: string @type starting_index: int @type requested_count: int @type sort_criteria: string @return: a list of containers and items @rtype: list """ service = self.get_cd_service() browse_response = service.Browse(ObjectID=str(object_id), BrowseFlag=browse_flag, Filter=filter, StartingIndex=starting_index, RequestedCount=requested_count, SortCriteria=sort_criteria) elt = Element.from_string(browse_response['Result']) browse_response['Result'] = elt.get_items() return browse_response
def _soap_Browse(self, *args): """ Real implementation of the soap browse. @param args: list of arguments @type args: list @return: the results of browsing @rtype: dict """ (object_id, browse_flag, filter, starting_index, requested_count, sort_criteria) = args try: starting_index = int(starting_index) requested_count = int(requested_count) last_index = None plugin = self.plugin_manager.root_plugin if browse_flag == 'BrowseDirectChildren' and \ requested_count != 0: last_index = requested_count + starting_index if ':' in object_id: namespace = object_id.split(':')[0] plugin = self.plugin_manager.plugins_instances[namespace] if not plugin: log.error('Could not get plugin associated with this'\ 'browse action on id %s' % object_id) elements = plugin.browse(object_id, browse_flag, filter, starting_index, requested_count, sort_criteria) elements.sort(cmp=compare_objects) didl = Element() total = 0 if plugin.has_browse_filter: for item in elements: didl.add_item(item) total = total + 1 else: for item in elements[starting_index: last_index]: didl.add_item(item) total = total + 1 didl_xml = didl.to_string() soap_result = {'Result': didl_xml, 'TotalMatches': len(elements), 'NumberReturned': total, 'UpdateID': self.updateID} except Exception as e: soap_result = {'Result': '', 'TotalMatches': 0, 'NumberReturned': 0, 'UpdateID': self.updateID} log.error('ContentDirectory.Browse internal problem: %s', e) return soap_result
def browse(self, object_id, browse_flag, filter, starting_index, requested_count, sort_criteria="dc:title"): """ Browses media servers. @param object_id: object id @param browse_flag: BrowseDirectChildren or BrowseMetadata @param filter: a filter to indicate which metadata properties are to be returned. Usually "*". @param starting_index: starting index to consider the requested count @param requested_count: requested number of entries @param sort_criteria: sorting criteria @type object_id: string @type browse_flag: string @type filter: string @type starting_index: int @type requested_count: int @type sort_criteria: string @return: a list of containers and items, or a fault @rtype: list """ service = self.get_cd_service() browse_response = service.Browse(ObjectID=str(object_id), BrowseFlag=browse_flag, Filter=filter, StartingIndex=starting_index, RequestedCount=requested_count, SortCriteria=sort_criteria) if 'Result' in browse_response: elt = Element.from_string(browse_response['Result']) browse_response['Result'] = elt.get_items() return browse_response
def search(self, container_id, search_criteria, filter, starting_index, requested_count, sort_criteria): """ Search items in Media Server. This method search items with search_criteria key in the container_id of current media server. @param container_id: unique identifier of the container in which to begin searching. @param search_criteria: search criteria @param filter: a filter to indicate which metadata properties are to be returned. @param starting_index: starting index to consider the requested count @param requested_count: requested number of entries under the object specified by container_id @param sort_criteria: sorting criteria @type container_id: string @type search_criteria: string @type filter: string @type starting_index: int @type requested_count: int @type sort_criteria: string @return: search result @rtype: dict """ service = self.get_cd_service() search_response = service.Search(ContainerID=container_id, SearchCriteria=search_criteria, Filter=filter, StartingIndex=starting_index, RequestedCount=requested_count, SortCriteria=sort_criteria) elt = Element.from_string(search_response['Result']) return elt.get_items()
def _soap_Browse(self, *args): """ Real implementation of the soap browse. @param args: list of arguments @type args: list @return: the results of browsing @rtype: dict """ (object_id, browse_flag, filter, starting_index, requested_count, sort_criteria) = args try: starting_index = int(starting_index) requested_count = int(requested_count) last_index = None plugin = self.plugin_manager.root_plugin if browse_flag == 'BrowseDirectChildren' and \ requested_count != 0: last_index = requested_count + starting_index if ':' in object_id: namespace = object_id.split(':')[0] plugin = self.plugin_manager.plugins_instances[namespace] if not plugin: log.error('Could not get plugin associated with this'\ 'browse action on id %s' % object_id) elements = plugin.browse(object_id, browse_flag, filter, starting_index, requested_count, sort_criteria) elements.sort(cmp=compare_objects) didl = Element() total = 0 if plugin.has_browse_filter: for item in elements: didl.add_item(item) total = total + 1 else: for item in elements[starting_index:last_index]: didl.add_item(item) total = total + 1 didl_xml = didl.to_string() soap_result = { 'Result': didl_xml, 'TotalMatches': len(elements), 'NumberReturned': total, 'UpdateID': self.updateID } except Exception, e: soap_result = { 'Result': '', 'TotalMatches': 0, 'NumberReturned': 0, 'UpdateID': self.updateID } log.error('ContentDirectory.Browse internal problem: %s', e)