From c20a3b3a01f0cb86e057b3e8e12a319f08c7951b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 3 Oct 2016 08:23:40 +0200 Subject: [PATCH] [*chan] code cleanup --- gallery_dl/extractor/4chan.py | 12 +++--------- gallery_dl/extractor/8chan.py | 12 +++--------- gallery_dl/extractor/chan.py | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/gallery_dl/extractor/4chan.py b/gallery_dl/extractor/4chan.py index 15d19801..bad34c7e 100644 --- a/gallery_dl/extractor/4chan.py +++ b/gallery_dl/extractor/4chan.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015 Mike Fährmann +# Copyright 2015, 2016 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,12 +8,11 @@ """Extract images and videos from https://www.4chan.org/""" -from .chan import ChanExtractor +from . import chan -class FourchanThreadExtractor(ChanExtractor): +class FourchanThreadExtractor(chan.ChanThreadExtractor): """Extractor for images from threads from 4chan.org""" category = "4chan" - subcategory = "thread" pattern = [r"(?:https?://)?boards\.4chan\.org/([^/]+)/thread/(\d+)"] test = [("https://boards.4chan.org/tg/thread/15396072/", { "url": "39082ad166161966d7ba8e37f2173a824eb540f0", @@ -22,8 +21,3 @@ class FourchanThreadExtractor(ChanExtractor): })] api_url = "https://a.4cdn.org/{board}/thread/{thread}.json" file_url = "https://i.4cdn.org/{board}/{tim}{ext}" - - def __init__(self, match): - ChanExtractor.__init__( - self, match.group(1), match.group(2) - ) diff --git a/gallery_dl/extractor/8chan.py b/gallery_dl/extractor/8chan.py index b4468183..526c2905 100644 --- a/gallery_dl/extractor/8chan.py +++ b/gallery_dl/extractor/8chan.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014, 2015 Mike Fährmann +# Copyright 2014-2016 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,12 +8,11 @@ """Extract images and videos from https://8ch.net/""" -from .chan import ChanExtractor +from . import chan -class InfinitychanThreadExtractor(ChanExtractor): +class InfinitychanThreadExtractor(chan.ChanThreadExtractor): """Extractor for images from threads from 8ch.net""" category = "8chan" - subcategory = "thread" pattern = [r"(?:https?://)?(?:www\.)?8ch\.net/([^/]+)/res/(\d+)"] test = [("https://8ch.net/tg/res/175887.html", { "url": "cb03fdc650ad8e796fdab553fbd5489f468d3f45", @@ -22,8 +21,3 @@ class InfinitychanThreadExtractor(ChanExtractor): })] api_url = "https://8ch.net/{board}/res/{thread}.json" file_url = "https://8ch.net/{board}/src/{tim}{ext}" - - def __init__(self, match): - ChanExtractor.__init__( - self, match.group(1), match.group(2) - ) diff --git a/gallery_dl/extractor/chan.py b/gallery_dl/extractor/chan.py index 8e5aed3c..086f251d 100644 --- a/gallery_dl/extractor/chan.py +++ b/gallery_dl/extractor/chan.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015 Mike Fährmann +# Copyright 2015, 2016 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 @@ -11,34 +11,37 @@ from .common import Extractor, Message from .. import text -class ChanExtractor(Extractor): +class ChanThreadExtractor(Extractor): """Base class for extractors for Futaba Channel boards""" + category = "chan" + subcategory = "thread" directory_fmt = ["{category}", "{board}-{thread}"] filename_fmt = "{tim}-{filename}{ext}" api_url = "" file_url = "" - def __init__(self, board, thread): + def __init__(self, match): Extractor.__init__(self) self.metadata = { - "board": board, - "thread": thread, + "board": match.group(1), + "thread": match.group(2), } def items(self): yield Message.Version, 1 - posts = self.request(self.api_url.format(**self.metadata)).json()["posts"] + url = self.api_url.format_map(self.metadata) + posts = self.request(url).json()["posts"] self.metadata["title"] = self.get_thread_title(posts[0]) yield Message.Directory, self.metadata for post in posts: if "filename" not in post: continue post.update(self.metadata) - yield Message.Url, self.file_url.format(**post), post + yield Message.Url, self.file_url.format_map(post), post if "extra_files" in post: for file in post["extra_files"]: post.update(file) - yield Message.Url, self.file_url.format(**post), post + yield Message.Url, self.file_url.format_map(post), post @staticmethod def get_thread_title(post):