mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-26 04:32:51 +01:00
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:
parent
1ab4c7986f
commit
26a866e7d8
@ -25,6 +25,7 @@ class Extractor():
|
||||
|
||||
category = ""
|
||||
subcategory = ""
|
||||
categorytransfer = False
|
||||
directory_fmt = ["{category}"]
|
||||
filename_fmt = "{filename}"
|
||||
cookiedomain = ""
|
||||
@ -147,6 +148,7 @@ class AsynchronousExtractor(Extractor):
|
||||
class MangaExtractor(Extractor):
|
||||
|
||||
subcategory = "manga"
|
||||
categorytransfer = True
|
||||
scheme = "http"
|
||||
root = ""
|
||||
reverse = True
|
||||
|
@ -136,8 +136,7 @@ class ImagefapUserExtractor(Extractor):
|
||||
"""Extractor for all galleries from a user at imagefap.com"""
|
||||
category = "imagefap"
|
||||
subcategory = "user"
|
||||
directory_fmt = ["{category}", "{gallery_id} {title}"]
|
||||
filename_fmt = "{category}_{gallery_id}_{name}.{extension}"
|
||||
categorytransfer = True
|
||||
pattern = [(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
||||
r"profile(?:\.php\?user=|/)([^/]+)"),
|
||||
(r"(?:https?://)?(?:www\.)?imagefap\.com/"
|
||||
|
@ -121,6 +121,12 @@ class Job():
|
||||
kwdict["category"] = self.extractor.category
|
||||
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):
|
||||
if self.ufile:
|
||||
print(url, file=self.ufile, flush=True)
|
||||
@ -150,7 +156,7 @@ class DownloadJob(Job):
|
||||
|
||||
def handle_queue(self, url, keywords):
|
||||
try:
|
||||
DownloadJob(url).run()
|
||||
self._prepare(DownloadJob(url)).run()
|
||||
except exception.NoExtractorError:
|
||||
self._write_unsupported(url)
|
||||
|
||||
@ -183,9 +189,18 @@ class KeywordJob(Job):
|
||||
self.print_keywords(keywords)
|
||||
|
||||
def handle_queue(self, url, keywords):
|
||||
print("Keywords for chapter filters:")
|
||||
print("-----------------------------")
|
||||
self.print_keywords(keywords)
|
||||
if not keywords:
|
||||
self.extractor.log.info(
|
||||
"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()
|
||||
|
||||
@staticmethod
|
||||
@ -227,7 +242,7 @@ class UrlJob(Job):
|
||||
|
||||
def handle_queue(self, url, _):
|
||||
try:
|
||||
UrlJob(url, self.depth + 1).run()
|
||||
self._prepare(UrlJob(url, self.depth + 1)).run()
|
||||
except exception.NoExtractorError:
|
||||
self._write_unsupported(url)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user