Skip to content
Snippets Groups Projects
Commit 7def637d authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Add docdate parser into fb2 ebok and mobi

parent 07078bd5
Branches
Tags
No related merge requests found
...@@ -17,6 +17,7 @@ class BookFile(object): ...@@ -17,6 +17,7 @@ class BookFile(object):
self.series_info = None self.series_info = None
self.language_code = None self.language_code = None
self.issues = [] self.issues = []
self.docdate = ''
def __enter__(self): def __enter__(self):
return self return self
...@@ -47,6 +48,12 @@ class BookFile(object): ...@@ -47,6 +48,12 @@ class BookFile(object):
if title: if title:
self.title = title self.title = title
def __set_docdate__(self, docdate):
if docdate and BookFile.__is_text(docdate):
docdate = docdate.strip()
if docdate:
self.docdate = docdate
def __add_author__(self, name, sortkey=None): def __add_author__(self, name, sortkey=None):
if not name or not BookFile.__is_text(name): if not name or not BookFile.__is_text(name):
return return
......
...@@ -102,6 +102,12 @@ class EPub(BookFile): ...@@ -102,6 +102,12 @@ class EPub(BookFile):
if len(res) > 0: if len(res) > 0:
self.__set_title__(res[0].text) self.__set_title__(res[0].text)
res = tree.xpath('/opf:package/opf:metadata/dc:date[@event="modification"]', namespaces=namespaces)
if len(res) == 0:
res = tree.xpath('/opf:package/opf:metadata/dc:date', namespaces=namespaces)
if len(res) > 0:
self.__set_docdate__(res[0].text)
res = tree.xpath('/opf:package/opf:metadata/dc:creator[@role="aut"]', namespaces=namespaces) res = tree.xpath('/opf:package/opf:metadata/dc:creator[@role="aut"]', namespaces=namespaces)
if len(res) == 0: if len(res) == 0:
res = tree.xpath('/opf:package/opf:metadata/dc:creator', namespaces=namespaces) res = tree.xpath('/opf:package/opf:metadata/dc:creator', namespaces=namespaces)
......
...@@ -27,6 +27,7 @@ class FB2Base(BookFile): ...@@ -27,6 +27,7 @@ class FB2Base(BookFile):
self.__detect_tags(tree) self.__detect_tags(tree)
self.__detect_series_info(tree) self.__detect_series_info(tree)
self.__detect_language(tree) self.__detect_language(tree)
self.__detect_docdate(tree)
description = self.__detect_description(tree) description = self.__detect_description(tree)
if description: if description:
self.description = description.strip() self.description = description.strip()
...@@ -73,6 +74,22 @@ class FB2Base(BookFile): ...@@ -73,6 +74,22 @@ class FB2Base(BookFile):
return None return None
def __detect_docdate(self, tree):
is_attrib = 1
res = tree.xpath('/fb:FictionBook/fb:description/fb:document-info/fb:date/@value', namespaces=self.__namespaces)
if len(res) == 0:
res = tree.xpath('/FictionBook/description/document-info/date/@value')
if len(res) == 0:
is_attrib = 0
res = tree.xpath('/fb:FictionBook/fb:description/fb:document-info/fb:date', namespaces=self.__namespaces)
if len(res) == 0:
is_attrib = 0
res = tree.xpath('/FictionBook/description/document-info/date')
if len(res) > 0:
self.__set_docdate__(res[0] if is_attrib else res[0].text)
return None
def __detect_authors(self, tree): def __detect_authors(self, tree):
use_namespaces = True use_namespaces = True
......
...@@ -13,6 +13,7 @@ class Mobipocket(BookFile): ...@@ -13,6 +13,7 @@ class Mobipocket(BookFile):
self._encryption_method = bm['encryption'] self._encryption_method = bm['encryption']
self.__set_title__(bm['title']) self.__set_title__(bm['title'])
self.__add_author__(bm['author']) self.__add_author__(bm['author'])
self.__set_docdate__(bm['modificationDate'].strftime("%Y-%m-%d"))
if bm['subject']: if bm['subject']:
for tag in bm['subject']: for tag in bm['subject']:
self.__add_tag__(tag) self.__add_tag__(tag)
......
...@@ -217,7 +217,7 @@ class opdsScanner: ...@@ -217,7 +217,7 @@ class opdsScanner:
title = book_data.title.strip(self.strip_symbols) if book_data.title else n title = book_data.title.strip(self.strip_symbols) if book_data.title else n
annotation = book_data.description if book_data.description else '' annotation = book_data.description if book_data.description else ''
annotation = annotation.strip(self.strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(self.strip_symbols) annotation = annotation.strip(self.strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(self.strip_symbols)
docdate = '' docdate = book_data.docdate if book_data.docdate else ''
book=opdsdb.addbook(name,rel_path,cat,e[1:],title,annotation,docdate,lang,file_size,archive) book=opdsdb.addbook(name,rel_path,cat,e[1:],title,annotation,docdate,lang,file_size,archive)
self.books_added+=1 self.books_added+=1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment