[reddit:user] implement 'only' option (#8228)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -707,7 +707,11 @@
|
||||
"previews" : true,
|
||||
"recursion" : 0,
|
||||
"selftext" : null,
|
||||
"videos" : "dash"
|
||||
"videos" : "dash",
|
||||
|
||||
"user": {
|
||||
"only": true
|
||||
}
|
||||
},
|
||||
"redgifs":
|
||||
{
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user