mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-01-02 06:04:56 +01:00
Add use_flaresolverr_proxy:withimages option for FlareSolverr v1 users.
This commit is contained in:
parent
77d1037a90
commit
582c1a6e7f
4 changed files with 45 additions and 15 deletions
|
|
@ -578,8 +578,15 @@ browser_cache_age_limit:4.0
|
|||
|
||||
## FlareSolverr (https://github.com/FlareSolverr/FlareSolverr) is a
|
||||
## generic proxy that works with several otherwise blocked sites.
|
||||
## Note that FFF cannot fetch images through FlareSolverr.
|
||||
## It's recommended to only set use_flaresolverr_proxy:true for specific sites.
|
||||
## It's recommended to only set use_flaresolverr_proxy:true for
|
||||
## specific sites.
|
||||
## FlareSolverr v1 doesn't work with some sites anymore (including
|
||||
## ffnet), but FlareSolverr v2+ cannot download images.
|
||||
## use_flaresolverr_proxy:true assumes FSv2 and automatically sets
|
||||
## include_images:false
|
||||
## If you want to use FSv1 with images, you can set
|
||||
## use_flaresolverr_proxy:withimages
|
||||
|
||||
#[www.fanfiction.net]
|
||||
#use_flaresolverr_proxy:true
|
||||
## option settings, these are the defaults:
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ def get_valid_set_options():
|
|||
'use_cloudscraper':(None,None,boollist),
|
||||
'use_basic_cache':(None,None,boollist),
|
||||
'use_nsapa_proxy':(None,None,boollist),
|
||||
'use_flaresolverr_proxy':(None,None,boollist),
|
||||
'use_flaresolverr_proxy':(None,None,boollist)+['withimages'],
|
||||
|
||||
## currently, browser_cache_path is assumed to be
|
||||
## shared and only ffnet uses it so far
|
||||
|
|
@ -1004,8 +1004,10 @@ class Configuration(ConfigParser):
|
|||
if self.getConfig('use_flaresolverr_proxy',False):
|
||||
logger.debug("use_flaresolverr_proxy:%s"%self.getConfig('use_flaresolverr_proxy'))
|
||||
fetchcls = flaresolverr_proxy.FlareSolverr_ProxyFetcher
|
||||
logger.warning("FlareSolverr doesn't work with images: include_images automatically set false")
|
||||
self.set('overrides', 'include_images', 'false')
|
||||
if self.getConfig('use_flaresolverr_proxy') != 'withimages':
|
||||
logger.warning("FlareSolverr v2+ doesn't work with images: include_images automatically set false")
|
||||
logger.warning("Set use_flaresolverr_proxy:withimages if your are using FlareSolver v1 and want images")
|
||||
self.set('overrides', 'include_images', 'false')
|
||||
elif self.getConfig('use_nsapa_proxy',False):
|
||||
logger.debug("use_nsapa_proxy:%s"%self.getConfig('use_nsapa_proxy'))
|
||||
fetchcls = nsapa_proxy.NSAPA_ProxyFetcher
|
||||
|
|
|
|||
|
|
@ -571,8 +571,15 @@ browser_cache_age_limit:4.0
|
|||
|
||||
## FlareSolverr (https://github.com/FlareSolverr/FlareSolverr) is a
|
||||
## generic proxy that works with several otherwise blocked sites.
|
||||
## Note that FFF cannot fetch images through FlareSolverr.
|
||||
## It's recommended to only set use_flaresolverr_proxy:true for specific sites.
|
||||
## It's recommended to only set use_flaresolverr_proxy:true for
|
||||
## specific sites.
|
||||
## FlareSolverr v1 doesn't work with some sites anymore (including
|
||||
## ffnet), but FlareSolverr v2+ cannot download images.
|
||||
## use_flaresolverr_proxy:true assumes FSv2 and automatically sets
|
||||
## include_images:false
|
||||
## If you want to use FSv1 with images, you can set
|
||||
## use_flaresolverr_proxy:withimages
|
||||
|
||||
#[www.fanfiction.net]
|
||||
#use_flaresolverr_proxy:true
|
||||
## option settings, these are the defaults:
|
||||
|
|
|
|||
|
|
@ -69,12 +69,15 @@ class FlareSolverr_ProxyFetcher(RequestsFetcher):
|
|||
'url':url,
|
||||
#'userAgent': 'Mozilla/5.0',
|
||||
'maxTimeout': 30000,
|
||||
#'download': True,
|
||||
# download:True causes response to be base64 encoded
|
||||
# which makes images work.
|
||||
'cookies':cookiejar_to_jsonable(self.get_cookiejar()),
|
||||
'postData':encode_params(parameters),
|
||||
}
|
||||
if self.getConfig('use_flaresolverr_proxy') == 'withimages':
|
||||
# download param removed in FlareSolverr v2+, but optional
|
||||
# for FFF users still on FlareSolver v1.
|
||||
fs_data['download'] = True
|
||||
if self.fs_session:
|
||||
fs_data['session']=self.fs_session
|
||||
|
||||
|
|
@ -111,22 +114,33 @@ class FlareSolverr_ProxyFetcher(RequestsFetcher):
|
|||
url = resp.json['solution']['url']
|
||||
for c in cookiejson_to_jarable(resp.json['solution']['cookies']):
|
||||
self.get_cookiejar().set_cookie(c)
|
||||
if resp.json.get('version','').startswith('v2.'):
|
||||
# FlareSolverr v2 detected, don't need base64 decode,
|
||||
# and image downloads won't work.
|
||||
data = None
|
||||
## FSv2 check removed in favor of
|
||||
## use_flaresolverr_proxy:withimages in the hope one day
|
||||
## FS will have download option again.
|
||||
if self.getConfig('use_flaresolverr_proxy') == 'withimages':
|
||||
try:
|
||||
# v1 flaresolverr has 'download' option.
|
||||
data = base64.b64decode(resp.json['solution']['response'])
|
||||
except Exception as e:
|
||||
logger.warning("Base64 decode of FlareSolverr response failed. FSv2 doesn't work with use_flaresolverr_proxy:withimages.")
|
||||
## Allows for user misconfiguration, IE,
|
||||
## use_flaresolverr_proxy:withimages with FSv2. Warning
|
||||
## instead of error out--until they hit an image and crash
|
||||
## FSv2.2 at least. But hopefully that will be fixed.
|
||||
if data is None:
|
||||
# Without download (or with FlareSolverr v2), don't
|
||||
# need base64 decode, and image downloads won't work.
|
||||
if 'image' in resp.json['solution']['headers']['content-type']:
|
||||
raise exceptions.HTTPErrorFFF(
|
||||
url,
|
||||
428, # 404 & 410 trip StoryDoesNotExist
|
||||
# 428 ('Precondition Required') gets the
|
||||
# error_msg through to the user.
|
||||
"FlareSolverr v2 doesn't support image download.",# error_msg
|
||||
"FlareSolverr v2 doesn't support image download (or use_flaresolverr_proxy!=withimages)",# error_msg
|
||||
None # data
|
||||
)
|
||||
data = resp.json['solution']['response']
|
||||
else:
|
||||
# v1 flaresolverr has 'download' option.
|
||||
data = base64.b64decode(resp.json['solution']['response'])
|
||||
else:
|
||||
logger.debug("flaresolverr error resp:")
|
||||
logger.debug(json.dumps(resp.json, sort_keys=True,
|
||||
|
|
|
|||
Loading…
Reference in a new issue