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 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 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 mapCVDataToMetadata(self, volume_results, issue_results, settings): # Now, map the Comic Vine data to generic metadata metadata = GenericMetadata() metadata.series = issue_results['volume']['name'] num_s = IssueString(issue_results['issue_number']).asString() metadata.issue = num_s metadata.title = issue_results['name'] metadata.publisher = volume_results['publisher']['name'] metadata.day, metadata.month, metadata.year = self.parseDateStr( issue_results['cover_date']) #metadata.issueCount = volume_results['count_of_issues'] metadata.comments = self.cleanup_html( issue_results['description'], settings.remove_html_tables) if settings.use_series_start_as_volume: metadata.volume = volume_results['start_year'] metadata.notes = "Tagged with the {0} fork of ComicTagger {1} using info from Comic Vine on {2}. [Issue ID {3}]".format( ctversion.fork, ctversion.version, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), issue_results['id']) #metadata.notes += issue_results['site_detail_url'] metadata.webLink = issue_results['site_detail_url'] person_credits = issue_results['person_credits'] for person in person_credits: if 'role' in person: roles = person['role'].split(',') for role in roles: # can we determine 'primary' from CV?? metadata.addCredit( person['name'], role.title().strip(), False) character_credits = issue_results['character_credits'] character_list = list() for character in character_credits: character_list.append(character['name']) metadata.characters = utils.listToString(character_list) team_credits = issue_results['team_credits'] team_list = list() for team in team_credits: team_list.append(team['name']) metadata.teams = utils.listToString(team_list) location_credits = issue_results['location_credits'] location_list = list() for location in location_credits: location_list.append(location['name']) metadata.locations = utils.listToString(location_list) story_arc_credits = issue_results['story_arc_credits'] arc_list = [] for arc in story_arc_credits: arc_list.append(arc['name']) if len(arc_list) > 0: metadata.storyArc = utils.listToString(arc_list) 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