Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Calibre series metadata #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions epub_meta/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ def iterate_all_tags(root):
yield subnode


def find_tag(xmldoc, tag_name, attr, value):
def find_tags(xmldoc, tag_name, attr, value):
# print('Finding tag: <{} {}="{}">'.format(tag_name, attr, value))
result = []
for tag in xmldoc.getElementsByTagName(tag_name):
if attr in tag.attributes.keys() and tag.attributes[attr].value == value:
return tag
result.append(tag)
return result


def find_tag(xmldoc, tag_name, attr, value):
tags = find_tags(xmldoc, tag_name, attr, value)
if tags:
return tags[0]
return None


def find_img_tag(xmldoc, tag_name, attr, value):
Expand Down Expand Up @@ -180,6 +189,24 @@ def _discover_subject(opf_xmldoc):
return __discover_dc(opf_xmldoc, 'subject', first_only=False)


def _discover_calibre_series_index(opf_xmldoc):
tags = find_tags(opf_xmldoc, 'meta', 'name', 'calibre:series_index')
results = []
for tag in tags:
if tag and 'content' in tag.attributes.keys():
results.append(tag.attributes['content'].value)
return results


def _discover_calibre_series(opf_xmldoc):
tags = find_tags(opf_xmldoc, 'meta', 'name', 'calibre:series')
results = []
for tag in tags:
if tag and 'content' in tag.attributes.keys():
results.append(tag.attributes['content'].value)
return results


def _discover_cover_image(zf, opf_xmldoc, opf_filepath):
'''
Find the cover image path in the OPF file.
Expand Down Expand Up @@ -382,6 +409,8 @@ def get_epub_metadata(filepath, read_cover_image=True, read_toc=True):
'identifiers': _discover_identifiers(opf_xmldoc),
'subject': _discover_subject(opf_xmldoc),
'file_size_in_bytes': file_size_in_bytes,
'calibre_series': _discover_calibre_series(opf_xmldoc),
'calibre_series_index': _discover_calibre_series_index(opf_xmldoc),
})

if read_cover_image:
Expand Down