Krita Source Code Documentation
Loading...
Searching...
No Matches
CPMT_Comic_Rack_XML_Exporter.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2018 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3
4This file is part of the Comics Project Management Tools(CPMT).
5
6SPDX-License-Identifier: GPL-3.0-or-later
7"""
8
9"""
10The comicrack information is sorta... incomplete, so no idea if the following is right...
11I can't check in any case: It is a windows application.
12
13Based off:
14
15https://github.com/dickloraine/EmbedComicMetadata/blob/master/comicinfoxml.py
16
17ComicRack is also a dead application.
18
19Missing:
20
21Count (issues)
22AlternateSeries
23AlternateNumber
24StoryArc
25SeriesGroup
26AlternateCount
27Notes
28Imprint
29Locations
30ScanInformation
31AgeRating - Not sure if this should be added or not...
32Teams
33Web
34
35"""
36
37from xml.dom import minidom
38try:
39 from PyQt6.QtCore import QDate, Qt
40except:
41 from PyQt5.QtCore import QDate, Qt
42
43def write_xml(configDictionary = {}, pagesLocationList = [], location = str()):
44 document = minidom.Document()
45 root = document.createElement("ComicInfo")
46 root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
47 root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
48
49 title = document.createElement("Title")
50 if "title" in configDictionary.keys():
51 title.appendChild(document.createTextNode(str(configDictionary["title"])))
52 else:
53 title.appendChild(document.createTextNode(str("Untitled Comic")))
54 root.appendChild(title)
55 description = document.createElement("Summary")
56 if "summary" in configDictionary.keys():
57 description.appendChild(document.createTextNode(str(configDictionary["summary"])))
58 else:
59 description.appendChild(document.createTextNode(str("There was no summary upon generation of this file.")))
60 root.appendChild(description)
61
62 if "seriesNumber" in configDictionary.keys():
63 number = document.createElement("Number")
64 number.appendChild(document.createTextNode(str(configDictionary["seriesNumber"])))
65 root.appendChild(number)
66 if "seriesName" in configDictionary.keys():
67 seriesname = document.createElement("Series")
68 seriesname.appendChild(document.createTextNode(str(configDictionary["seriesName"])))
69 root.appendChild(seriesname)
70
71 if "publishingDate" in configDictionary.keys():
72 date = QDate.fromString(configDictionary["publishingDate"], Qt.DateFormat.ISODate)
73 publishYear = document.createElement("Year")
74 publishYear.appendChild(document.createTextNode(str(date.year())))
75 publishMonth = document.createElement("Month")
76 publishMonth.appendChild(document.createTextNode(str(date.month())))
77 publishDay = document.createElement("Day")
78 publishDay.appendChild(document.createTextNode(str(date.day())))
79 root.appendChild(publishYear)
80 root.appendChild(publishMonth)
81 root.appendChild(publishDay)
82
83 if "format" in configDictionary.keys():
84 for form in configDictionary["format"]:
85 formattag = document.createElement("Format")
86 formattag.appendChild(document.createTextNode(str(form)))
87 root.appendChild(formattag)
88 if "otherKeywords" in configDictionary.keys():
89 tags = document.createElement("Tags")
90 tags.appendChild(document.createTextNode(str(", ".join(configDictionary["otherKeywords"]))))
91 root.appendChild(tags)
92
93 if "authorList" in configDictionary.keys():
94 for authorE in range(len(configDictionary["authorList"])):
95 author = document.createElement("Writer")
96 authorDict = configDictionary["authorList"][authorE]
97 if "role" in authorDict.keys():
98 if str(authorDict["role"]).lower() in ["writer", "penciller", "editor", "assistant editor", "cover artist", "letterer", "inker", "colorist"]:
99 if str(authorDict["role"]).lower() == "cover artist":
100 author = document.createElement("CoverArtist")
101 elif str(authorDict["role"]).lower() == "assistant editor":
102 author = document.createElement("Editor")
103 else:
104 author = document.createElement(str(authorDict["role"]).title())
105 stringName = []
106 if "last-name" in authorDict.keys():
107 stringName.append(authorDict["last-name"])
108 if "first-name" in authorDict.keys():
109 stringName.append(authorDict["first-name"])
110 if "nickname" in authorDict.keys():
111 stringName.append("(" + authorDict["nickname"] + ")")
112 author.appendChild(document.createTextNode(str(",".join(stringName))))
113 root.appendChild(author)
114 if "publisherName" in configDictionary.keys():
115 publisher = document.createElement("Publisher")
116 publisher.appendChild(document.createTextNode(str(configDictionary["publisherName"])))
117 root.appendChild(publisher)
118
119 if "genre" in configDictionary.keys():
120 genreListConf = configDictionary["genre"]
121 if isinstance(configDictionary["genre"], dict):
122 genreListConf = configDictionary["genre"].keys()
123 for genreE in genreListConf:
124 genre = document.createElement("Genre")
125 genre.appendChild(document.createTextNode(str(genreE)))
126 root.appendChild(genre)
127 blackAndWhite = document.createElement("BlackAndWhite")
128 blackAndWhite.appendChild(document.createTextNode(str("No")))
129 root.appendChild(blackAndWhite)
130 readingDirection = document.createElement("Manga")
131 readingDirection.appendChild(document.createTextNode(str("No")))
132 if "readingDirection" in configDictionary.keys():
133 if configDictionary["readingDirection"] == "rightToLeft":
134 readingDirection.appendChild(document.createTextNode(str("YesAndRightToLeft")))
135 root.appendChild(readingDirection)
136
137 if "characters" in configDictionary.keys():
138 for char in configDictionary["characters"]:
139 character = document.createElement("Character")
140 character.appendChild(document.createTextNode(str(char)))
141 root.appendChild(character)
142 if "pages" in configDictionary.keys():
143 pagecount = document.createElement("PageCount")
144 pagecount.appendChild(document.createTextNode(str(len(configDictionary["pages"]))))
145 root.appendChild(pagecount)
146 pages = document.createElement("Pages")
147 covernumber = 0
148 if "pages" in configDictionary.keys() and "cover" in configDictionary.keys():
149 covernumber = configDictionary["pages"].index(configDictionary["cover"])
150 for i in range(len(pagesLocationList)):
151 page = document.createElement("Page")
152 page.setAttribute("Image", str(i))
153 if i is covernumber:
154 page.setAttribute("Type", "FrontCover")
155 pages.appendChild(page)
156 root.appendChild(pages)
157 document.appendChild(root)
158 f = open(location, 'w', newline="", encoding="utf-8")
159 f.write(document.toprettyxml(indent=" "))
160 f.close()
161 return True
write_xml(configDictionary={}, pagesLocationList=[], location=str())