From a33b13c631a32dd2e4717c5b6219123d30379957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 15 Oct 2016 23:06:54 +0200 Subject: [PATCH] [8chan] fix file urls --- gallery_dl/extractor/8chan.py | 10 ++++++++-- gallery_dl/extractor/chan.py | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/8chan.py b/gallery_dl/extractor/8chan.py index f6b6904d..6882fddd 100644 --- a/gallery_dl/extractor/8chan.py +++ b/gallery_dl/extractor/8chan.py @@ -13,11 +13,17 @@ from . import chan class InfinitychanThreadExtractor(chan.ChanThreadExtractor): """Extractor for images from threads from 8ch.net""" category = "8chan" + filename_fmt = "{time}-{filename}{ext}" pattern = [r"(?:https?://)?(?:www\.)?8ch\.net/([^/]+)/res/(\d+)"] test = [("https://8ch.net/tg/res/175887.html", { - "url": "cb03fdc650ad8e796fdab553fbd5489f468d3f45", + "url": "646d4230b40f9cff3f8674e3efe44bba3af4924b", "keyword": "d313fa77f689ddcd45736f1e86bf63cf58614786", "content": "81e21a3cc87f64f224a966f207e8e1731216c345", })] api_url = "https://8ch.net/{board}/res/{thread}.json" - file_url = "https://8ch.net/{board}/src/{tim}{ext}" + file_url = "https://media.8ch.net/{board}/src/{tim}{ext}" + file_url_v2 = "https://media.8ch.net/file_store/{tim}{ext}" + + def build_url(self, post): + fmt = self.file_url if len(post["tim"]) < 64 else self.file_url_v2 + return fmt.format_map(post) diff --git a/gallery_dl/extractor/chan.py b/gallery_dl/extractor/chan.py index 8e0b1e77..d06d4b95 100644 --- a/gallery_dl/extractor/chan.py +++ b/gallery_dl/extractor/chan.py @@ -37,17 +37,21 @@ class ChanThreadExtractor(Extractor): if "filename" not in post: continue self.update(post) - yield Message.Url, self.file_url.format_map(post), post + yield Message.Url, self.build_url(post), post if "extra_files" in post: for file in post["extra_files"]: self.update(post, file) - yield Message.Url, self.file_url.format_map(post), post + yield Message.Url, self.build_url(post), post def update(self, post, data=None): """Update keyword dictionary""" post.update(data or self.metadata) post["extension"] = post["ext"][1:] + def build_url(self, post): + """Construct an image url out of a post object""" + return self.file_url.format_map(post) + @staticmethod def get_thread_title(post): """Return thread title from first post"""