From 89420ff5d75b22aaa70c2cfa83d0543fe24baf28 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 6 Aug 2019 23:39:39 -0700 Subject: [PATCH] Add some simple getters for authors, languages, and titles. --- epubfile.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/epubfile.py b/epubfile.py index 58407a4..0fe18c2 100644 --- a/epubfile.py +++ b/epubfile.py @@ -687,6 +687,28 @@ class Epub: spine_item['linear'] = linear + # METADATA + ############################################################################ + def get_authors(self): + ''' + Thank you double_j for showing how to deal with find_all not working + on namespaced tags. + https://stackoverflow.com/a/44681560 + ''' + creators = self.opf.metadata.find_all({'dc:creator'}) + creators = [str(c.contents[0]) for c in creators if len(c.contents) == 1] + return creators + + def get_languages(self): + languages = self.opf.metadata.find_all({'dc:language'}) + languages = [str(l.contents[0]) for l in languages if len(l.contents) == 1] + return languages + + def get_titles(self): + titles = self.opf.metadata.find_all({'dc:title'}) + titles = [str(t.contents[0]) for t in titles if len(t.contents) == 1] + return titles + # UTILITIES ############################################################################ def fix_all_xhtml(self):