def parseMetadataFromString(self, mdstr): """The metadata string is a comma separated list of name-value pairs The names match the attributes of the internal metadata struct (for now) The caret is the special "escape character", since it's not common in natural language text example = "series=Kickers^, Inc. ,issue=1, year=1986" """ escaped_comma = "^," escaped_equals = "^=" replacement_token = "<_~_>" md = GenericMetadata() # First, replace escaped commas with with a unique token (to be changed # back later) mdstr = mdstr.replace(escaped_comma, replacement_token) tmp_list = mdstr.split(",") md_list = [] for item in tmp_list: item = item.replace(replacement_token, ",") md_list.append(item) # Now build a nice dict from the list md_dict = dict() for item in md_list: # Make sure to fix any escaped equal signs i = item.replace(escaped_equals, replacement_token) key, value = i.split("=") value = value.replace(replacement_token, "=").strip() key = key.strip() if key.lower() == "credit": cred_attribs = value.split(":") role = cred_attribs[0] person = (cred_attribs[1] if len(cred_attribs) > 1 else "") primary = (cred_attribs[2] if len(cred_attribs) > 2 else None) md.addCredit( person.strip(), role.strip(), True if primary is not None else False) else: md_dict[key] = value # Map the dict to the metadata object for key in md_dict: if not hasattr(md, key): print("Warning: '{0}' is not a valid tag name".format(key)) else: md.isEmpty = False setattr(md, key, md_dict[key]) # print(md) return md
def metadataFromString( self, string ): cbi_container = json.loads( unicode(string, 'utf-8') ) metadata = GenericMetadata() cbi = cbi_container[ 'ComicBookInfo/1.0' ] #helper func # If item is not in CBI, return None def xlate( cbi_entry): if cbi_entry in cbi: return cbi[cbi_entry] else: return None metadata.series = xlate( 'series' ) metadata.title = xlate( 'title' ) metadata.issue = xlate( 'issue' ) metadata.publisher = xlate( 'publisher' ) metadata.month = xlate( 'publicationMonth' ) metadata.year = xlate( 'publicationYear' ) metadata.issueCount = xlate( 'numberOfIssues' ) metadata.comments = xlate( 'comments' ) metadata.credits = xlate( 'credits' ) metadata.genre = xlate( 'genre' ) metadata.volume = xlate( 'volume' ) metadata.volumeCount = xlate( 'numberOfVolumes' ) metadata.language = xlate( 'language' ) metadata.country = xlate( 'country' ) metadata.criticalRating = xlate( 'rating' ) metadata.tags = xlate( 'tags' ) # make sure credits and tags are at least empty lists and not None if metadata.credits is None: metadata.credits = [] if metadata.tags is None: metadata.tags = [] #need to massage the language string to be ISO if metadata.language is not None: # reverse look-up pattern = metadata.language metadata.language = None for key in utils.getLanguageDict(): if utils.getLanguageDict()[ key ] == pattern.encode('utf-8'): metadata.language = key break metadata.isEmpty = False return metadata
def metadataFromString(self, string): cbi_container = json.loads(unicode(string, 'utf-8')) metadata = GenericMetadata() cbi = cbi_container['ComicBookInfo/1.0'] #helper func # If item is not in CBI, return None def xlate(cbi_entry): if cbi_entry in cbi: return cbi[cbi_entry] else: return None metadata.series = xlate('series') metadata.title = xlate('title') metadata.issue = xlate('issue') metadata.publisher = xlate('publisher') metadata.month = xlate('publicationMonth') metadata.year = xlate('publicationYear') metadata.issueCount = xlate('numberOfIssues') metadata.comments = xlate('comments') metadata.credits = xlate('credits') metadata.genre = xlate('genre') metadata.volume = xlate('volume') metadata.volumeCount = xlate('numberOfVolumes') metadata.language = xlate('language') metadata.country = xlate('country') metadata.criticalRating = xlate('rating') metadata.tags = xlate('tags') # make sure credits and tags are at least empty lists and not None if metadata.credits is None: metadata.credits = [] if metadata.tags is None: metadata.tags = [] #need to massage the language string to be ISO if metadata.language is not None: # reverse look-up pattern = metadata.language metadata.language = None for key in utils.getLanguageDict(): if utils.getLanguageDict()[key] == pattern.encode('utf-8'): metadata.language = key break metadata.isEmpty = False return metadata
def parseMetadataFromString(self, mdstr): """The metadata string is a comma separated list of name-value pairs The names match the attributes of the internal metadata struct (for now) The caret is the special "escape character", since it's not common in natural language text example = "series=Kickers^, Inc. ,issue=1, year=1986" """ escaped_comma = "^," escaped_equals = "^=" replacement_token = "<_~_>" md = GenericMetadata() # First, replace escaped commas with with a unique token (to be changed # back later) mdstr = mdstr.replace(escaped_comma, replacement_token) tmp_list = mdstr.split(",") md_list = [] for item in tmp_list: item = item.replace(replacement_token, ",") md_list.append(item) # Now build a nice dict from the list md_dict = dict() for item in md_list: # Make sure to fix any escaped equal signs i = item.replace(escaped_equals, replacement_token) key, value = i.split("=") value = value.replace(replacement_token, "=").strip() key = key.strip() if key.lower() == "credit": cred_attribs = value.split(":") role = cred_attribs[0] person = (cred_attribs[1] if len(cred_attribs) > 1 else "") primary = (cred_attribs[2] if len(cred_attribs) > 2 else None) md.addCredit(person.strip(), role.strip(), True if primary is not None else False) else: md_dict[key] = value # Map the dict to the metadata object for key in md_dict: if not hasattr(md, key): print("Warning: '{0}' is not a valid tag name".format(key)) else: md.isEmpty = False setattr(md, key, md_dict[key]) # print(md) return md
def metadataFromFilename(self, parse_scan_info=True): metadata = GenericMetadata() fnp = FileNameParser() fnp.parseFilename(self.path) if fnp.issue != "": metadata.issue = fnp.issue if fnp.series != "": metadata.series = fnp.series if fnp.volume != "": metadata.volume = fnp.volume if fnp.year != "": metadata.year = fnp.year if fnp.issue_count != "": metadata.issueCount = fnp.issue_count if parse_scan_info: if fnp.remainder != "": metadata.scanInfo = fnp.remainder metadata.isEmpty = False return metadata
def metadataFromFilename( self ): metadata = GenericMetadata() fnp = FileNameParser() fnp.parseFilename( self.path ) if fnp.issue != "": metadata.issue = fnp.issue if fnp.series != "": metadata.series = fnp.series if fnp.volume != "": metadata.volume = fnp.volume if fnp.year != "": metadata.year = fnp.year if fnp.issue_count != "": metadata.issueCount = fnp.issue_count if self.settings.parse_scan_info: if fnp.remainder != "": metadata.scanInfo = fnp.remainder metadata.isEmpty = False return metadata
def convertXMLToMetadata(self, tree): root = tree.getroot() if root.tag != 'comet': raise 1 return None metadata = GenericMetadata() md = metadata # Helper function def xlate(tag): node = root.find(tag) if node is not None: return node.text else: return None md.series = xlate('series') md.title = xlate('title') md.issue = xlate('issue') md.volume = xlate('volume') md.comments = xlate('description') md.publisher = xlate('publisher') md.language = xlate('language') md.format = xlate('format') md.pageCount = xlate('pages') md.maturityRating = xlate('rating') md.price = xlate('price') md.isVersionOf = xlate('isVersionOf') md.rights = xlate('rights') md.identifier = xlate('identifier') md.lastMark = xlate('lastMark') md.genre = xlate('genre') # TODO - repeatable field date = xlate('date') if date is not None: parts = date.split('-') if len(parts) > 0: md.year = parts[0] if len(parts) > 1: md.month = parts[1] md.coverImage = xlate('coverImage') readingDirection = xlate('readingDirection') if readingDirection is not None and readingDirection == "rtl": md.manga = "YesAndRightToLeft" # loop for character tags char_list = [] for n in root: if n.tag == 'character': char_list.append(n.text.strip()) md.characters = utils.listToString(char_list) # Now extract the credit info for n in root: if (n.tag == 'writer' or n.tag == 'penciller' or n.tag == 'inker' or n.tag == 'colorist' or n.tag == 'letterer' or n.tag == 'editor'): metadata.addCredit(n.text.strip(), n.tag.title()) if n.tag == 'coverDesigner': metadata.addCredit(n.text.strip(), "Cover") metadata.isEmpty = False return metadata
def convertXMLToMetadata( self, tree, check = True ): root = tree.getroot() if check and root.tag != 'ComicInfo': raise 1 return None metadata = GenericMetadata() md = metadata # Helper function def xlate( tag ): node = root.find( tag ) if node is not None: return node.text else: return None md.series = xlate( 'Series' ) md.title = xlate( 'Title' ) md.issue = xlate( 'Number' ) md.issueCount = xlate( 'Count' ) md.volume = xlate( 'Volume' ) md.alternateSeries = xlate( 'AlternateSeries' ) md.alternateNumber = xlate( 'AlternateNumber' ) md.alternateCount = xlate( 'AlternateCount' ) md.comments = xlate( 'Summary' ) md.notes = xlate( 'Notes' ) md.year = xlate( 'Year' ) md.month = xlate( 'Month' ) md.day = xlate( 'Day' ) md.publisher = xlate( 'Publisher' ) md.imprint = xlate( 'Imprint' ) md.genre = xlate( 'Genre' ) md.webLink = xlate( 'Web' ) md.language = xlate( 'LanguageISO' ) md.format = xlate( 'Format' ) md.manga = xlate( 'Manga' ) md.characters = xlate( 'Characters' ) md.teams = xlate( 'Teams' ) md.locations = xlate( 'Locations' ) md.pageCount = xlate( 'PageCount' ) md.scanInfo = xlate( 'ScanInformation' ) md.storyArc = xlate( 'StoryArc' ) md.seriesGroup = xlate( 'SeriesGroup' ) md.maturityRating = xlate( 'AgeRating' ) tmp = xlate( 'BlackAndWhite' ) md.blackAndWhite = False if tmp is not None and tmp.lower() in [ "yes", "true", "1" ]: md.blackAndWhite = True # Now extract the credit info for n in root: if ( n.tag == 'Writer' or n.tag == 'Penciller' or n.tag == 'Inker' or n.tag == 'Colorist' or n.tag == 'Letterer' or n.tag == 'Editor' ): if n.text is not None: for name in n.text.split(','): metadata.addCredit( name.strip(), n.tag ) if n.tag == 'CoverArtist': if n.text is not None: for name in n.text.split(','): metadata.addCredit( name.strip(), "Cover" ) # parse page data now pages_node = root.find( "Pages" ) if pages_node is not None: for page in pages_node: metadata.pages.append( page.attrib ) #print page.attrib metadata.isEmpty = False return metadata
def convertXMLToMetadata(self, tree, check=True): root = tree.getroot() if check and root.tag != 'ComicInfo': raise 1 return None metadata = GenericMetadata() md = metadata # Helper function def xlate(tag): node = root.find(tag) if node is not None: return node.text else: return None md.series = xlate('Series') md.title = xlate('Title') md.issue = xlate('Number') md.issueCount = xlate('Count') md.volume = xlate('Volume') md.alternateSeries = xlate('AlternateSeries') md.alternateNumber = xlate('AlternateNumber') md.alternateCount = xlate('AlternateCount') md.comments = xlate('Summary') md.notes = xlate('Notes') md.year = xlate('Year') md.month = xlate('Month') md.day = xlate('Day') md.publisher = xlate('Publisher') md.imprint = xlate('Imprint') md.genre = xlate('Genre') md.webLink = xlate('Web') md.language = xlate('LanguageISO') md.format = xlate('Format') md.manga = xlate('Manga') md.characters = xlate('Characters') md.teams = xlate('Teams') md.locations = xlate('Locations') md.pageCount = xlate('PageCount') md.scanInfo = xlate('ScanInformation') md.storyArc = xlate('StoryArc') md.seriesGroup = xlate('SeriesGroup') md.maturityRating = xlate('AgeRating') tmp = xlate('BlackAndWhite') md.blackAndWhite = False if tmp is not None and tmp.lower() in ["yes", "true", "1"]: md.blackAndWhite = True # Now extract the credit info for n in root: if (n.tag == 'Writer' or n.tag == 'Penciller' or n.tag == 'Inker' or n.tag == 'Colorist' or n.tag == 'Letterer' or n.tag == 'Editor'): if n.text is not None: for name in n.text.split(','): metadata.addCredit(name.strip(), n.tag) if n.tag == 'CoverArtist': if n.text is not None: for name in n.text.split(','): metadata.addCredit(name.strip(), "Cover") # parse page data now pages_node = root.find("Pages") if pages_node is not None: for page in pages_node: metadata.pages.append(page.attrib) #print page.attrib metadata.isEmpty = False return metadata
def convertXMLToMetadata( self, tree ): root = tree.getroot() if root.tag != 'comet': raise 1 return None metadata = GenericMetadata() md = metadata # Helper function def xlate( tag ): node = root.find( tag ) if node is not None: return node.text else: return None md.series = xlate( 'series' ) md.title = xlate( 'title' ) md.issue = xlate( 'issue' ) md.volume = xlate( 'volume' ) md.comments = xlate( 'description' ) md.publisher = xlate( 'publisher' ) md.language = xlate( 'language' ) md.format = xlate( 'format' ) md.pageCount = xlate( 'pages' ) md.maturityRating = xlate( 'rating' ) md.price = xlate( 'price' ) md.isVersionOf = xlate( 'isVersionOf' ) md.rights = xlate( 'rights' ) md.identifier = xlate( 'identifier' ) md.lastMark = xlate( 'lastMark' ) md.genre = xlate( 'genre' ) # TODO - repeatable field date = xlate( 'date' ) if date is not None: parts = date.split('-') if len( parts) > 0: md.year = parts[0] if len( parts) > 1: md.month = parts[1] md.coverImage = xlate( 'coverImage' ) readingDirection = xlate( 'readingDirection' ) if readingDirection is not None and readingDirection == "rtl": md.manga = "YesAndRightToLeft" # loop for character tags char_list = [] for n in root: if n.tag == 'character': char_list.append(n.text.strip()) md.characters = utils.listToString( char_list ) # Now extract the credit info for n in root: if ( n.tag == 'writer' or n.tag == 'penciller' or n.tag == 'inker' or n.tag == 'colorist' or n.tag == 'letterer' or n.tag == 'editor' ): metadata.addCredit( n.text.strip(), n.tag.title() ) if n.tag == 'coverDesigner': metadata.addCredit( n.text.strip(), "Cover" ) metadata.isEmpty = False return metadata
def convertXMLToMetadata(self, tree): root = tree.getroot() if root.tag != "comet": raise 1 return None metadata = GenericMetadata() md = metadata # Helper function def xlate(tag): node = root.find(tag) if node is not None: return node.text else: return None md.series = xlate("series") md.title = xlate("title") md.issue = xlate("issue") md.volume = xlate("volume") md.comments = xlate("description") md.publisher = xlate("publisher") md.language = xlate("language") md.format = xlate("format") md.pageCount = xlate("pages") md.maturityRating = xlate("rating") md.price = xlate("price") md.isVersionOf = xlate("isVersionOf") md.rights = xlate("rights") md.identifier = xlate("identifier") md.lastMark = xlate("lastMark") md.genre = xlate("genre") # TODO - repeatable field date = xlate("date") if date is not None: parts = date.split("-") if len(parts) > 0: md.year = parts[0] if len(parts) > 1: md.month = parts[1] md.coverImage = xlate("coverImage") readingDirection = xlate("readingDirection") if readingDirection is not None and readingDirection == "rtl": md.manga = "YesAndRightToLeft" # loop for character tags char_list = [] for n in root: if n.tag == "character": char_list.append(n.text.strip()) md.characters = utils.listToString(char_list) # Now extract the credit info for n in root: if ( n.tag == "writer" or n.tag == "penciller" or n.tag == "inker" or n.tag == "colorist" or n.tag == "letterer" or n.tag == "editor" ): metadata.addCredit(n.text.strip(), n.tag.title()) if n.tag == "coverDesigner": metadata.addCredit(n.text.strip(), "Cover") metadata.isEmpty = False return metadata