1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

[8chan] fix file urls

This commit is contained in:
Mike Fährmann 2016-10-15 23:06:54 +02:00
parent ffc3c2d32c
commit a33b13c631
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -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"""