Ejemplo n.º 1
0
	def matchesSearch(searchCriteria, entry):
		dlna = DLNAInterface()
		protocol = dlna.dlna_write_protocol_info(dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
					            dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
					            dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
					            dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
						    dlna.flags,
						    entry.dlnaProfile)
			
		keyword = CDSService.SEARCH_OBJECT_KEYWORD #Defaults
		derivedFrom = False
		protocolContains = False
		result = False

		if searchCriteria is CDSService.SEARCH_CLASS_MATCH_KEYWORD:
			keyword = CDSService.SEARCH_CLASS_MATCH_KEYWORD
		elif searchCriteria is CDSService.SEARCH_CLASS_DERIVED_KEYWORD:
			derivedFrom = True
			keyword = CDSService.SEARCH_CLASS_DERIVED_KEYWORD
		elif searchCriteria is CDSService.SEARCH_PROTOCOL_CONTAINS_KEYWORD:
			protocolContains = True
			keyword = CDSService.SEARCH_PROTOCOL_CONTAINS_KEYWORD
		
		if (protocolContains) and (protocol.find(keyword) >= 0):
			result = True

		andClause = searchCriteria.find(CDSService.SEARCH_AND)
		if andClause >= 0:
			result = result and CDSService.matchesSearch(searchCriteria[andClause],entry)

		return result
Ejemplo n.º 2
0
    def matchesSearch(searchCriteria, entry):
        dlna = DLNAInterface()
        protocol = dlna.dlna_write_protocol_info(
            dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
            dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
            dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
            dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'], dlna.flags,
            entry.dlnaProfile)

        keyword = CDSService.SEARCH_OBJECT_KEYWORD  #Defaults
        derivedFrom = False
        protocolContains = False
        result = False

        if searchCriteria is CDSService.SEARCH_CLASS_MATCH_KEYWORD:
            keyword = CDSService.SEARCH_CLASS_MATCH_KEYWORD
        elif searchCriteria is CDSService.SEARCH_CLASS_DERIVED_KEYWORD:
            derivedFrom = True
            keyword = CDSService.SEARCH_CLASS_DERIVED_KEYWORD
        elif searchCriteria is CDSService.SEARCH_PROTOCOL_CONTAINS_KEYWORD:
            protocolContains = True
            keyword = CDSService.SEARCH_PROTOCOL_CONTAINS_KEYWORD

        if (protocolContains) and (protocol.find(keyword) >= 0):
            result = True

        andClause = searchCriteria.find(CDSService.SEARCH_AND)
        if andClause >= 0:
            result = result and CDSService.matchesSearch(
                searchCriteria[andClause], entry)

        return result
Ejemplo n.º 3
0
	def cdsSearchDirectChildrenRecursive(buf, count, entry, _filter, searchCriteria):
		if entry.children is None:
			return -1

		resultCount = 0

		for child in entry.children:
			if (count is 0) or (resultCount < count):
				if child.children is not None: #Container
					newCount,buf = CDSService.cdsSearchDirectChildrenRecursive(buf,
							0 if count is 0 else count - resultCount,
							child, _filter, searchCriteria)
					resultCount += newCount
				else: #File
					if CDSService.matchesSearch(searchCriteria, child):
						dlna = DLNAInterface()
						protocol = dlna.dlna_write_protocol_info(dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
									            dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
									            dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
									            dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
										    dlna.flags,
										    entry.dlnaProfile)
						buf = CDSService.didlAddItem(buf, child._id,
								  child.parent._id if child.parent is not None else -1,
								  "true", dlna.dlna_profile_upnp_object_item(child.dlnaProfile),
								  child.title, protocol,
								  child.size, child.url, _filter)
						resultCount += 1
		return resultCount, buf
