Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[smugloli] add smugloli extractors #3060

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ Consider all sites to be NSFW unless otherwise known.
<td>Presentations</td>
<td></td>
</tr>
<tr>
<td>Smugloli</td>
<td>https://smuglo.li/</td>
<td>Boards, Threads</td>
<td></td>
</tr>
<tr>
<td>SmugMug</td>
<td>https://www.smugmug.com/</td>
Expand Down
1 change: 1 addition & 0 deletions gallery_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"foolslide",
"mastodon",
"shopify",
"smugloli",
"lolisafe",
"imagehosts",
"directlink",
Expand Down
98 changes: 98 additions & 0 deletions gallery_dl/extractor/smugloli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-

# 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
# published by the Free Software Foundation.

"""Extractors for https://smuglo.li/"""

from .common import Extractor, Message
from .. import text


class SmugloliThreadExtractor(Extractor):
"""Extractor for smugloli threads"""
category = "smugloli"
subcategory = "thread"
directory_fmt = ("{category}", "{board}", "{thread} {title}")
filename_fmt = "{time}{num:?-//} {filename}.{extension}"
archive_fmt = "{board}_{thread}_{tim}"
pattern = r"(?:https?://)?(smuglo(?:\.li|li\.net))/([^/]+)/res/(\d+)\.html"
test = (
("https://smuglo.li/a/res/1154380.html", {
"pattern": r"https://smug.+/a/src/\d+(-\d)?\.\w+",
"count": ">= 18",
"keyword": {
"board": "a",
"thread": "1154380",
"title": "Mob Psycho 100 Season 3",
},
}),
("https://smugloli.net/a/res/1145409.html"),
)

def __init__(self, match):
Extractor.__init__(self, match)
self.domain, self.board, self.thread = match.groups()

def items(self):
url = "https://{}/{}/res/{}.json".format(
self.domain, self.board, self.thread)
posts = self.request(url).json()["posts"]
title = posts[0].get("sub") or text.remove_html(posts[0]["com"])
process = self._process

data = {
"board" : self.board,
"thread": self.thread,
"title" : text.unescape(title)[:50],
"num" : 0,
}

yield Message.Directory, data
for post in posts:
if "filename" in post:
yield process(post, data)
if "extra_files" in post:
for post["num"], filedata in enumerate(
post["extra_files"], 1):
yield process(post, filedata)

def _process(self, post, data):
post.update(data)
post["extension"] = post["ext"][1:]
post["url"] = "https://{}/{}/src/{}{}".format(
self.domain, post["board"], post["tim"], post["ext"])
return Message.Url, post["url"], post


class SmugloliBoardExtractor(Extractor):
"""Extractor for smugloli boards"""
category = "smugloli"
subcategory = "board"
pattern = (r"(?:https?://)?(smuglo(?:\.li|li\.net))"
r"/([^/?#]+)(?:/(?:index|catalog|\d{1,2})\.html)?/?$")
test = (
("https://smuglo.li/a/", {
"pattern": SmugloliThreadExtractor.pattern,
"count": ">= 100",
}),
("https://smuglo.li/a/1.html"),
("https://smuglo.li/cute/catalog.html"),
)

def __init__(self, match):
Extractor.__init__(self, match)
self.domain, self.board = match.groups()

def items(self):
url = "https://{}/{}/threads.json".format(self.domain, self.board)
threads = self.request(url).json()

for page in threads:
for thread in page["threads"]:
url = "{}/{}/res/{}.html".format(
self.domain, self.board, thread["no"])
thread["page"] = page["page"]
thread["_extractor"] = SmugloliThreadExtractor
yield Message.Queue, url, thread