Skip to content

Commit

Permalink
merge #6113: [weasyl:favorite] fix pagination, support readable URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 25, 2024
2 parents 3eb3564 + 9d7f8f8 commit 050d87d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 17 additions & 11 deletions gallery_dl/extractor/weasyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,26 @@ 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+)|/([^/?#]+))"
example = "https://www.weasyl.com/favorites?userid=12345"

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

def items(self):
userid, username = self.groups
owner_login = lastid = None
url = self.root + "/favorites"

if username:
owner_login = username
path = "/favorites/" + username
else:
path = "/favorites"
params = {
"userid" : self.userid,
"userid" : userid,
"feature": "submit",
}

while True:
page = self.request(url, params=params).text
page = self.request(self.root + path, params=params).text
pos = page.index('id="favorites-content"')

if not owner_login:
Expand All @@ -186,12 +188,16 @@ def items(self):
if submitid == lastid:
continue
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 "&nextid=" not in page:
try:
pos = page.index('">Next (', pos)
except ValueError:
return
params["nextid"] = submitid
path = text.unescape(text.rextract(page, 'href="', '"', pos)[0])
params = None
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",
}

)

0 comments on commit 050d87d

Please sign in to comment.