forked from chu-shen/BangumiKomga
-
Notifications
You must be signed in to change notification settings - Fork 2
/
processMetadata.py
201 lines (157 loc) · 7.34 KB
/
processMetadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# -*- coding: utf-8 -*- #
# ------------------------------------------------------------------
# Description: Handles komga bd metadata
# ------------------------------------------------------------------
from komgaApi import seriesMetadata, bookMetadata
def __setGenres(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['genresLock']:
preparedKomgaMetadata.genres = bedetheque_metadata['genres']
else:
preparedKomgaMetadata.genres = komga_metadata['genres']
def __setStatus(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['statusLock']:
runningLang = ["Série en cours"]
abandonedLang = ["Série abandonnée"]
endedLang = ["Série finie"]
suspendedLang = ['Série suspendue']
status = "ONGOING"
if bedetheque_metadata["status"].strip() in runningLang:
status = "ONGOING"
elif bedetheque_metadata["status"].strip() in abandonedLang:
status = "ABANDONED"
elif bedetheque_metadata["status"].strip() in endedLang:
status = "ENDED"
elif bedetheque_metadata["status"].strip() in suspendedLang:
status = "HIATUS"
preparedKomgaMetadata.status = status
else:
preparedKomgaMetadata.status = komga_metadata['status']
def __prepareAuthors(authors, bedetheque_author, role):
for author in authors:
if author['role'] == role:
authors.remove(author)
bedetheque_author.reverse()
author = ''
for bedetheque_author_split in bedetheque_author:
author += bedetheque_author_split.strip() + ' '
authors.append({"name": author.strip(), "role": role})
return authors
def __setAuthors(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
'''
basic format = {'name':'value','role':'role type'}
The role types are:
writer
inker
translator
editor
cover
letterer
colorist
penciller
Custom role type value
'''
if not komga_metadata['authorsLock']:
authors = komga_metadata['authors'].copy()
for scenario in bedetheque_metadata["scenarios"]:
authors = __prepareAuthors(authors, scenario, "writer")
for penciller in bedetheque_metadata["dessins"]:
authors = __prepareAuthors(authors, penciller, "penciller")
for colorist in bedetheque_metadata["couleurs"]:
authors = __prepareAuthors(authors, colorist, "colorist")
for cover in bedetheque_metadata["couvertures"]:
authors = __prepareAuthors(authors, cover, "cover")
for letterer in bedetheque_metadata["lettrages"]:
authors = __prepareAuthors(authors, letterer, "letterer")
preparedKomgaMetadata.authors = authors
else:
preparedKomgaMetadata.authors = komga_metadata['authors']
def __setTotalBookCount(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['totalBookCountLock']:
preparedKomgaMetadata.totalBookCount = bedetheque_metadata['totalBookCount']
else:
preparedKomgaMetadata.totalBookCount = komga_metadata['totalBookCount']
def __setBookNumber(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['numberLock']:
preparedKomgaMetadata.number = bedetheque_metadata['booknumber']
else:
preparedKomgaMetadata.number = komga_metadata['number']
# if not komga_metadata['numberSortLock']:
# preparedKomgaMetadata.numberSort = bedetheque_metadata['booknumber'] // TODO: verify if used on bedetheque, otherwise just uncomment
# else:
# preparedKomgaMetadata.numberSort = komga_metadata['numberSort']
def __setPublisher(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['publisherLock']:
preparedKomgaMetadata.publisher = bedetheque_metadata['publisher']
else:
preparedKomgaMetadata.publisher = komga_metadata['publisher']
def __setTitle(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['titleLock']:
preparedKomgaMetadata.title = bedetheque_metadata["title"]
else:
preparedKomgaMetadata.title = komga_metadata['title']
def __setSummary(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['summaryLock']:
preparedKomgaMetadata.summary = bedetheque_metadata["summary"]
else:
preparedKomgaMetadata.summary = komga_metadata['summary']
def __setISBN(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['isbnLock']:
preparedKomgaMetadata.isbn = bedetheque_metadata["isbn"]
else:
preparedKomgaMetadata.isbn = komga_metadata['isbn']
def __setReleaseDate(preparedKomgaMetadata, bedetheque_metadata, komga_metadata):
if not komga_metadata['releaseDateLock']:
preparedKomgaMetadata.releaseDate = bedetheque_metadata["releaseDate"]
else:
preparedKomgaMetadata.releaseDate = komga_metadata['releaseDate']
def __setLinks(preparedKomgaMetadata, url, komga_metadata):
if not komga_metadata['linksLock']:
links = komga_metadata['links'].copy()
for komgalink in komga_metadata['links']:
if komgalink['label'] == "www.bedetheque.com":
if komgalink['url'] != url:
links.remove(komgalink)
else:
break
else:
links.append({"label": "www.bedetheque.com", "url": url})
preparedKomgaMetadata.links = links
else:
preparedKomgaMetadata.links = komga_metadata['links']
def prepareKomgaSeriesMetadata(bedetheque_metadata, komga_metadata, serie_url):
# init
preparedKomgaSeriesMetadata = seriesMetadata()
# link
__setLinks(preparedKomgaSeriesMetadata, serie_url, komga_metadata)
# summary
__setSummary(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
# status
__setStatus(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
# genres
__setGenres(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
# totalBookCount
__setTotalBookCount(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
# publisher
__setPublisher(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
# title
__setTitle(preparedKomgaSeriesMetadata, bedetheque_metadata, komga_metadata)
preparedKomgaSeriesMetadata.isvalid = True
return preparedKomgaSeriesMetadata
def prepareKomgaBookMetadata(bedetheque_metadata, komga_metadata, book_url):
preparedKomgaBooksMetadata = bookMetadata()
# title
__setTitle(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
# link
__setLinks(preparedKomgaBooksMetadata, book_url, komga_metadata)
# booknumber
__setBookNumber(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
# summary
__setSummary(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
# authors
__setAuthors(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
# releaseDate
__setReleaseDate(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
# isbn
__setISBN(preparedKomgaBooksMetadata, bedetheque_metadata, komga_metadata)
preparedKomgaBooksMetadata.isvalid = True
return preparedKomgaBooksMetadata