From 6b9b298594039dabe8a7234e69e5fcfac1a66165 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 May 2020 20:33:47 +0530 Subject: [PATCH] FB2 metadata: Add support for setting publisher and publish year --- src/calibre/ebooks/metadata/fb2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/calibre/ebooks/metadata/fb2.py b/src/calibre/ebooks/metadata/fb2.py index ceaf0479a1..50f01a5ae7 100644 --- a/src/calibre/ebooks/metadata/fb2.py +++ b/src/calibre/ebooks/metadata/fb2.py @@ -356,6 +356,22 @@ def _set_authors(title_info, mi, ctx): ctx.create_tag(atag, 'last-name', at_start=False).text = ' '.join(author_parts) +def _set_publisher(publish_info, mi, ctx): + if mi.is_null('publisher'): + return + ctx.clear_meta_tags(publish_info, 'publisher') + tag = ctx.create_tag(publish_info, 'publisher') + tag.text = mi.publisher + + +def _set_pubdate(publish_info, mi, ctx): + if mi.is_null('pubdate'): + return + ctx.clear_meta_tags(publish_info, 'year') + tag = ctx.create_tag(publish_info, 'year') + tag.text = mi.pubdate.strftime('%Y') + + def _set_tags(title_info, mi, ctx): if not mi.is_null('tags'): ctx.clear_meta_tags(title_info, 'genre') @@ -410,6 +426,7 @@ def set_metadata(stream, mi, apply_null=False, update_timestamp=False): ctx = Context(root) desc = ctx.get_or_create(root, 'description') ti = ctx.get_or_create(desc, 'title-info') + pi = ctx.get_or_create(desc, 'publish-info') indent = ti.text @@ -418,6 +435,8 @@ def set_metadata(stream, mi, apply_null=False, update_timestamp=False): _set_tags(ti, mi, ctx) _set_authors(ti, mi, ctx) _set_title(ti, mi, ctx) + _set_publisher(pi, mi, ctx) + _set_pubdate(pi, mi, ctx) _set_cover(ti, mi, ctx) for child in ti: