replace SharedConfigExtractor class with a Mixin
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015-2018 Mike Fährmann
|
||||
# Copyright 2015-2019 Mike Fährmann
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
"""Base classes for extractors for danbooru and co"""
|
||||
|
||||
from .common import SharedConfigExtractor, Message
|
||||
from .common import Extractor, Message, SharedConfigMixin
|
||||
from .. import text, exception
|
||||
from xml.etree import ElementTree
|
||||
import collections
|
||||
@@ -17,7 +17,7 @@ import operator
|
||||
import re
|
||||
|
||||
|
||||
class BooruExtractor(SharedConfigExtractor):
|
||||
class BooruExtractor(SharedConfigMixin, Extractor):
|
||||
"""Base class for all booru extractors"""
|
||||
basecategory = "booru"
|
||||
filename_fmt = "{category}_{id}_{md5}.{extension}"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2014-2018 Mike Fährmann
|
||||
# Copyright 2014-2019 Mike Fährmann
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
@@ -287,11 +287,11 @@ class MangaExtractor(Extractor):
|
||||
"""Return a list of all (chapter-url, metadata)-tuples"""
|
||||
|
||||
|
||||
class SharedConfigExtractor(Extractor):
|
||||
|
||||
class SharedConfigMixin():
|
||||
"""Enable sharing of config settings based on 'basecategory'"""
|
||||
basecategory = ""
|
||||
|
||||
def config(self, key, default=None, sentinel=object()):
|
||||
def config(self, key, default=None, *, sentinel=object()):
|
||||
value = Extractor.config(self, key, sentinel)
|
||||
if value is sentinel:
|
||||
cat, self.category = self.category, self.basecategory
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
"""Extractors for 4chan archives based on FoolFuuka"""
|
||||
|
||||
from .common import SharedConfigExtractor, Message
|
||||
from .common import Extractor, Message, SharedConfigMixin
|
||||
from .. import text, config
|
||||
import itertools
|
||||
import operator
|
||||
import re
|
||||
|
||||
|
||||
class FoolfuukaThreadExtractor(SharedConfigExtractor):
|
||||
class FoolfuukaThreadExtractor(SharedConfigMixin, Extractor):
|
||||
"""Base extractor for FoolFuuka based boards/archives"""
|
||||
basecategory = "foolfuuka"
|
||||
subcategory = "thread"
|
||||
@@ -26,7 +26,7 @@ class FoolfuukaThreadExtractor(SharedConfigExtractor):
|
||||
root = ""
|
||||
|
||||
def __init__(self, match):
|
||||
SharedConfigExtractor.__init__(self)
|
||||
Extractor.__init__(self)
|
||||
self.board, self.thread = match.groups()
|
||||
self.session.headers["Referer"] = self.root
|
||||
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
|
||||
"""Extractors for FoOlSlide based sites"""
|
||||
|
||||
from .common import SharedConfigExtractor, MangaExtractor, Message
|
||||
from .common import Extractor, MangaExtractor, Message, SharedConfigMixin
|
||||
from .. import text, util, config
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
|
||||
|
||||
class FoolslideExtractor(SharedConfigExtractor):
|
||||
class FoolslideBase(SharedConfigMixin):
|
||||
"""Base class for FoOlSlide extractors"""
|
||||
basecategory = "foolslide"
|
||||
|
||||
def request(self, url):
|
||||
return SharedConfigExtractor.request(
|
||||
return Extractor.request(
|
||||
self, url, encoding="utf-8", method="POST", data={"adult": "true"})
|
||||
|
||||
@staticmethod
|
||||
@@ -35,7 +35,7 @@ class FoolslideExtractor(SharedConfigExtractor):
|
||||
return data
|
||||
|
||||
|
||||
class FoolslideChapterExtractor(FoolslideExtractor):
|
||||
class FoolslideChapterExtractor(FoolslideBase, Extractor):
|
||||
"""Base class for chapter extractors for FoOlSlide based sites"""
|
||||
subcategory = "chapter"
|
||||
directory_fmt = [
|
||||
@@ -46,7 +46,7 @@ class FoolslideChapterExtractor(FoolslideExtractor):
|
||||
decode = "default"
|
||||
|
||||
def __init__(self, match):
|
||||
FoolslideExtractor.__init__(self)
|
||||
Extractor.__init__(self)
|
||||
self.url = self.root + match.group(1)
|
||||
|
||||
def items(self):
|
||||
@@ -98,12 +98,11 @@ class FoolslideChapterExtractor(FoolslideExtractor):
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
class FoolslideMangaExtractor(FoolslideExtractor, MangaExtractor):
|
||||
class FoolslideMangaExtractor(FoolslideBase, MangaExtractor):
|
||||
"""Base class for manga extractors for FoOlSlide based sites"""
|
||||
|
||||
def __init__(self, match):
|
||||
FoolslideExtractor.__init__(self)
|
||||
self.url = self.root + match.group(1)
|
||||
MangaExtractor.__init__(self, match, self.root + match.group(1))
|
||||
|
||||
def chapters(self, page):
|
||||
"""Return a list of all chapter urls"""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Mike Fährmann
|
||||
# Copyright 2018-2019 Mike Fährmann
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
"""Extract images from https://rule34.paheal.net/"""
|
||||
|
||||
from .common import SharedConfigExtractor, Message
|
||||
from .common import Extractor, Message, SharedConfigMixin
|
||||
from .. import text
|
||||
|
||||
|
||||
class PahealExtractor(SharedConfigExtractor):
|
||||
class PahealExtractor(SharedConfigMixin, Extractor):
|
||||
"""Base class for paheal extractors"""
|
||||
basecategory = "booru"
|
||||
category = "paheal"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
"""Generic extractors for *reactor sites"""
|
||||
|
||||
from .common import SharedConfigExtractor, Message
|
||||
from .common import Extractor, Message, SharedConfigMixin
|
||||
from .. import text
|
||||
import urllib.parse
|
||||
import random
|
||||
@@ -19,7 +19,7 @@ import json
|
||||
BASE_PATTERN = r"(?:https?://)?([^/.]+\.reactor\.cc)"
|
||||
|
||||
|
||||
class ReactorExtractor(SharedConfigExtractor):
|
||||
class ReactorExtractor(SharedConfigMixin, Extractor):
|
||||
"""Base class for *reactor.cc extractors"""
|
||||
basecategory = "reactor"
|
||||
directory_fmt = ["{category}"]
|
||||
@@ -27,7 +27,7 @@ class ReactorExtractor(SharedConfigExtractor):
|
||||
archive_fmt = "{post_id}_{num}"
|
||||
|
||||
def __init__(self, match):
|
||||
SharedConfigExtractor.__init__(self)
|
||||
Extractor.__init__(self)
|
||||
self.url = match.group(0)
|
||||
self.root = "http://" + match.group(1)
|
||||
self.session.headers["Referer"] = self.root
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
"""Extract images from https://chan.sankakucomplex.com/"""
|
||||
|
||||
from .common import SharedConfigExtractor, Message
|
||||
from .common import Extractor, Message, SharedConfigMixin
|
||||
from .. import text, util, exception
|
||||
from ..cache import cache
|
||||
import collections
|
||||
@@ -17,7 +17,7 @@ import time
|
||||
import re
|
||||
|
||||
|
||||
class SankakuExtractor(SharedConfigExtractor):
|
||||
class SankakuExtractor(SharedConfigMixin, Extractor):
|
||||
"""Base class for sankaku extractors"""
|
||||
basecategory = "booru"
|
||||
category = "sankaku"
|
||||
@@ -27,7 +27,7 @@ class SankakuExtractor(SharedConfigExtractor):
|
||||
subdomain = "chan"
|
||||
|
||||
def __init__(self):
|
||||
SharedConfigExtractor.__init__(self)
|
||||
Extractor.__init__(self)
|
||||
self.root = "https://" + self.cookiedomain
|
||||
self.logged_in = True
|
||||
self.start_page = 1
|
||||
|
||||
Reference in New Issue
Block a user