[reddit:user] implement 'only' option (#8228)

This commit is contained in:
Mike Fährmann
2026-02-07 19:38:50 +01:00
parent c16892a150
commit 935bdb6229
3 changed files with 30 additions and 1 deletions

View File

@@ -5435,6 +5435,16 @@ Note
but it will not always get the best video quality available.
extractor.reddit.user.only
--------------------------
Type
``bool``
Default
``trur``
Description
Only process and return posts from the user specified in the input URL.
extractor.redgifs.format
------------------------
Type

View File

@@ -707,7 +707,11 @@
"previews" : true,
"recursion" : 0,
"selftext" : null,
"videos" : "dash"
"videos" : "dash",
"user": {
"only": true
}
},
"redgifs":
{

View File

@@ -317,8 +317,23 @@ class RedditUserExtractor(RedditExtractor):
submissions = self.api.submissions_user(
user["name"], text.parse_query(qs))
if self.config("only", True):
submissions = self._only(submissions, user)
return submissions
def _only(self, submissions, user):
uid = "t2_" + user["id"]
for submission, comments in submissions:
if submission and submission.get("author_fullname") != uid:
submission = None
comments = [
comment
for comment in (comments or ())
if comment.get("author_fullname") == uid
]
if submission or comments:
yield submission, comments
class RedditSubmissionExtractor(RedditExtractor):
"""Extractor for URLs from a submission on reddit.com"""