diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index e53d7db8..b1c7a654 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -2292,6 +2292,22 @@ chapter_categories_use_all: false ## or just use the text. If this can't be done, the full title is used. clean_chapter_titles: false +## For stories, collect tags from individual chapter pages in addition to the +## series page tags. This allows collection of tags beyond the top 10 on the series but +## if the author updates tags on a chapter and not the series, those tags may persist even if +## the chapter is not fetched during an update. +## Default is false to maintain previous behavior. +tags_from_chapters: false + +## For multi-chapter stories (series), use the chapter approval dates for datePublished +## and dateUpdated instead of the series metadata dates. This provides more accurate dates +## based on actual posting dates rather than just when the series metadata changes. This +## method can provide wildly different dates if chapters were written long before being +## approved, if chapters are approved out of order, or if the works were approved/updated +## before literotica's current series system was implemented. +## Default is false to maintain previous behavior. +dates_from_chapters: false + ## Some stories mistakenly include 'Ch' or 'Pt' at the end of the ## story title. Appears to be a site bug or common author error. Copy ## these to your personal.ini (and uncomment) to correct. diff --git a/fanficfare/adapters/adapter_literotica.py b/fanficfare/adapters/adapter_literotica.py index 8122f474..565a8649 100644 --- a/fanficfare/adapters/adapter_literotica.py +++ b/fanficfare/adapters/adapter_literotica.py @@ -182,12 +182,14 @@ class LiteroticaSiteAdapter(BaseSiteAdapter): else: # if all else fails self.story.setMetadata('authorId', stripHTML(authora)) - if soup.select('div#tabpanel-tags'): - # logger.debug("tags1") - self.story.extendList('eroticatags', [ stripHTML(t).title() for t in soup.select('div#tabpanel-tags a.av_as') ]) - if soup.select('div[class^="_widget__tags_"]'): - # logger.debug("tags2") - self.story.extendList('eroticatags', [ stripHTML(t).title() for t in soup.select('div[class^="_widget__tags_"] a[class^="_tags__link_"]') ]) + ## Collect tags from series/story page if tags_from_chapters is enabled + if self.getConfig("tags_from_chapters"): + if soup.select('div#tabpanel-tags'): + # logger.debug("tags1") + self.story.extendList('eroticatags', [ stripHTML(t).title() for t in soup.select('div#tabpanel-tags a.av_as') ]) + if soup.select('div[class^="_widget__tags_"]'): + # logger.debug("tags2") + self.story.extendList('eroticatags', [ stripHTML(t).title() for t in soup.select('div[class^="_widget__tags_"] a[class^="_tags__link_"]') ]) # logger.debug(self.story.getList('eroticatags')) ## look first for 'Series Introduction', then Info panel short desc @@ -250,7 +252,8 @@ class LiteroticaSiteAdapter(BaseSiteAdapter): ## Multi-chapter stories. AKA multi-part 'Story Series'. bn_antags = soup.select('div#tabpanel-info p.bn_an') # logger.debug(bn_antags) - if bn_antags: + if bn_antags and not self.getConfig("dates_from_chapters"): + ## Use dates from series metadata unless dates_from_chapters is enabled dates = [] for datetag in bn_antags[:2]: datetxt = stripHTML(datetag) @@ -345,6 +348,21 @@ class LiteroticaSiteAdapter(BaseSiteAdapter): ## series elif 'series' in json_state: all_rates = [ float(x['rate_all']) for x in json_state['series']['works'] ] + + ## Extract dates from chapter approval dates if dates_from_chapters is enabled + if self.getConfig("dates_from_chapters"): + date_approvals = [] + for work in json_state['series']['works']: + if 'date_approve' in work: + try: + date_approvals.append(makeDate(work['date_approve'], self.dateformat)) + except: + pass + if date_approvals: + # Oldest date is published, newest is updated + date_approvals.sort() + self.story.setMetadata('datePublished', date_approvals[0]) + self.story.setMetadata('dateUpdated', date_approvals[-1]) if all_rates: self.story.setMetadata('averrating', '%4.2f' % (sum(all_rates) / float(len(all_rates)))) except Exception as e: diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index 664ee3b3..d16f68de 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -266,6 +266,8 @@ def get_valid_set_options(): 'description_in_chapter':(['literotica.com'],None,boollist), 'fetch_stories_from_api':(['literotica.com'],None,boollist), 'order_chapters_by_date':(['literotica.com'],None,boollist), + 'tags_from_chapters':(['literotica.com'],None,boollist), + 'dates_from_chapters':(['literotica.com'],None,boollist), 'inject_chapter_title':(['asianfanfics.com']+wpc_list,None,boollist), 'inject_chapter_image':(['asianfanfics.com'],None,boollist), @@ -520,6 +522,8 @@ def get_valid_keywords(): 'description_in_chapter', 'order_chapters_by_date', 'fetch_stories_from_api', + 'tags_from_chapters', + 'dates_from_chapters', 'inject_chapter_title', 'inject_chapter_image', 'append_datepublished_to_storyurl', diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 7a4568f1..5f1c012c 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -2285,6 +2285,22 @@ chapter_categories_use_all: false ## or just use the text. If this can't be done, the full title is used. clean_chapter_titles: false +## For stories, collect tags from individual chapter pages in addition to the +## series page tags. This allows collection of tags beyond the top 10 on the series but +## if the author updates tags on a chapter and not the series, those tags may persist even if +## the chapter is not fetched during an update. +## Default is false to maintain previous behavior. +tags_from_chapters: false + +## For multi-chapter stories (series), use the chapter approval dates for datePublished +## and dateUpdated instead of the series metadata dates. This provides more accurate dates +## based on actual posting dates rather than just when the series metadata changes. This +## method can provide wildly different dates if chapters were written long before being +## approved, if chapters are approved out of order, or if the works were approved/updated +## before literotica's current series system was implemented. +## Default is false to maintain previous behavior. +dates_from_chapters: false + ## Some stories mistakenly include 'Ch' or 'Pt' at the end of the ## story title. Appears to be a site bug or common author error. Copy ## these to your personal.ini (and uncomment) to correct.