Ejemplo n.º 4
0
    def cdsSearchDirectChildrenRecursive(buf, count, entry, _filter,
                                         searchCriteria):
        if entry.children is None:
            return -1

        resultCount = 0

        for child in entry.children:
            if (count is 0) or (resultCount < count):
                if child.children is not None:  #Container
                    newCount, buf = CDSService.cdsSearchDirectChildrenRecursive(
                        buf, 0 if count is 0 else count - resultCount, child,
                        _filter, searchCriteria)
                    resultCount += newCount
                else:  #File
                    if CDSService.matchesSearch(searchCriteria, child):
                        dlna = DLNAInterface()
                        protocol = dlna.dlna_write_protocol_info(
                            dlna.dlna_protocol_info_type_t[
                                'DLNA_PROTOCOL_INFO_TYPE_HTTP'],
                            dlna.dlna_org_play_speed_t[
                                'DLNA_ORG_PLAY_SPEED_NORMAL'], dlna.
                            dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
                            dlna.
                            dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
                            dlna.flags, entry.dlnaProfile)
                        buf = CDSService.didlAddItem(
                            buf, child._id, child.parent._id
                            if child.parent is not None else -1, "true",
                            dlna.dlna_profile_upnp_object_item(
                                child.dlnaProfile), child.title, protocol,
                            child.size, child.url, _filter)
                        resultCount += 1
        return resultCount, buf
Ejemplo n.º 5
0
    def cdsBrowseDirectChildren(event, buf, index, count, entry, _filter):
        resultCount = 0
        if entry.children is None:  #Its a file
            return -1, buf

        buf = CDSService.didlAddHeader(buf)

        #If index = 0 and count = 0 then all children must be returned
        if (index is 0) and (count is 0):
            count = len(entry.children)

        for child in entry.children:
            if (count is 0) or (resultCount < count):
                if child.children is not None:  #Container
                    buf = CDSService.didlAddContainer(
                        buf, child._id,
                        child.parent._id if child.parent is not None else -1,
                        len(child.children), "true", None, child.title,
                        CDSService.CONTAINER_MIME)
                else:  #Item
                    manager = OneServerManager()
                    manager.log.debug("child=%s, child.children=%s" %
                                      (child, child.children))
                    manager.log.debug("child.fullpath=%s" % child.fullPath)
                    manager.log.debug("child.dlnaProfile=%s" %
                                      child.dlnaProfile.contents.mime)
                    dlna = DLNAInterface()
                    protocol = dlna.dlna_write_protocol_info(
                        dlna.dlna_protocol_info_type_t[
                            'DLNA_PROTOCOL_INFO_TYPE_HTTP'], dlna.
                        dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
                        dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
                        dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
                        dlna.flags, child.dlnaProfile)
                    buf = CDSService.didlAddItem(
                        buf, child._id,
                        child.parent._id if child.parent is not None else -1,
                        "true",
                        dlna.dlna_profile_upnp_object_item(child.dlnaProfile),
                        child.title, protocol, child.size, child.url, _filter)

                resultCount = resultCount + 1
        buf = CDSService.didlAddFooter(buf)

        Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_RESULT, buf)
        Service.upnpAddResponse(event,
                                CDSService.SERVICE_CDS_DIDL_NUM_RETURNED,
                                str(resultCount))
        Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_TOTAL_MATCH,
                                str(len(entry.children)))

        return resultCount, buf
Ejemplo n.º 6
0
	def cdsBrowseMetadata(event, buf, index, count, entry, _filter):
		if entry is None:
			return 0,buf
		
		resultCount = 0
		if entry.children is None: # File
			protocol = ""
			dlna = DLNAInterface()
			protocol = dlna.dlna_write_protocol_info(dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
							    dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
							    dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
							    dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
							    dlna.flags,
							    entry.dlnaProfile)
			
			buf = CDSService.didlAddHeader(buf)
			
			buf = CDSService.didlAddItem(buf,
					  entry._id,
					  entry.parent._id if entry.parent is not None else -1,
					  "false",
					  dlna.dlna_profile_upnp_object_item(entry.dlnaProfile),
					  entry.title,
					  protocol,
					  entry.size,
					  entry.url,
					  _filter)
			
			buf = CDSService.didlAddFooter(buf)
			for a in range(index, min(index+count, -1)):
					resultCount += 1

		else: #Directory
			buf = CDSService.didlAddHeader(buf)
			buf = CDSService.didlAddContainer(buf,
					       entry._id,
					       entry.parent._id if entry.parent is not None else -1,
					       len(entry.children),
					       "true",
					       "true",
					       entry.title,
					       CDSService.CONTAINER_MIME)
			buf = CDSService.didlAddFooter(buf)

			resultCount = 1

		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_RESULT, buf)
		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_NUM_RETURNED, "1")
		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_TOTAL_MATCH, "1")

		return resultCount,buf
