[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:
@@ -820,35 +820,6 @@ How To
|
|||||||
=========== =====
|
=========== =====
|
||||||
|
|
||||||
|
|
||||||
extractor.pinterest.access-token
|
|
||||||
--------------------------------
|
|
||||||
=========== =====
|
|
||||||
Type ``string``
|
|
||||||
How To - register a Pinterest application and use its client-id and
|
|
||||||
client-secret (see `extractor.pinterest.client-id & .secret`_)
|
|
||||||
- run `gallery-dl oauth:pinterest` and authenticate access with
|
|
||||||
(preferably) the same account that registered the application
|
|
||||||
Notes Access tokens currently only allow for 10 requests per hour.
|
|
||||||
=========== =====
|
|
||||||
|
|
||||||
|
|
||||||
extractor.pinterest.client-id & .secret
|
|
||||||
---------------------------------------
|
|
||||||
=========== =====
|
|
||||||
Type ``string``
|
|
||||||
How To - login and visit Pinterest's
|
|
||||||
`Apps <https://developers.pinterest.com/apps/>`__ section
|
|
||||||
- agree to "Pinterest Developer Terms and the API Policy"
|
|
||||||
and click "Create app"
|
|
||||||
- choose a random name and description and click "Create"
|
|
||||||
- scroll down and set a Site URL (e.g. https://example.org/)
|
|
||||||
and allow https://mikf.github.io/gallery-dl/oauth-redirect.html
|
|
||||||
as Redirect URI
|
|
||||||
- scroll back up again, copy the "App ID" and "App secret" values
|
|
||||||
and put them in your configuration file
|
|
||||||
=========== =====
|
|
||||||
|
|
||||||
|
|
||||||
extractor.reddit.client-id & .user-agent
|
extractor.reddit.client-id & .user-agent
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
=========== =====
|
=========== =====
|
||||||
|
|||||||
@@ -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):
|
class OAuthReddit(OAuthBase):
|
||||||
subcategory = "reddit"
|
subcategory = "reddit"
|
||||||
pattern = ["oauth:reddit$"]
|
pattern = ["oauth:reddit$"]
|
||||||
|
|||||||
@@ -81,15 +81,12 @@ class PinterestBoardExtractor(PinterestExtractor):
|
|||||||
def items(self):
|
def items(self):
|
||||||
board = self.api.board(self.user, self.board)
|
board = self.api.board(self.user, self.board)
|
||||||
data = {"board": board, "count": board["pin_count"]}
|
data = {"board": board, "count": board["pin_count"]}
|
||||||
num = data["count"]
|
|
||||||
yield Message.Version, 1
|
yield Message.Version, 1
|
||||||
yield Message.Directory, data
|
yield Message.Directory, data
|
||||||
for pin in self.api.board_pins(board["id"]):
|
for pin in self.api.board_pins(board["id"]):
|
||||||
url, pdata = self.data_from_pin(pin)
|
url, pin_data = self.data_from_pin(pin)
|
||||||
data.update(pdata)
|
pin_data.update(data)
|
||||||
data["num"] = num
|
yield Message.Url, url, pin_data
|
||||||
num -= 1
|
|
||||||
yield Message.Url, url, data
|
|
||||||
|
|
||||||
|
|
||||||
class PinterestPinitExtractor(PinterestExtractor):
|
class PinterestPinitExtractor(PinterestExtractor):
|
||||||
@@ -157,11 +154,8 @@ class PinterestAPI():
|
|||||||
return self._pagination("BoardFeed", options)
|
return self._pagination("BoardFeed", options)
|
||||||
|
|
||||||
def _call(self, resource, options):
|
def _call(self, resource, options):
|
||||||
url = "{}/resource/{}Resource/get".format(self.BASE_URL, resource)
|
url = "{}/resource/{}Resource/get/".format(self.BASE_URL, resource)
|
||||||
params = {
|
params = {"data": json.dumps({"options": options}), "source_url": ""}
|
||||||
"source_url": "",
|
|
||||||
"data": json.dumps({"options": options}),
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.session.get(url, params=params, headers=self.HEADERS)
|
response = self.session.get(url, params=params, headers=self.HEADERS)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@@ -179,10 +173,8 @@ class PinterestAPI():
|
|||||||
self.log.error("API request failed: %s", msg)
|
self.log.error("API request failed: %s", msg)
|
||||||
raise exception.StopExtraction()
|
raise exception.StopExtraction()
|
||||||
|
|
||||||
def _pagination(self, resource, options, bookmarks=None):
|
def _pagination(self, resource, options):
|
||||||
while True:
|
while True:
|
||||||
if bookmarks:
|
|
||||||
options["bookmarks"] = bookmarks
|
|
||||||
data = self._call(resource, options)
|
data = self._call(resource, options)
|
||||||
yield from data["resource_response"]["data"]
|
yield from data["resource_response"]["data"]
|
||||||
|
|
||||||
@@ -190,5 +182,6 @@ class PinterestAPI():
|
|||||||
bookmarks = data["resource"]["options"]["bookmarks"]
|
bookmarks = data["resource"]["options"]["bookmarks"]
|
||||||
if not bookmarks or bookmarks[0] == "-end-":
|
if not bookmarks or bookmarks[0] == "-end-":
|
||||||
return
|
return
|
||||||
|
options["bookmarks"] = bookmarks
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user