[pinterest] scrap OAuth implementation; code improvements
OAuth authentication isn't needed anymore and other tools like Postman are better suited for this job anyway.
This commit is contained in:
@@ -198,29 +198,6 @@ class OAuthFlickr(OAuthBase):
|
||||
)
|
||||
|
||||
|
||||
class OAuthPinterest(OAuthBase):
|
||||
subcategory = "pinterest"
|
||||
pattern = ["oauth:pinterest$"]
|
||||
redirect_uri = "https://mikf.github.io/gallery-dl/oauth-redirect.html"
|
||||
|
||||
def items(self):
|
||||
yield Message.Version, 1
|
||||
|
||||
client_id = self.oauth_config("client-id")
|
||||
client_secret = self.oauth_config("client-secret")
|
||||
|
||||
if not client_id or not client_secret:
|
||||
self.log.error("'client-id' and 'client-secret' required")
|
||||
return
|
||||
|
||||
self._oauth2_authorization_code_grant(
|
||||
client_id, client_secret,
|
||||
"https://api.pinterest.com/oauth/",
|
||||
"https://api.pinterest.com/v1/oauth/token",
|
||||
scope="read_public", key="access_token", auth=False,
|
||||
)
|
||||
|
||||
|
||||
class OAuthReddit(OAuthBase):
|
||||
subcategory = "reddit"
|
||||
pattern = ["oauth:reddit$"]
|
||||
|
||||
@@ -81,15 +81,12 @@ class PinterestBoardExtractor(PinterestExtractor):
|
||||
def items(self):
|
||||
board = self.api.board(self.user, self.board)
|
||||
data = {"board": board, "count": board["pin_count"]}
|
||||
num = data["count"]
|
||||
yield Message.Version, 1
|
||||
yield Message.Directory, data
|
||||
for pin in self.api.board_pins(board["id"]):
|
||||
url, pdata = self.data_from_pin(pin)
|
||||
data.update(pdata)
|
||||
data["num"] = num
|
||||
num -= 1
|
||||
yield Message.Url, url, data
|
||||
url, pin_data = self.data_from_pin(pin)
|
||||
pin_data.update(data)
|
||||
yield Message.Url, url, pin_data
|
||||
|
||||
|
||||
class PinterestPinitExtractor(PinterestExtractor):
|
||||
@@ -157,11 +154,8 @@ class PinterestAPI():
|
||||
return self._pagination("BoardFeed", options)
|
||||
|
||||
def _call(self, resource, options):
|
||||
url = "{}/resource/{}Resource/get".format(self.BASE_URL, resource)
|
||||
params = {
|
||||
"source_url": "",
|
||||
"data": json.dumps({"options": options}),
|
||||
}
|
||||
url = "{}/resource/{}Resource/get/".format(self.BASE_URL, resource)
|
||||
params = {"data": json.dumps({"options": options}), "source_url": ""}
|
||||
|
||||
response = self.session.get(url, params=params, headers=self.HEADERS)
|
||||
data = response.json()
|
||||
@@ -179,10 +173,8 @@ class PinterestAPI():
|
||||
self.log.error("API request failed: %s", msg)
|
||||
raise exception.StopExtraction()
|
||||
|
||||
def _pagination(self, resource, options, bookmarks=None):
|
||||
def _pagination(self, resource, options):
|
||||
while True:
|
||||
if bookmarks:
|
||||
options["bookmarks"] = bookmarks
|
||||
data = self._call(resource, options)
|
||||
yield from data["resource_response"]["data"]
|
||||
|
||||
@@ -190,5 +182,6 @@ class PinterestAPI():
|
||||
bookmarks = data["resource"]["options"]["bookmarks"]
|
||||
if not bookmarks or bookmarks[0] == "-end-":
|
||||
return
|
||||
options["bookmarks"] = bookmarks
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user