| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://www.dcinside.com/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor, Extractor, Message |
| 12 |
from .. import text |
| 13 |
|
| 14 |
|
| 15 |
class DcinsideGalleryExtractor(GalleryExtractor): |
| 16 |
category = "dcinside" |
| 17 |
subcategory = "gallery" |
| 18 |
root = "https://gall.dcinside.com" |
| 19 |
directory_fmt = ("{category}", "{username}") |
| 20 |
filename_fmt = "{id} {title} {num:>02}.{extension}" |
| 21 |
archive_fmt = "{id}_{num}" |
| 22 |
pattern = (r"(?:https?://)?gall\.dcinside\.com" |
| 23 |
r"(/(?:mgallery/)?board/view/?\?([^#]+))") |
| 24 |
example = "https://gall.dcinside.com/board/view/?id=ID&no=12345" |
| 25 |
|
| 26 |
def metadata(self, page): |
| 27 |
|
| 28 |
|
| 29 |
extr = text.extract_from(page) |
| 30 |
params = text.parse_query(self.groups[1]) |
| 31 |
|
| 32 |
return { |
| 33 |
"id" : text.parse_int(params.get("no")), |
| 34 |
"title" : extr('"headline":"', '",\r'), |
| 35 |
"content" : extr('"articleBody":"', '",\r'), |
| 36 |
"date" : self.parse_datetime_iso(extr( |
| 37 |
'"datePublished":"', '"')), |
| 38 |
"display_name" : extr('"name":"', '",\r'), |
| 39 |
"username" : extr('"url":"https://gallog.dcinside.com/', '"'), |
| 40 |
"comments" : text.parse_int(extr( |
| 41 |
'"userInteractionCount": ', ' ')), |
| 42 |
"views" : text.parse_int(extr( |
| 43 |
'"userInteractionCount": ', ' ')), |
| 44 |
"_http_headers": {"Accept-Encoding": "identity"}, |
| 45 |
} |
| 46 |
|
| 47 |
def images(self, page): |
| 48 |
if box := text.extr(page, 'class="writing_view_box', "\t</div>"): |
| 49 |
results = [] |
| 50 |
for img in text.extract_iter(box, "<img", ">"): |
| 51 |
url = text.unescape(text.extr(img, ' src="', '"')) |
| 52 |
results.append((url, { |
| 53 |
"hash" : text.extr(img, ' alt="', '"'), |
| 54 |
"extension": "jpg", |
| 55 |
})) |
| 56 |
return results |
| 57 |
|
| 58 |
if image := text.extr(page, '"image":{', '}'): |
| 59 |
url = text.extr(image, '"URL":"', '"') |
| 60 |
return ((url, {"extension": "jpg"}),) |
| 61 |
|
| 62 |
|
| 63 |
class DcinsideUserExtractor(Extractor): |
| 64 |
category = "dcinside" |
| 65 |
subcategory = "user" |
| 66 |
root = "https://gallog.dcinside.com" |
| 67 |
pattern = (r"(?:https?://)?gallog\.dcinside\.com/([^/?#]+)" |
| 68 |
r"(?:(/posting(?:/index)?)/?\?([^#]+))?") |
| 69 |
example = "https://gallog.dcinside.com/USER" |
| 70 |
|
| 71 |
def items(self): |
| 72 |
username, path, query = self.groups |
| 73 |
url = f"{self.root}/{username}{path or '/posting'}" |
| 74 |
params = text.parse_query(query) |
| 75 |
params["p"] = text.parse_int(params.get("p"), 1) |
| 76 |
|
| 77 |
data = {"_extractor": DcinsideGalleryExtractor} |
| 78 |
while True: |
| 79 |
page = self.request(url, params=params).text |
| 80 |
|
| 81 |
for href in text.extract_iter( |
| 82 |
page, '<a class="link " href="', '"'): |
| 83 |
yield Message.Queue, text.unescape(href), data |
| 84 |
|
| 85 |
if "</em><a href=" not in page: |
| 86 |
break |
| 87 |
params["p"] += 1 |