implement (sub)category-transfer between extractors (#41)
ImageFap- and all Manga-Extractors will transfer their (sub)category values to other extractors instantiated by them, which will in turn allow those to use options set for their parents. Example: ImagefapGalleryExtractors will use options set under extractor.imagefap.user, if (and only if) they have been instantiated by a ImagefapUserExtractor; and options from extractor.imagefap.gallery otherwise.
This commit is contained in:
@@ -25,6 +25,7 @@ class Extractor():
|
|||||||
|
|
||||||
category = ""
|
category = ""
|
||||||
subcategory = ""
|
subcategory = ""
|
||||||
|
categorytransfer = False
|
||||||
directory_fmt = ["{category}"]
|
directory_fmt = ["{category}"]
|
||||||
filename_fmt = "{filename}"
|
filename_fmt = "{filename}"
|
||||||
cookiedomain = ""
|
cookiedomain = ""
|
||||||
@@ -147,6 +148,7 @@ class AsynchronousExtractor(Extractor):
|
|||||||
class MangaExtractor(Extractor):
|
class MangaExtractor(Extractor):
|
||||||
|
|
||||||
subcategory = "manga"
|
subcategory = "manga"
|
||||||
|
categorytransfer = True
|
||||||
scheme = "http"
|
scheme = "http"
|
||||||
root = ""
|
root = ""
|
||||||
reverse = True
|
reverse = True
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ class ImagefapUserExtractor(Extractor):
|
|||||||
"""Extractor for all galleries from a user at imagefap.com"""
|
"""Extractor for all galleries from a user at imagefap.com"""
|
||||||
category = "imagefap"
|
category = "imagefap"
|
||||||
subcategory = "user"
|
subcategory = "user"
|
||||||
directory_fmt = ["{category}", "{gallery_id} {title}"]
|
categorytransfer = True
|
||||||
filename_fmt = "{category}_{gallery_id}_{name}.{extension}"
|
|
||||||
pattern = [(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
pattern = [(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
||||||
r"profile(?:\.php\?user=|/)([^/]+)"),
|
r"profile(?:\.php\?user=|/)([^/]+)"),
|
||||||
(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
||||||
|
|||||||
@@ -121,6 +121,12 @@ class Job():
|
|||||||
kwdict["category"] = self.extractor.category
|
kwdict["category"] = self.extractor.category
|
||||||
kwdict["subcategory"] = self.extractor.subcategory
|
kwdict["subcategory"] = self.extractor.subcategory
|
||||||
|
|
||||||
|
def _prepare(self, job):
|
||||||
|
if self.extractor.categorytransfer:
|
||||||
|
job.extractor.category = self.extractor.category
|
||||||
|
job.extractor.subcategory = self.extractor.subcategory
|
||||||
|
return job
|
||||||
|
|
||||||
def _write_unsupported(self, url):
|
def _write_unsupported(self, url):
|
||||||
if self.ufile:
|
if self.ufile:
|
||||||
print(url, file=self.ufile, flush=True)
|
print(url, file=self.ufile, flush=True)
|
||||||
@@ -150,7 +156,7 @@ class DownloadJob(Job):
|
|||||||
|
|
||||||
def handle_queue(self, url, keywords):
|
def handle_queue(self, url, keywords):
|
||||||
try:
|
try:
|
||||||
DownloadJob(url).run()
|
self._prepare(DownloadJob(url)).run()
|
||||||
except exception.NoExtractorError:
|
except exception.NoExtractorError:
|
||||||
self._write_unsupported(url)
|
self._write_unsupported(url)
|
||||||
|
|
||||||
@@ -183,9 +189,18 @@ class KeywordJob(Job):
|
|||||||
self.print_keywords(keywords)
|
self.print_keywords(keywords)
|
||||||
|
|
||||||
def handle_queue(self, url, keywords):
|
def handle_queue(self, url, keywords):
|
||||||
print("Keywords for chapter filters:")
|
if not keywords:
|
||||||
print("-----------------------------")
|
self.extractor.log.info(
|
||||||
self.print_keywords(keywords)
|
"This extractor transfers work to other extractors "
|
||||||
|
"and does not provide any keywords on its own. Try "
|
||||||
|
"'gallery-dl -K \"%s\"' instead.", url)
|
||||||
|
else:
|
||||||
|
print("Keywords for --chapter-filter:")
|
||||||
|
print("------------------------------")
|
||||||
|
self.print_keywords(keywords)
|
||||||
|
if self.extractor.categorytransfer:
|
||||||
|
print()
|
||||||
|
self._prepare(KeywordJob(url)).run()
|
||||||
raise exception.StopExtraction()
|
raise exception.StopExtraction()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -227,7 +242,7 @@ class UrlJob(Job):
|
|||||||
|
|
||||||
def handle_queue(self, url, _):
|
def handle_queue(self, url, _):
|
||||||
try:
|
try:
|
||||||
UrlJob(url, self.depth + 1).run()
|
self._prepare(UrlJob(url, self.depth + 1)).run()
|
||||||
except exception.NoExtractorError:
|
except exception.NoExtractorError:
|
||||||
self._write_unsupported(url)
|
self._write_unsupported(url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user