[scrolller] support album posts (#7339)

This commit is contained in:
Mike Fährmann
2025-04-24 16:31:12 +02:00
parent 4b855b1565
commit 25e8a98547
2 changed files with 44 additions and 20 deletions

View File

@@ -20,8 +20,8 @@ class ScrolllerExtractor(Extractor):
category = "scrolller" category = "scrolller"
root = "https://scrolller.com" root = "https://scrolller.com"
directory_fmt = ("{category}", "{subredditTitle}") directory_fmt = ("{category}", "{subredditTitle}")
filename_fmt = "{id}{title:? //}.{extension}" filename_fmt = "{id}{num:?_//>03}{title:? //}.{extension}"
archive_fmt = "{id}" archive_fmt = "{id}_{num}"
request_interval = (0.5, 1.5) request_interval = (0.5, 1.5)
def _init(self): def _init(self):
@@ -31,23 +31,36 @@ class ScrolllerExtractor(Extractor):
self.login() self.login()
for post in self.posts(): for post in self.posts():
files = self._extract_files(post)
media_sources = post.get("mediaSources") post["count"] = len(files)
if not media_sources:
self.log.warning("%s: No media files", post.get("id"))
continue
src = max(media_sources, key=self._sort_key)
post.update(src)
url = src["url"]
text.nameext_from_url(url, post)
yield Message.Directory, post yield Message.Directory, post
yield Message.Url, url, post for file in files:
url = file["url"]
post.update(file)
yield Message.Url, url, text.nameext_from_url(url, post)
def posts(self): def posts(self):
return () return ()
def _extract_files(self, post):
album = post.pop("albumContent", None)
if not album:
sources = post.get("mediaSources")
if not sources:
self.log.warning("%s: No media files", post.get("id"))
return ()
src = max(sources, key=self._sort_key)
src["num"] = 0
return (src,)
files = []
for num, media in enumerate(album, 1):
src = max(media["mediaSources"], key=self._sort_key)
src["num"] = num
files.append(src)
return files
def login(self): def login(self):
username, password = self._get_auth_info() username, password = self._get_auth_info()
if username: if username:

View File

@@ -43,34 +43,45 @@ __tests__ = (
{ {
"#url" : "https://scrolller.com/cabin-in-northern-finland-7nagf1929p", "#url" : "https://scrolller.com/cabin-in-northern-finland-7nagf1929p",
"#class": scrolller.ScrolllerPostExtractor, "#class": scrolller.ScrolllerPostExtractor,
"#urls" : "https://yocto.scrolller.com/cabin-in-northern-finland-93vjsuxmcz.jpg", "#urls" : "https://static.scrolller.com/yocto/cabin-in-northern-finland-93vjsuxmcz.jpg",
"albumUrl" : None, "count" : 1,
"displayName" : None, "displayName" : None,
"extension" : "jpg", "extension" : "jpg",
"filename" : "cabin-in-northern-finland-93vjsuxmcz", "filename" : "cabin-in-northern-finland-93vjsuxmcz",
"fullLengthSource": None, "fullLengthSource": None,
"gfycatSource" : None, "gfycatSource" : None,
"hasAudio" : None, "hasAudio" : False,
"height" : 1350, "height" : 1350,
"id" : 10478722, "id" : 10478722,
"isNsfw" : False, "isNsfw" : False,
"isOptimized" : False, "isOptimized" : False,
"isPaid" : None, "isPaid" : False,
"mediaSources" : list, "mediaSources" : list,
"num" : 0,
"ownerAvatar" : None, "ownerAvatar" : None,
"redditPath" : "/r/AmateurPhotography/comments/jj048q/cabin_in_northern_finland/", "redditPath" : "/r/AmateurPhotography/comments/jj048q/cabin_in_northern_finland/",
"redgifsSource" : None, "redgifsSource" : None,
"subredditId" : 0, "subredditId" : 413,
"subredditTitle" : "AmateurPhotography", "subredditTitle" : "AmateurPhotography",
"subredditUrl" : "/r/AmateurPhotography", "subredditUrl" : "/r/AmateurPhotography",
"tags" : None, "tags" : None,
"title" : "Cabin in northern Finland", "title" : "Cabin in northern Finland",
"url" : "https://yocto.scrolller.com/cabin-in-northern-finland-93vjsuxmcz.jpg", "url" : "https://static.scrolller.com/yocto/cabin-in-northern-finland-93vjsuxmcz.jpg",
"username" : None, "username" : "",
"width" : 1080, "width" : 1080,
}, },
{
"#url" : "https://scrolller.com/long-comic-the-twelve-tasks-of-eve-12ch1ve8ko",
"#class" : scrolller.ScrolllerPostExtractor,
"#pattern": r"https://static\.scrolller\.com/\w+/long-comic-the-twelve-tasks-of-eve-\d+-\w+\.png",
"#count" : 177,
"count": 177,
"num" : range(1, 177),
},
{ {
"#url" : "https://scrolller.com/following", "#url" : "https://scrolller.com/following",
"#class" : scrolller.ScrolllerFollowingExtractor, "#class" : scrolller.ScrolllerFollowingExtractor,