fix --range causing crashes (#4557)

regression caused by a383eca7
This commit is contained in:
Mike Fährmann
2023-09-21 23:14:08 +02:00
parent 3528974459
commit 2cd801232b
5 changed files with 29 additions and 7 deletions

View File

@@ -39,6 +39,7 @@ class DeviantartExtractor(Extractor):
def __init__(self, match): def __init__(self, match):
Extractor.__init__(self, match) Extractor.__init__(self, match)
self.user = match.group(1) or match.group(2) self.user = match.group(1) or match.group(2)
self.offset = 0
def _init(self): def _init(self):
self.flat = self.config("flat", True) self.flat = self.config("flat", True)
@@ -48,7 +49,6 @@ class DeviantartExtractor(Extractor):
self.api = DeviantartOAuthAPI(self) self.api = DeviantartOAuthAPI(self)
self.group = False self.group = False
self.offset = 0
self._premium_cache = {} self._premium_cache = {}
unwatch = self.config("auto-unwatch") unwatch = self.config("auto-unwatch")
@@ -445,6 +445,8 @@ class DeviantartUserExtractor(DeviantartExtractor):
def initialize(self): def initialize(self):
pass pass
skip = Extractor.skip
def items(self): def items(self):
base = "{}/{}/".format(self.root, self.user) base = "{}/{}/".format(self.root, self.user)
return self._dispatch_extractors(( return self._dispatch_extractors((

View File

@@ -28,9 +28,9 @@ class FuraffinityExtractor(Extractor):
def __init__(self, match): def __init__(self, match):
Extractor.__init__(self, match) Extractor.__init__(self, match)
self.user = match.group(1) self.user = match.group(1)
self.offset = 0
def _init(self): def _init(self):
self.offset = 0
self.external = self.config("external", False) self.external = self.config("external", False)
if self.config("descriptions") == "html": if self.config("descriptions") == "html":
@@ -295,6 +295,8 @@ class FuraffinityUserExtractor(FuraffinityExtractor):
def initialize(self): def initialize(self):
pass pass
skip = Extractor.skip
def items(self): def items(self):
base = "{}/{{}}/{}/".format(self.root, self.user) base = "{}/{{}}/{}/".format(self.root, self.user)
return self._dispatch_extractors(( return self._dispatch_extractors((

View File

@@ -106,16 +106,15 @@ class Job():
"current_git_head": util.git_head() "current_git_head": util.git_head()
} }
# predicates
self.pred_url = self._prepare_predicates("image", True)
self.pred_queue = self._prepare_predicates("chapter", False)
def run(self): def run(self):
"""Execute or run the job""" """Execute or run the job"""
extractor = self.extractor extractor = self.extractor
log = extractor.log log = extractor.log
msg = None msg = None
self._init()
# sleep before extractor start
sleep = util.build_duration_func( sleep = util.build_duration_func(
extractor.config("sleep-extractor")) extractor.config("sleep-extractor"))
if sleep: if sleep:
@@ -201,6 +200,11 @@ class Job():
if self.kwdict: if self.kwdict:
kwdict.update(self.kwdict) kwdict.update(self.kwdict)
def _init(self):
self.extractor.initialize()
self.pred_url = self._prepare_predicates("image", True)
self.pred_queue = self._prepare_predicates("chapter", False)
def _prepare_predicates(self, target, skip=True): def _prepare_predicates(self, target, skip=True):
predicates = [] predicates = []
@@ -810,6 +814,8 @@ class DataJob(Job):
self.filter = dict.copy if private else util.filter_dict self.filter = dict.copy if private else util.filter_dict
def run(self): def run(self):
self._init()
extractor = self.extractor extractor = self.extractor
sleep = util.build_duration_func( sleep = util.build_duration_func(
extractor.config("sleep-extractor")) extractor.config("sleep-extractor"))

View File

@@ -37,7 +37,7 @@ __tests__ = (
"#category": ("", "deviantart", "gallery"), "#category": ("", "deviantart", "gallery"),
"#class" : deviantart.DeviantartGalleryExtractor, "#class" : deviantart.DeviantartGalleryExtractor,
"#pattern" : r"https://(images-)?wixmp-[^.]+\.wixmp\.com/f/.+/.+\.(jpg|png)\?token=.+", "#pattern" : r"https://(images-)?wixmp-[^.]+\.wixmp\.com/f/.+/.+\.(jpg|png)\?token=.+",
"#count" : ">= 30", "#count" : ">= 38",
"allows_comments" : bool, "allows_comments" : bool,
"author" : { "author" : {
@@ -82,6 +82,17 @@ __tests__ = (
"username" : "shimoda7", "username" : "shimoda7",
}, },
{
"#url" : "https://www.deviantart.com/shimoda7/gallery/",
"#comment" : "range/skip (#4557)",
"#category": ("", "deviantart", "gallery"),
"#class" : deviantart.DeviantartGalleryExtractor,
"#options" : {"original": False},
"#pattern" : r"https://images-wixmp-[0-9a-f]+\.wixmp\.com/f/0e474835-ec35-4937-b647-b6830ed58bd1/d2idul-6158ded2-37ac-413d-802e-0689f0f020ad\.jpg\?token=[\w.]+",
"#range" : "38-",
"#count" : 1,
},
{ {
"#url" : "https://www.deviantart.com/yakuzafc/gallery", "#url" : "https://www.deviantart.com/yakuzafc/gallery",
"#comment" : "group", "#comment" : "group",

View File

@@ -206,6 +206,7 @@ class ResultJob(job.DownloadJob):
self.extractor.filename_fmt).format_map self.extractor.filename_fmt).format_map
def run(self): def run(self):
self._init()
for msg in self.extractor: for msg in self.extractor:
self.dispatch(msg) self.dispatch(msg)