From 951acf61b43f9a02ee3807f28e5905b9fd361fc2 Mon Sep 17 00:00:00 2001 From: dbhmw <167717232+dbhmw@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:57:23 +0000 Subject: [PATCH] ficbook.net Add chapter dates for TOC (#1065) * Fix the broken stuff * Last correction * Add chapter dates --- calibre-plugin/plugin-defaults.ini | 11 ++++-- fanficfare/adapters/adapter_ficbooknet.py | 48 +++++++++++++---------- fanficfare/defaults.ini | 11 ++++-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index 0f20676d..662c9cb3 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -1932,8 +1932,9 @@ add_to_output_css: white-space: pre-wrap; } -# 'collections' may generate a lot requests if the work is in many collections. For every 30 there will be additional request made. -extra_valid_entries:dedication,authorcomment,likes,follows,reviews,bookmarks,numcollections,pages,collections +# 'collections' may generate a lot of requests if the work is included in many +# collections. For every 30 there will be additional request made. +extra_valid_entries:dedication,authorcomment,likes,follows,reviews,bookmarks,numcollections,pages dedication_label:Dedication authorcomment_label:Author Comment @@ -1943,9 +1944,11 @@ reviews_label:Reviews bookmarks_label:Bookmarks numcollections_label:Collections pages_label:Pages +collections_label:Collections -# add_to_titlepage_entries:, likes, follows, reviews, bookmarks, numcollections, pages -add_to_wide_titlepage_entries:,dedication, authorcomment +# add_to_titlepage_entries:,likes,follows,reviews,bookmarks,numcollections,pages,dedication,authorcomment + +add_to_wide_titlepage_entries:,dedication,authorcomment # exclude_notes: headnotes,footnotes diff --git a/fanficfare/adapters/adapter_ficbooknet.py b/fanficfare/adapters/adapter_ficbooknet.py index 4ceb4331..15e7c0b5 100644 --- a/fanficfare/adapters/adapter_ficbooknet.py +++ b/fanficfare/adapters/adapter_ficbooknet.py @@ -105,6 +105,19 @@ class FicBookNetAdapter(BaseSiteAdapter): self.story.setMetadata('author',a.text) logger.debug("Author: (%s)"%self.story.getMetadata('author')) + fullmon = {"yanvarya":"01", u"января":"01", + "fievralya":"02", u"февраля":"02", + "marta":"03", u"марта":"03", + "aprielya":"04", u"апреля":"04", + "maya":"05", u"мая":"05", + "iyunya":"06", u"июня":"06", + "iyulya":"07", u"июля":"07", + "avghusta":"08", u"августа":"08", + "sentyabrya":"09", u"сентября":"09", + "oktyabrya":"10", u"октября":"10", + "noyabrya":"11", u"ноября":"11", + "diekabrya":"12", u"декабря":"12" } + # Find the chapters: pubdate = None chapters = soup.find('ul', {'class' : 'list-of-fanfic-parts'}) @@ -112,7 +125,16 @@ class FicBookNetAdapter(BaseSiteAdapter): for chapdiv in chapters.findAll('li', {'class':'part'}): chapter=chapdiv.find('a',href=re.compile(r'/readfic/'+self.story.getMetadata('storyId')+r"/\d+#part_content$")) churl='https://'+self.host+chapter['href'] - self.add_chapter(chapter,churl) + + # Find the dates + date_str = chapdiv.find('span', {'title': True})['title'].split(' г.')[0] + # Remove additional characters + date_str = date_str.replace('\u202f', '').replace('г. в', '').strip() + for month_name, month_num in fullmon.items(): + date_str = date_str.replace(month_name, month_num) + chapterdate = makeDate(date_str,"%d %m %Y %H:%M") + self.add_chapter(chapter,churl, + {'date':chapterdate.strftime(self.getConfig("datechapter_format",self.getConfig("datePublished_format","%Y-%m-%d %H:%M")))}) datespan = chapdiv.find('span') if pubdate == None and datespan: @@ -133,19 +155,6 @@ class FicBookNetAdapter(BaseSiteAdapter): pubdate=pubdate.split(',')[0] update=update.split(',')[0] - fullmon = {"yanvarya":"01", u"января":"01", - "fievralya":"02", u"февраля":"02", - "marta":"03", u"марта":"03", - "aprielya":"04", u"апреля":"04", - "maya":"05", u"мая":"05", - "iyunya":"06", u"июня":"06", - "iyulya":"07", u"июля":"07", - "avghusta":"08", u"августа":"08", - "sentyabrya":"09", u"сентября":"09", - "oktyabrya":"10", u"октября":"10", - "noyabrya":"11", u"ноября":"11", - "diekabrya":"12", u"декабря":"12" } - for (name,num) in fullmon.items(): if name in pubdate: pubdate = pubdate.replace(name,num) @@ -264,26 +273,25 @@ class FicBookNetAdapter(BaseSiteAdapter): for coll in targetcoll: o = coll.find('a', href=re.compile(r'/collections/')) self.story.addToList('collections', stripHTML(o)) - if self.getMetadata('collections') != num_collections: - logger.debug("Collections mismatch: (" + self.story.getMetadata('collections') + '/' + num_collections) logger.debug("Collections: (%s)"%self.story.getMetadata('collections')) targetpages = soup.find('strong',string='Размер:').find_next('div') if targetpages: - pages = re.findall(r'([\d,]+)\s+страницы', targetpages.text) - self.story.setMetadata('pages', pages) + pages = int(', '.join(re.findall(r'([\d,]+)\s+(?:страницы|страниц)', targetpages.text))) + if pages != None and pages > 0: + self.story.setMetadata('pages', pages) # Find dedication. ded = soup.find('div', {'class' : 'js-public-beta-dedication'}) if ded != None: - self.story.setMetadata('dedication',stripHTML(ded)) + self.story.setMetadata('dedication',ded) # Find author comment comm = soup.find('div', {'class' : 'js-public-beta-author-comment'}) if comm != None: - self.story.setMetadata('authorcomment',stripHTML(comm)) + self.story.setMetadata('authorcomment',comm) # grab the text for an individual chapter. diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 4323181c..2beec540 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -1927,8 +1927,9 @@ add_to_output_css: white-space: pre-wrap; } -# 'collections' may generate a lot requests if the work is in many collections. For every 30 there will be additional request made. -extra_valid_entries:dedication,authorcomment,likes,follows,reviews,bookmarks,numcollections,pages,collections +# 'collections' may generate a lot of requests if the work is included in many +# collections. For every 30 there will be additional request made. +extra_valid_entries:dedication,authorcomment,likes,follows,reviews,bookmarks,numcollections,pages dedication_label:Dedication authorcomment_label:Author Comment @@ -1938,9 +1939,11 @@ reviews_label:Reviews bookmarks_label:Bookmarks numcollections_label:Collections pages_label:Pages +collections_label:Collections -# add_to_titlepage_entries:, likes, follows, reviews, bookmarks, numcollections, pages -add_to_wide_titlepage_entries:,dedication, authorcomment +# add_to_titlepage_entries:,likes,follows,reviews,bookmarks,numcollections,pages,dedication,authorcomment + +add_to_wide_titlepage_entries:,dedication,authorcomment # exclude_notes: headnotes,footnotes