Skip to content

Commit

Permalink
adapter_literotica: Collect averrating from hidden JSON. #1058
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmXinu committed Apr 27, 2024
1 parent 99fd4ea commit 6116a19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions calibre-plugin/plugin-defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2247,9 +2247,10 @@ extracategories:Lois & Clark: The New Adventures of Superman
[literotica.com]
use_basic_cache:true
user_agent:
extra_valid_entries:eroticatags
extra_valid_entries:eroticatags,averrating
eroticatags_label:Erotica Tags
extra_titlepage_entries:eroticatags
averrating_label:Average Rating
extra_titlepage_entries:eroticatags,averrating

## Chapters can be in different categories. Default to not using all
## to be consistent with previous version.
Expand Down
24 changes: 24 additions & 0 deletions fanficfare/adapters/adapter_literotica.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,30 @@ def extractChapterUrlsAndMetadata(self):
if coverimg:
self.setCoverImage(self.url,coverimg['src'])

#### Attempting averrating from JS metadata.
try:
state_start="state='"
state_end="'</script>"
i = data.index(state_start)
if i:
state = data[i+len(state_start):data.index(state_end,i)].replace("\\'","'").replace("\\\\","\\")
if state:
# logger.debug(state)
import json
json_state = json.loads(state)
# logger.debug(json.dumps(json_state, sort_keys=True,indent=2, separators=(',', ':')))
all_rates = []
## one-shot
if 'story' in json_state:
all_rates = [ float(json_state['story']['data']['rate_all']) ]
## series
elif 'series' in json_state:
all_rates = [ float(x['rate_all']) for x in json_state['series']['works'] ]
if all_rates:
self.story.setMetadata('averrating', sum(all_rates) / len(all_rates))
except Exception as e:
logger.debug("Processing JSON to find averrating failed. (%s)"%e)

## Features removed because not supportable by new site form:
## averrating metadata entry
## order_chapters_by_date option
Expand Down
5 changes: 3 additions & 2 deletions fanficfare/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2242,9 +2242,10 @@ extracategories:Lois & Clark: The New Adventures of Superman
[literotica.com]
use_basic_cache:true
user_agent:
extra_valid_entries:eroticatags
extra_valid_entries:eroticatags,averrating
eroticatags_label:Erotica Tags
extra_titlepage_entries:eroticatags
averrating_label:Average Rating
extra_titlepage_entries:eroticatags,averrating

## Chapters can be in different categories. Default to not using all
## to be consistent with previous version.
Expand Down

0 comments on commit 6116a19

Please sign in to comment.