@@ -4517,6 +4517,32 @@ Description
|
|||||||
or ``"hq"`` if not present.
|
or ``"hq"`` if not present.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.reddit.api
|
||||||
|
--------------------
|
||||||
|
Type
|
||||||
|
``string``
|
||||||
|
Default
|
||||||
|
``"oauth"``
|
||||||
|
Description
|
||||||
|
Selects which API endpoints to use.
|
||||||
|
|
||||||
|
``"oauth"``
|
||||||
|
Use the OAuth API at ``https://oauth.reddit.com``
|
||||||
|
|
||||||
|
Requires
|
||||||
|
`client-id & user-agent <extractor.reddit.client-id & .user-agent_>`__
|
||||||
|
and uses a
|
||||||
|
`refresh token <extractor.reddit.refresh-token_>`__
|
||||||
|
for authentication.
|
||||||
|
|
||||||
|
``"rest"``
|
||||||
|
Use the REST API at ``https://www.reddit.com``
|
||||||
|
|
||||||
|
Uses
|
||||||
|
`cookies <extractor.*.cookies_>`__
|
||||||
|
for authentication.
|
||||||
|
|
||||||
|
|
||||||
extractor.reddit.comments
|
extractor.reddit.comments
|
||||||
-------------------------
|
-------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -623,6 +623,7 @@
|
|||||||
"user-agent" : null,
|
"user-agent" : null,
|
||||||
"refresh-token": null,
|
"refresh-token": null,
|
||||||
|
|
||||||
|
"api" : "oauth",
|
||||||
"comments" : 0,
|
"comments" : 0,
|
||||||
"morecomments": false,
|
"morecomments": false,
|
||||||
"embeds" : true,
|
"embeds" : true,
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ class RedditAPI():
|
|||||||
|
|
||||||
Ref: https://www.reddit.com/dev/api/
|
Ref: https://www.reddit.com/dev/api/
|
||||||
"""
|
"""
|
||||||
|
ROOT = "https://oauth.reddit.com"
|
||||||
CLIENT_ID = "6N9uN0krSDE-ig"
|
CLIENT_ID = "6N9uN0krSDE-ig"
|
||||||
USER_AGENT = "Python:gallery-dl:0.8.4 (by /u/mikf1)"
|
USER_AGENT = "Python:gallery-dl:0.8.4 (by /u/mikf1)"
|
||||||
|
|
||||||
@@ -369,41 +370,50 @@ class RedditAPI():
|
|||||||
self.log = extractor.log
|
self.log = extractor.log
|
||||||
|
|
||||||
config = extractor.config
|
config = extractor.config
|
||||||
|
|
||||||
self.comments = text.parse_int(config("comments", 0))
|
self.comments = text.parse_int(config("comments", 0))
|
||||||
self.morecomments = config("morecomments", False)
|
self.morecomments = config("morecomments", False)
|
||||||
|
self._warn_429 = False
|
||||||
|
|
||||||
client_id = config("client-id")
|
if config("api") == "rest":
|
||||||
if client_id is None:
|
self.root = "https://www.reddit.com"
|
||||||
self.client_id = self.CLIENT_ID
|
self.headers = None
|
||||||
self.headers = {"User-Agent": self.USER_AGENT}
|
self.authenticate = util.noop
|
||||||
|
self.log.debug("Using REST API")
|
||||||
else:
|
else:
|
||||||
self.client_id = client_id
|
self.root = self.ROOT
|
||||||
self.headers = {"User-Agent": config("user-agent")}
|
|
||||||
|
|
||||||
if self.client_id == self.CLIENT_ID:
|
client_id = config("client-id")
|
||||||
client_id = self.client_id
|
if client_id is None:
|
||||||
self._warn_429 = True
|
self.client_id = self.CLIENT_ID
|
||||||
kind = "default"
|
self.headers = {"User-Agent": self.USER_AGENT}
|
||||||
else:
|
else:
|
||||||
client_id = client_id[:5] + "*" * (len(client_id)-5)
|
self.client_id = client_id
|
||||||
self._warn_429 = False
|
self.headers = {"User-Agent": config("user-agent")}
|
||||||
kind = "custom"
|
|
||||||
|
|
||||||
self.log.debug(
|
if self.client_id == self.CLIENT_ID:
|
||||||
"Using %s API credentials (client-id %s)", kind, client_id)
|
client_id = self.client_id
|
||||||
|
self._warn_429 = True
|
||||||
|
kind = "default"
|
||||||
|
else:
|
||||||
|
client_id = client_id[:5] + "*" * (len(client_id)-5)
|
||||||
|
kind = "custom"
|
||||||
|
|
||||||
token = config("refresh-token")
|
self.log.debug(
|
||||||
if token is None or token == "cache":
|
"Using %s API credentials (client-id %s)", kind, client_id)
|
||||||
key = "#" + self.client_id
|
|
||||||
self.refresh_token = _refresh_token_cache(key)
|
|
||||||
else:
|
|
||||||
self.refresh_token = token
|
|
||||||
|
|
||||||
if not self.refresh_token:
|
token = config("refresh-token")
|
||||||
# allow downloading from quarantined subreddits (#2180)
|
if token is None or token == "cache":
|
||||||
extractor.cookies.set(
|
key = "#" + self.client_id
|
||||||
"_options", '%7B%22pref_quarantine_optin%22%3A%20true%7D',
|
self.refresh_token = _refresh_token_cache(key)
|
||||||
domain=extractor.cookies_domain)
|
else:
|
||||||
|
self.refresh_token = token
|
||||||
|
|
||||||
|
if not self.refresh_token:
|
||||||
|
# allow downloading from quarantined subreddits (#2180)
|
||||||
|
extractor.cookies.set(
|
||||||
|
"_options", '%7B%22pref_quarantine_optin%22%3A%20true%7D',
|
||||||
|
domain=extractor.cookies_domain)
|
||||||
|
|
||||||
def submission(self, submission_id):
|
def submission(self, submission_id):
|
||||||
"""Fetch the (submission, comments)=-tuple for a submission id"""
|
"""Fetch the (submission, comments)=-tuple for a submission id"""
|
||||||
@@ -477,7 +487,7 @@ class RedditAPI():
|
|||||||
return "Bearer " + data["access_token"]
|
return "Bearer " + data["access_token"]
|
||||||
|
|
||||||
def _call(self, endpoint, params):
|
def _call(self, endpoint, params):
|
||||||
url = "https://oauth.reddit.com" + endpoint
|
url = f"{self.root}{endpoint}"
|
||||||
params["raw_json"] = "1"
|
params["raw_json"] = "1"
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user