def toElement(self, **kwargs): root = ET.Element(self.elementName) #if self.id == 1000: # root.attrib['id'] = '0' # ET.SubElement(root, 'dc:title').text = 'root' #else: # root.attrib['id'] = str(self.id) # ET.SubElement(root, 'dc:title').text = self.title root.attrib['id'] = str(self.id) ET.SubElement(root, qname('title', DC_NS)).text = self.title #if self.title != None: # ET.SubElement(root, 'dc:title').text = self.title #else: # ET.SubElement(root, 'dc:title').text = 'root' root.attrib['parentID'] = str(self.parentID) if (kwargs.get('upnp_client', '') != 'XBox'): if self.refID: root.attrib['refID'] = str(self.refID) if kwargs.get('requested_id', None): if kwargs.get('requested_id') == '0': t = root.find(qname('title', DC_NS)) t.text = 'root' #if kwargs.get('requested_id') != '0' and kwargs.get('requested_id') != root.attrib['id']: if kwargs.get('requested_id') != root.attrib['id']: if (kwargs.get('upnp_client', '') != 'XBox'): root.attrib['refID'] = root.attrib['id'] r_id = kwargs.get('requested_id') root.attrib['id'] = r_id r_id = r_id.split('@', 1) try: root.attrib['parentID'] = r_id[1] except IndexError: pass if (kwargs.get('upnp_client', '') != 'XBox'): self.info("Changing ID from %r to %r, with parentID %r", root.attrib['refID'], root.attrib['id'], root.attrib['parentID']) else: self.info("Changing ID from %r to %r, with parentID %r", self.id, root.attrib['id'], root.attrib['parentID']) elif kwargs.get('parent_container', None): if (kwargs.get('parent_container') != '0' and kwargs.get('parent_container') != root.attrib['parentID']): if (kwargs.get('upnp_client', '') != 'XBox'): root.attrib['refID'] = root.attrib['id'] root.attrib['id'] = '@'.join( (root.attrib['id'], kwargs.get('parent_container'))) root.attrib['parentID'] = kwargs.get('parent_container') if (kwargs.get('upnp_client', '') != 'XBox'): self.info( "Changing ID from %r to %r, with parentID from %r to %r", root.attrib['refID'], root.attrib['id'], self.parentID, root.attrib['parentID']) else: self.info( "Changing ID from %r to %r, with parentID from %r to %r", self.id, root.attrib['id'], self.parentID, root.attrib['parentID']) ET.SubElement(root, qname('class', UPNP_NS)).text = self.upnp_class if kwargs.get('upnp_client', '') == 'XBox': u = root.find(qname('class', UPNP_NS)) if (kwargs.get('parent_container', None) != None and u.text.startswith('object.container')): if kwargs.get('parent_container') in ('14', '15', '16'): u.text = 'object.container.storageFolder' if self.upnp_class == 'object.container': u.text = 'object.container.storageFolder' if self.restricted: root.attrib['restricted'] = '1' else: root.attrib['restricted'] = '0' if self.creator is not None: ET.SubElement(root, qname('creator', DC_NS)).text = self.creator if self.writeStatus is not None: ET.SubElement(root, qname('writeStatus', UPNP_NS)).text = self.writeStatus if self.date is not None: if isinstance(self.date, datetime): ET.SubElement(root, qname('date', DC_NS)).text = self.date.isoformat() else: ET.SubElement(root, qname('date', DC_NS)).text = self.date else: ET.SubElement(root, qname('date', DC_NS)).text = utils.datefaker().isoformat() if self.albumArtURI is not None: e = ET.SubElement(root, qname('albumArtURI', UPNP_NS)) e.text = self.albumArtURI e.attrib['xmlns:dlna'] = 'urn:schemas-dlna-org:metadata-1-0' e.attrib['dlna:profileID'] = 'JPEG_TN' if self.artist is not None: ET.SubElement(root, qname('artist', UPNP_NS)).text = self.artist if self.genre is not None: ET.SubElement(root, qname('genre', UPNP_NS)).text = self.genre if self.genres is not None: for genre in self.genres: ET.SubElement(root, qname('genre', UPNP_NS)).text = genre if self.originalTrackNumber is not None: ET.SubElement(root, qname('originalTrackNumber', UPNP_NS)).text = str(self.originalTrackNumber) if self.description is not None: ET.SubElement(root, qname('description', DC_NS)).text = self.description if self.longDescription is not None: ET.SubElement(root, qname('longDescription', UPNP_NS)).text = self.longDescription if self.server_uuid is not None: ET.SubElement(root, qname('server_uuid', UPNP_NS)).text = self.server_uuid return root
def toElement(self,**kwargs): root = ET.Element(self.elementName) #if self.id == 1000: # root.attrib['id'] = '0' # ET.SubElement(root, 'dc:title').text = 'root' #else: # root.attrib['id'] = str(self.id) # ET.SubElement(root, 'dc:title').text = self.title root.attrib['id'] = str(self.id) ET.SubElement(root, qname('title',DC_NS)).text = self.title #if self.title != None: # ET.SubElement(root, 'dc:title').text = self.title #else: # ET.SubElement(root, 'dc:title').text = 'root' root.attrib['parentID'] = str(self.parentID) if(kwargs.get('upnp_client','') != 'XBox'): if self.refID: root.attrib['refID'] = str(self.refID) if kwargs.get('requested_id',None): if kwargs.get('requested_id') == '0': t = root.find(qname('title',DC_NS)) t.text = 'root' #if kwargs.get('requested_id') != '0' and kwargs.get('requested_id') != root.attrib['id']: if kwargs.get('requested_id') != root.attrib['id']: if(kwargs.get('upnp_client','') != 'XBox'): root.attrib['refID'] = root.attrib['id'] r_id = kwargs.get('requested_id') root.attrib['id'] = r_id r_id = r_id.split('@',1) try: root.attrib['parentID'] = r_id[1] except IndexError: pass if(kwargs.get('upnp_client','') != 'XBox'): self.info("Changing ID from %r to %r, with parentID %r", root.attrib['refID'], root.attrib['id'], root.attrib['parentID']) else: self.info("Changing ID from %r to %r, with parentID %r", self.id, root.attrib['id'], root.attrib['parentID']) elif kwargs.get('parent_container',None): if(kwargs.get('parent_container') != '0' and kwargs.get('parent_container') != root.attrib['parentID']): if(kwargs.get('upnp_client','') != 'XBox'): root.attrib['refID'] = root.attrib['id'] root.attrib['id'] = '@'.join((root.attrib['id'],kwargs.get('parent_container'))) root.attrib['parentID'] = kwargs.get('parent_container') if(kwargs.get('upnp_client','') != 'XBox'): self.info("Changing ID from %r to %r, with parentID from %r to %r", root.attrib['refID'], root.attrib['id'], self.parentID, root.attrib['parentID']) else: self.info("Changing ID from %r to %r, with parentID from %r to %r", self.id, root.attrib['id'], self.parentID, root.attrib['parentID']) ET.SubElement(root, qname('class',UPNP_NS)).text = self.upnp_class if kwargs.get('upnp_client','') == 'XBox': u = root.find(qname('class',UPNP_NS)) if(kwargs.get('parent_container',None) != None and u.text.startswith('object.container')): if kwargs.get('parent_container') in ('14','15','16'): u.text = 'object.container.storageFolder' if self.upnp_class == 'object.container': u.text = 'object.container.storageFolder' if self.restricted: root.attrib['restricted'] = '1' else: root.attrib['restricted'] = '0' if self.creator is not None: ET.SubElement(root, qname('creator',DC_NS)).text = self.creator if self.writeStatus is not None: ET.SubElement(root, qname('writeStatus',UPNP_NS)).text = self.writeStatus if self.date is not None: if isinstance(self.date, datetime): ET.SubElement(root, qname('date',DC_NS)).text = self.date.isoformat() else: ET.SubElement(root, qname('date',DC_NS)).text = self.date else: ET.SubElement(root, qname('date',DC_NS)).text = utils.datefaker().isoformat() if self.albumArtURI is not None: e = ET.SubElement(root, qname('albumArtURI',UPNP_NS)) e.text = self.albumArtURI e.attrib['xmlns:dlna'] = 'urn:schemas-dlna-org:metadata-1-0' e.attrib['dlna:profileID'] = 'JPEG_TN' if self.artist is not None: ET.SubElement(root, qname('artist',UPNP_NS)).text = self.artist if self.genre is not None: ET.SubElement(root, qname('genre',UPNP_NS)).text = self.genre if self.genres is not None: for genre in self.genres: ET.SubElement(root, qname('genre',UPNP_NS)).text = genre if self.originalTrackNumber is not None: ET.SubElement(root, qname('originalTrackNumber',UPNP_NS)).text = str(self.originalTrackNumber) if self.description is not None: ET.SubElement(root, qname('description',DC_NS)).text = self.description if self.longDescription is not None: ET.SubElement(root, qname('longDescription',UPNP_NS)).text = self.longDescription if self.server_uuid is not None: ET.SubElement(root, qname('server_uuid',UPNP_NS)).text = self.server_uuid return root
def toElement(self,**kwargs): root = ET.Element(self.elementName) if self.id == 1000: root.attrib['id'] = '0' ET.SubElement(root, 'dc:title').text = 'root' else: root.attrib['id'] = str(self.id) ET.SubElement(root, 'dc:title').text = self.title root.attrib['parentID'] = str(self.parentID) if(kwargs.get('upnp_client','') != 'XBox'): if self.refID: root.attrib['refID'] = str(self.refID) if kwargs.get('requested_id',None): if kwargs.get('requested_id') != root.attrib['id']: if(kwargs.get('upnp_client','') != 'XBox'): root.attrib['refID'] = root.attrib['id'] r_id = kwargs.get('requested_id') root.attrib['id'] = r_id r_id = r_id.split('@',1) try: root.attrib['parentID'] = r_id[1] except IndexError: pass if(kwargs.get('upnp_client','') != 'XBox'): self.info("Changing ID from %r to %r, with parentID %r", root.attrib['refID'], root.attrib['id'], root.attrib['parentID']) else: self.info("Changing ID from %r to %r, with parentID %r", self.id, root.attrib['id'], root.attrib['parentID']) elif kwargs.get('parent_container',None): if(kwargs.get('parent_container') != '0' and kwargs.get('parent_container') != root.attrib['parentID']): if(kwargs.get('upnp_client','') != 'XBox'): root.attrib['refID'] = root.attrib['id'] root.attrib['id'] = '@'.join((root.attrib['id'],kwargs.get('parent_container'))) root.attrib['parentID'] = kwargs.get('parent_container') if(kwargs.get('upnp_client','') != 'XBox'): self.info("Changing ID from %r to %r, with parentID from %r to %r", root.attrib['refID'], root.attrib['id'], self.parentID, root.attrib['parentID']) else: self.info("Changing ID from %r to %r, with parentID from %r to %r", self.id, root.attrib['id'], self.parentID, root.attrib['parentID']) if(isinstance(self, Container) and kwargs.get('upnp_client','') == 'XBox'): ET.SubElement(root, 'upnp:class').text = 'object.container.storageFolder' else: ET.SubElement(root, 'upnp:class').text = self.upnp_class if self.restricted: root.attrib['restricted'] = '1' else: root.attrib['restricted'] = '0' if self.creator is not None: ET.SubElement(root, 'dc:creator').text = self.creator if self.writeStatus is not None: ET.SubElement(root, 'upnp:writeStatus').text = self.writeStatus if self.date is not None: if isinstance(self.date, datetime): ET.SubElement(root, 'dc:date').text = self.date.isoformat() else: ET.SubElement(root, 'dc:date').text = self.date else: ET.SubElement(root, 'dc:date').text = utils.datefaker().isoformat() if self.albumArtURI is not None: e = ET.SubElement(root, 'upnp:albumArtURI') e.text = self.albumArtURI e.attrib['xmlns:dlna'] = 'urn:schemas-dlna-org:metadata-1-0' e.attrib['dlna:profileID'] = 'JPEG_TN' if self.artist is not None: ET.SubElement(root, 'upnp:artist').text = self.artist if self.originalTrackNumber is not None: ET.SubElement(root, 'upnp:originalTrackNumber').text = str(self.originalTrackNumber) if self.server_uuid is not None: ET.SubElement(root, 'upnp:server_uuid').text = self.server_uuid if self.desc is not None: ET.SubElement(root, 'desc').text = self.desc return root
def toElement(self, **kwargs): root = etree.Element(self.elementName) root.attrib['id'] = str(self.id) root.attrib['parentID'] = str(self.parentID) etree.SubElement(root, qname('title', xml_constants.DC_NS)).text = self.title if kwargs.get('upnp_client', '') != 'XBox': if self.refID: root.attrib['refID'] = str(self.refID) if kwargs.get('requested_id', None): if kwargs.get('requested_id') == '0': t = root.find(qname('title', xml_constants.DC_NS)) t.text = 'root' # if kwargs.get('requested_id') != '0' and # kwargs.get('requested_id') != root.attrib['id']: if kwargs.get('requested_id') != root.attrib['id']: if kwargs.get('upnp_client', '') != 'XBox': root.attrib['refID'] = root.attrib['id'] r_id = kwargs.get('requested_id') root.attrib['id'] = r_id r_id = r_id.split('@', 1) try: root.attrib['parentID'] = r_id[1] except IndexError: pass if kwargs.get('upnp_client', '') != 'XBox': self.info(f'Changing ID from {root.attrib["refID"]} to ' + f'{root.attrib["id"]}, with parentID ' + f'{root.attrib["parentID"]}') else: self.info( f'Changing ID from {self.id} to {root.attrib["id"]}, ' + f'with parentID {root.attrib["parentID"]}') elif kwargs.get('parent_container', None): if (kwargs.get('parent_container') != '0' and kwargs.get('parent_container') != root.attrib['parentID']): if kwargs.get('upnp_client', '') != 'XBox': root.attrib['refID'] = root.attrib['id'] root.attrib['id'] = '@'.join( (root.attrib['id'], kwargs.get('parent_container'))) root.attrib['parentID'] = kwargs.get('parent_container') if kwargs.get('upnp_client', '') != 'XBox': self.info(f'Changing ID from {root.attrib["refID"]} to ' + f'{root.attrib["id"]}, with parentID from ' + f'{self.parentID} to {root.attrib["parentID"]}') else: self.info( f'Changing ID from {self.id} to {root.attrib["id"]}, ' + f'with parentID from {self.parentID} to ' + f'{root.attrib["parentID"]}') etree.SubElement(root, qname('class', xml_constants.UPNP_NS)).text = self.upnp_class if kwargs.get('upnp_client', '') == 'XBox': u = root.find(qname('class', xml_constants.UPNP_NS)) if kwargs.get('parent_container', None) is not None and u.text.startswith( 'object.container'): if kwargs.get('parent_container') in ('14', '15', '16'): u.text = 'object.container.storageFolder' if self.upnp_class == 'object.container': u.text = 'object.container.storageFolder' if self.restricted: root.attrib['restricted'] = '1' else: root.attrib['restricted'] = '0' if self.creator is not None: etree.SubElement(root, qname('creator', xml_constants.DC_NS)).text = self.creator if self.writeStatus is not None: etree.SubElement(root, qname( 'writeStatus', xml_constants.UPNP_NS)).text = self.writeStatus if self.date is not None: if isinstance(self.date, datetime): etree.SubElement(root, qname( 'date', xml_constants.DC_NS)).text = self.date.isoformat() else: etree.SubElement(root, qname('date', xml_constants.DC_NS)).text = self.date else: etree.SubElement(root, qname( 'date', xml_constants.DC_NS)).text = utils.datefaker().isoformat() if self.albumArtURI is not None: e = etree.SubElement(root, qname('albumArtURI', xml_constants.UPNP_NS)) e.text = self.albumArtURI e.attrib[qname('profileID', xml_constants.DLNA_NS)] = 'JPEG_TN' if self.artist is not None: etree.SubElement(root, qname('artist', xml_constants.UPNP_NS)).text = self.artist if self.genre is not None: etree.SubElement(root, qname('genre', xml_constants.UPNP_NS)).text = self.genre if self.genres is not None: for genre in self.genres: etree.SubElement(root, qname('genre', xml_constants.UPNP_NS)).text = genre if self.originalTrackNumber is not None: etree.SubElement( root, qname('originalTrackNumber', xml_constants.UPNP_NS)).text = str( self.originalTrackNumber) if self.description is not None: etree.SubElement(root, qname( 'description', xml_constants.DC_NS)).text = self.description if self.longDescription is not None: etree.SubElement( root, qname('longDescription', xml_constants.UPNP_NS)).text = self.longDescription if self.server_uuid is not None: etree.SubElement(root, qname( 'server_uuid', xml_constants.UPNP_NS)).text = self.server_uuid return root
def toElement(self, **kwargs): root = ET.Element(self.elementName) # if self.id == 1000: # root.attrib['id'] = '0' # ET.SubElement(root, 'dc:title').text = 'root' # else: # root.attrib['id'] = str(self.id) # ET.SubElement(root, 'dc:title').text = self.title root.attrib["id"] = str(self.id) ET.SubElement(root, qname("title", DC_NS)).text = self.title # if self.title != None: # ET.SubElement(root, 'dc:title').text = self.title # else: # ET.SubElement(root, 'dc:title').text = 'root' root.attrib["parentID"] = str(self.parentID) if kwargs.get("upnp_client", "") != "XBox": if self.refID: root.attrib["refID"] = str(self.refID) if kwargs.get("requested_id", None): if kwargs.get("requested_id") == "0": t = root.find(qname("title", DC_NS)) t.text = "root" # if kwargs.get('requested_id') != '0' and kwargs.get('requested_id') != root.attrib['id']: if kwargs.get("requested_id") != root.attrib["id"]: if kwargs.get("upnp_client", "") != "XBox": root.attrib["refID"] = root.attrib["id"] r_id = kwargs.get("requested_id") root.attrib["id"] = r_id r_id = r_id.split("@", 1) try: root.attrib["parentID"] = r_id[1] except IndexError: pass if kwargs.get("upnp_client", "") != "XBox": self.info( "Changing ID from %r to %r, with parentID %r", root.attrib["refID"], root.attrib["id"], root.attrib["parentID"], ) else: self.info( "Changing ID from %r to %r, with parentID %r", self.id, root.attrib["id"], root.attrib["parentID"], ) elif kwargs.get("parent_container", None): if kwargs.get("parent_container") != "0" and kwargs.get("parent_container") != root.attrib["parentID"]: if kwargs.get("upnp_client", "") != "XBox": root.attrib["refID"] = root.attrib["id"] root.attrib["id"] = "@".join((root.attrib["id"], kwargs.get("parent_container"))) root.attrib["parentID"] = kwargs.get("parent_container") if kwargs.get("upnp_client", "") != "XBox": self.info( "Changing ID from %r to %r, with parentID from %r to %r", root.attrib["refID"], root.attrib["id"], self.parentID, root.attrib["parentID"], ) else: self.info( "Changing ID from %r to %r, with parentID from %r to %r", self.id, root.attrib["id"], self.parentID, root.attrib["parentID"], ) ET.SubElement(root, qname("class", UPNP_NS)).text = self.upnp_class if kwargs.get("upnp_client", "") == "XBox": u = root.find(qname("class", UPNP_NS)) if kwargs.get("parent_container", None) != None and u.text.startswith("object.container"): if kwargs.get("parent_container") in ("14", "15", "16"): u.text = "object.container.storageFolder" if self.upnp_class == "object.container": u.text = "object.container.storageFolder" if self.restricted: root.attrib["restricted"] = "1" else: root.attrib["restricted"] = "0" if self.creator is not None: ET.SubElement(root, qname("creator", DC_NS)).text = self.creator if self.writeStatus is not None: ET.SubElement(root, qname("writeStatus", UPNP_NS)).text = self.writeStatus if self.date is not None: if isinstance(self.date, datetime): ET.SubElement(root, qname("date", DC_NS)).text = self.date.isoformat() else: ET.SubElement(root, qname("date", DC_NS)).text = self.date else: ET.SubElement(root, qname("date", DC_NS)).text = utils.datefaker().isoformat() if self.albumArtURI is not None: e = ET.SubElement(root, qname("albumArtURI", UPNP_NS)) e.text = self.albumArtURI e.attrib["xmlns:dlna"] = "urn:schemas-dlna-org:metadata-1-0" e.attrib["dlna:profileID"] = "JPEG_TN" if self.artist is not None: ET.SubElement(root, qname("artist", UPNP_NS)).text = self.artist if self.originalTrackNumber is not None: ET.SubElement(root, qname("originalTrackNumber", UPNP_NS)).text = str(self.originalTrackNumber) if self.description is not None: ET.SubElement(root, qname("description", DC_NS)).text = self.description if self.longDescription is not None: ET.SubElement(root, qname("longDescription", UPNP_NS)).text = self.longDescription if self.server_uuid is not None: ET.SubElement(root, qname("server_uuid", UPNP_NS)).text = self.server_uuid return root