Add a few metadata methods, just proof-of-concept for now.
I know I don't want to create a full-blown metadata editor, but a couple methods for basic metadata types and simple adds/removes could be useful.
This commit is contained in:
parent
a68a69ab99
commit
d928b950ac
1 changed files with 19 additions and 0 deletions
19
epubfile.py
19
epubfile.py
|
@ -908,6 +908,25 @@ class Epub:
|
||||||
titles = [str(t.contents[0]) for t in titles if len(t.contents) == 1]
|
titles = [str(t.contents[0]) for t in titles if len(t.contents) == 1]
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
|
@writes
|
||||||
|
def remove_metadata_of_type(self, tag_name):
|
||||||
|
for meta in self.opf.metadata.find_all({tag_name}):
|
||||||
|
if meta.get('id'):
|
||||||
|
for refines in self.opf.metadata.find_all('meta', {'refines': f'#{meta["id"]}'}):
|
||||||
|
refines.extract()
|
||||||
|
meta.extract()
|
||||||
|
|
||||||
|
@writes
|
||||||
|
def set_languages(self, languages):
|
||||||
|
'''
|
||||||
|
A list like ['en', 'fr', 'ko'].
|
||||||
|
'''
|
||||||
|
self.remove_metadata_of_type('dc:language')
|
||||||
|
for language in languages:
|
||||||
|
element = f'<dc:language>{language}</dc:language>'
|
||||||
|
element = bs4.BeautifulSoup(element, 'html.parser')
|
||||||
|
self.opf.metadata.append(element)
|
||||||
|
|
||||||
# UTILITIES
|
# UTILITIES
|
||||||
############################################################################
|
############################################################################
|
||||||
@writes
|
@writes
|
||||||
|
|
Loading…
Reference in a new issue