[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"
root = "https://scrolller.com"
directory_fmt = ("{category}", "{subredditTitle}")
filename_fmt = "{id}{title:? //}.{extension}"
archive_fmt = "{id}"
filename_fmt = "{id}{num:?_//>03}{title:? //}.{extension}"
archive_fmt = "{id}_{num}"
request_interval = (0.5, 1.5)
def _init(self):
@@ -31,23 +31,36 @@ class ScrolllerExtractor(Extractor):
self.login()
for post in self.posts():
media_sources = post.get("mediaSources")
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)
files = self._extract_files(post)
post["count"] = len(files)
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):
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):
username, password = self._get_auth_info()
if username:

View File

@@ -43,34 +43,45 @@ __tests__ = (
{
"#url" : "https://scrolller.com/cabin-in-northern-finland-7nagf1929p",
"#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,
"extension" : "jpg",
"filename" : "cabin-in-northern-finland-93vjsuxmcz",
"fullLengthSource": None,
"gfycatSource" : None,
"hasAudio" : None,
"hasAudio" : False,
"height" : 1350,
"id" : 10478722,
"isNsfw" : False,
"isOptimized" : False,
"isPaid" : None,
"isPaid" : False,
"mediaSources" : list,
"num" : 0,
"ownerAvatar" : None,
"redditPath" : "/r/AmateurPhotography/comments/jj048q/cabin_in_northern_finland/",
"redgifsSource" : None,
"subredditId" : 0,
"subredditId" : 413,
"subredditTitle" : "AmateurPhotography",
"subredditUrl" : "/r/AmateurPhotography",
"tags" : None,
"title" : "Cabin in northern Finland",
"url" : "https://yocto.scrolller.com/cabin-in-northern-finland-93vjsuxmcz.jpg",
"username" : None,
"url" : "https://static.scrolller.com/yocto/cabin-in-northern-finland-93vjsuxmcz.jpg",
"username" : "",
"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",
"#class" : scrolller.ScrolllerFollowingExtractor,