Ejemplo n.º 7
0
	def cdsBrowseDirectChildren(event, buf, index, count, entry, _filter):
		resultCount = 0
		if entry.children is None: #Its a file
			return -1,buf

		buf = CDSService.didlAddHeader(buf)

		#If index = 0 and count = 0 then all children must be returned
		if (index is 0) and (count is 0):
			count = len(entry.children)
		
		for child in entry.children:
			if (count is 0) or (resultCount < count):
				if child.children is not None: #Container
					buf = CDSService.didlAddContainer(buf, child._id,
							       child.parent._id if child.parent is not None else -1,
							       len(child.children), "true", None,
							       child.title,
							       CDSService.CONTAINER_MIME)
				else: #Item 
					manager = OneServerManager()
					manager.log.debug("child=%s, child.children=%s" % (child,child.children))
					manager.log.debug("child.fullpath=%s" % child.fullPath)
					manager.log.debug("child.dlnaProfile=%s" % child.dlnaProfile.contents.mime)
					dlna = DLNAInterface()
					protocol = dlna.dlna_write_protocol_info(dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
								            dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
								            dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
								            dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
									    dlna.flags,
									    child.dlnaProfile)
					buf = CDSService.didlAddItem(buf, child._id,
							  child.parent._id if child.parent is not None else -1,
							  "true", dlna.dlna_profile_upnp_object_item(child.dlnaProfile),
							  child.title, protocol,
							  child.size, child.url, _filter)

				resultCount = resultCount + 1
		buf = CDSService.didlAddFooter(buf)

		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_RESULT, buf)
		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_NUM_RETURNED, str(resultCount))
		Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_TOTAL_MATCH, str(len(entry.children)))

		return resultCount, buf
Ejemplo n.º 8
0
    def cdsBrowseMetadata(event, buf, index, count, entry, _filter):
        if entry is None:
            return 0, buf

        resultCount = 0
        if entry.children is None:  # File
            protocol = ""
            dlna = DLNAInterface()
            protocol = dlna.dlna_write_protocol_info(
                dlna.dlna_protocol_info_type_t['DLNA_PROTOCOL_INFO_TYPE_HTTP'],
                dlna.dlna_org_play_speed_t['DLNA_ORG_PLAY_SPEED_NORMAL'],
                dlna.dlna_org_conversion_t['DLNA_ORG_CONVERSION_NONE'],
                dlna.dlna_org_operation_t['DLNA_ORG_OPERATION_RANGE'],
                dlna.flags, entry.dlnaProfile)

            buf = CDSService.didlAddHeader(buf)

            buf = CDSService.didlAddItem(
                buf, entry._id,
                entry.parent._id if entry.parent is not None else -1, "false",
                dlna.dlna_profile_upnp_object_item(entry.dlnaProfile),
                entry.title, protocol, entry.size, entry.url, _filter)

            buf = CDSService.didlAddFooter(buf)
            for a in range(index, min(index + count, -1)):
                resultCount += 1

        else:  #Directory
            buf = CDSService.didlAddHeader(buf)
            buf = CDSService.didlAddContainer(
                buf, entry._id,
                entry.parent._id if entry.parent is not None else -1,
                len(entry.children), "true", "true", entry.title,
                CDSService.CONTAINER_MIME)
            buf = CDSService.didlAddFooter(buf)

            resultCount = 1

        Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_RESULT, buf)
        Service.upnpAddResponse(event,
                                CDSService.SERVICE_CDS_DIDL_NUM_RETURNED, "1")
        Service.upnpAddResponse(event, CDSService.SERVICE_CDS_DIDL_TOTAL_MATCH,
                                "1")

        return resultCount, buf