Add XF2 threadmarks_cover/status/desc/title options.

This commit is contained in:
Jim Miller 2019-07-29 18:27:01 -05:00
parent 0e97cd7d99
commit 2397fdaaea
5 changed files with 117 additions and 5 deletions

View file

@ -756,7 +756,36 @@ use_threadmark_wordcounts:true
# .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; }
[base_xenforo2forum]
## So far, only SV. [base_xenforoforum] also applied.
## [base_xenforoforum] also applied, but [base_xenforo2forum] takes
## precedence. SV is the only XF2 site as of Jul 2019.
## Some additional 'thread' metadata entries.
add_to_extra_valid_entries:,threadmarks_title,threadmarks_description,threadmarks_status
#add_to_extra_titlepage_entries:,threadmarks_title,threadmarks_description,threadmarks_status
# Just to remove '_'.
threadmarks_title_label:Threadmarks Title
threadmarks_description_label:Threadmarks Description
threadmarks_status_label:Threadmarks Status
## When use_threadmarks_description is set true,
## threadmarks_description will be used to fill in the standard
## description metadata entry. Some stories have poor
## threadmarks_description, you can use this setting to avoid using
## it.
use_threadmarks_description:true
## Increasing description_limit from base_xenforoforum's default of
## 500 is also useful with use_threadmarks_description
description_limit:1000
## When use_threadmarks_status is set true, a normalized version of
## threadmarks_status will be used to fill in the standard status
## metadata entry. (In-Progress, Completed plus site statuses.)
use_threadmarks_status:true
## When use_threadmarks_cover is set true, the threadmarks image will
## be used to fill in the cover image. Set true by default.
use_threadmarks_cover:true
[epub]

View file

@ -98,6 +98,44 @@ class BaseXenForo2ForumAdapter(BaseXenForoForumAdapter):
self.story.setMetadata('title',stripHTML(h1))
# logger.debug(stripHTML(h1))
def set_threadmarks_metadata(self,useurl,topsoup):
header = topsoup.find('div',{'class':'threadmarkListingHeader'})
if header:
# logger.debug(header)
desc = self.get_post_body(header)
if desc:
self.story.setMetadata("threadmarks_description",desc)
if self.getConfig('use_threadmarks_description'):
self.setDescription(useurl,desc)
# logger.debug(desc)
title = header.find('h1',{'class':'threadmarkListingHeader-name'})
if title:
self.story.setMetadata("threadmarks_title",stripHTML(title))
statusdt = header.find('dt',text="Index progress")
if statusdt:
statusdd = statusdt.find_next_sibling('dd')
if statusdd:
threadmarks_status = stripHTML(statusdd)
self.story.setMetadata("threadmarks_status",threadmarks_status)
if self.getConfig('use_threadmarks_status'):
if 'Complete' in threadmarks_status:
self.story.setMetadata('status','Completed')
elif 'Incomplete' in threadmarks_status:
self.story.setMetadata('status','In-Progress')
else:
self.story.setMetadata('status',threadmarks_status)
if self.getConfig('use_threadmarks_cover'):
cover = header.find('span',{'class':'threadmarkListingHeader-icon'})
# logger.debug(cover)
if cover:
img = cover.find('img')
if img:
src = img['src']
if img.has_attr('srcset'):
src = img['srcset']
self.setCoverImage(useurl,src)
return
def get_forumtags(self,topsoup):
return topsoup.find('div',{'class':'p-description'}).findAll('a',{'class':'tagItem'})

View file

@ -469,6 +469,9 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
self.story.setMetadata('numWords',words)
souptag = self.get_first_post(topsoup)
if use_threadmark_chaps:
self.set_threadmarks_metadata(useurl,topsoup)
if use_threadmark_chaps or self.getConfig('always_use_forumtags'):
## only use tags if threadmarks for chapters or always_use_forumtags is on.
for tag in self.get_forumtags(topsoup):
@ -496,7 +499,8 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
# using threadmarks.
index_post = self.get_post_body(souptag)
self.setDescription(useurl,index_post)
if not self.story.getMetadata('description'):
self.setDescription(useurl,index_post)
# otherwise, use first post links--include first post since
# that's often also the first chapter.
@ -536,6 +540,10 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
tag.extract()
self.story.setMetadata('title',stripHTML(h1))
def set_threadmarks_metadata(self,topsoup):
# None in XF1.
return
def get_forumtags(self,topsoup):
return topsoup.findAll('a',{'class':'tag'}) + topsoup.findAll('span',{'class':'prefix'})

View file

@ -171,9 +171,11 @@ def get_valid_list_entries():
])
boollist=['true','false']
base_xenforo_list=['base_xenforoforum',
'forums.spacebattles.com',
base_xenforo2_list=['base_xenforo2forum',
'forums.sufficientvelocity.com',
]
base_xenforo_list=base_xenforo2_list+['base_xenforoforum',
'forums.spacebattles.com',
'forum.questionablequesting.com',
'www.alternatehistory.com',
]
@ -279,6 +281,9 @@ def get_valid_set_options():
'replace_failed_smilies_with_alt_text':(base_xenforo_list,None,boollist),
'use_threadmark_wordcounts':(base_xenforo_list,None,boollist),
'always_include_first_post_chapters':(base_xenforo_list,None,boollist),
'use_threadmarks_description':(base_xenforo2_list,None,boollist),
'use_threadmarks_status':(base_xenforo2_list,None,boollist),
'use_threadmarks_cover':(base_xenforo2_list,None,boollist),
'fix_pseudo_html': (['webnovel.com'], None, boollist),
'fix_excess_space': (['novelonlinefull.com', 'novelall.com'], ['epub', 'html'], boollist)
}
@ -488,6 +493,9 @@ def get_valid_keywords():
'replace_failed_smilies_with_alt_text',
'use_threadmark_wordcounts',
'always_include_first_post_chapters',
'use_threadmarks_description',
'use_threadmarks_status',
'use_threadmarks_cover',
'datethreadmark_format',
'fix_pseudo_html',
'fix_excess_space',

View file

@ -783,7 +783,36 @@ use_threadmark_wordcounts:true
# .bbCodeSpoilerContainer { border: 1px solid black; padding: 2px; }
[base_xenforo2forum]
## So far, only SV. [base_xenforoforum] also applied.
## [base_xenforoforum] also applied, but [base_xenforo2forum] takes
## precedence. SV is the only XF2 site as of Jul 2019.
## Some additional 'thread' metadata entries.
add_to_extra_valid_entries:,threadmarks_title,threadmarks_description,threadmarks_status
#add_to_extra_titlepage_entries:,threadmarks_title,threadmarks_description,threadmarks_status
# Just to remove '_'.
threadmarks_title_label:Threadmarks Title
threadmarks_description_label:Threadmarks Description
threadmarks_status_label:Threadmarks Status
## When use_threadmarks_description is set true,
## threadmarks_description will be used to fill in the standard
th use_threadmarks_description
description_limit:1000
## description metadata entry. Eventually I expect this will default
## to true once more threads use it. Increasing description_limit
## from base_xenforoforum's default of 500 is also useful.
#use_threadmarks_description:false
#description_limit:1000
## When use_threadmarks_status is set true, a normalized version of
## threadmarks_status will be used to fill in the standard status
## metadata entry. (In-Progress, Completed plus site statuses.)
use_threadmarks_status:true
## When use_threadmarks_cover is set true, the threadmarks image will
## be used to fill in the cover image. Set true by default.
use_threadmarks_cover:true
[epub]