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

[weasyl] Fix favourites extractor and add support for the readable URL format #6113

Merged
merged 5 commits into from
Sep 25, 2024
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
18 changes: 15 additions & 3 deletions gallery_dl/extractor/weasyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,25 @@ def items(self):

class WeasylFavoriteExtractor(WeasylExtractor):
subcategory = "favorite"
directory_fmt = ("{category}", "{owner_login}", "Favorites")
pattern = BASE_PATTERN + r"favorites\?userid=(\d+)"
directory_fmt = ("{category}", "{user}", "Favorites")
pattern = BASE_PATTERN + r"favorites(?:\?userid=(\d+)|\/([\w~-]+))"
example = "https://www.weasyl.com/favorites?userid=12345"

def __init__(self, match):
WeasylExtractor.__init__(self, match)
self.userid = match.group(1)
self.username = match.group(2)

def items(self):
if self.userid is None and self.username is not None:
new_url = self.root + "/favorites/{}".format(self.username)
page = self.request(new_url).text
self.userid = text.extr(
page,
'<a class="more" href="/favorites?userid=',
'&amp'
)

owner_login = lastid = None
url = self.root + "/favorites"
params = {
Expand All @@ -182,16 +192,18 @@ def items(self):
if not owner_login:
owner_login = text.extr(page, '<a href="/~', '"')

new_posts = False
for submitid in text.extract_iter(page, "/submissions/", "/", pos):
if submitid == lastid:
continue
new_posts = True
lastid = submitid
submission = self.request_submission(submitid)
if self.populate_submission(submission):
submission["user"] = owner_login
yield Message.Directory, submission
yield Message.Url, submission["url"], submission

if "&amp;nextid=" not in page:
if not new_posts:
return
params["nextid"] = submitid
7 changes: 7 additions & 0 deletions test/results/weasyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@
"#count" : ">= 5",
},

{
"#url" : "https://www.weasyl.com/favorites/furoferre",
"#category": ("", "weasyl", "favorite"),
"#class" : weasyl.WeasylFavoriteExtractor,
"#count" : ">= 5",
}

)
Loading