[pinterest] add 'domain' option (#3484)
use input URL domain by default
This commit is contained in:
@@ -2098,6 +2098,19 @@ Description
|
|||||||
Extract media from reblogged posts.
|
Extract media from reblogged posts.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.pinterest.domain
|
||||||
|
--------------------------
|
||||||
|
Type
|
||||||
|
``string``
|
||||||
|
Default
|
||||||
|
``"auto"``
|
||||||
|
Description
|
||||||
|
Specifies the domain used by ``pinterest`` extractots.
|
||||||
|
|
||||||
|
Setting this option to ``"auto"``
|
||||||
|
uses the same domain as a given input URL.
|
||||||
|
|
||||||
|
|
||||||
extractor.pinterest.sections
|
extractor.pinterest.sections
|
||||||
----------------------------
|
----------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -228,6 +228,7 @@
|
|||||||
},
|
},
|
||||||
"pinterest":
|
"pinterest":
|
||||||
{
|
{
|
||||||
|
"domain": "auto",
|
||||||
"sections": true,
|
"sections": true,
|
||||||
"videos": true
|
"videos": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ class PinterestExtractor(Extractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
|
|
||||||
|
domain = self.config("domain")
|
||||||
|
if not domain or domain == "auto" :
|
||||||
|
self.root = text.root_from_url(match.group(0))
|
||||||
|
else:
|
||||||
|
self.root = text.ensure_http_scheme(domain)
|
||||||
|
|
||||||
self.api = PinterestAPI(self)
|
self.api = PinterestAPI(self)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
@@ -380,26 +387,23 @@ class PinterestAPI():
|
|||||||
- https://github.com/seregazhuk/php-pinterest-bot
|
- https://github.com/seregazhuk/php-pinterest-bot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
BASE_URL = "https://www.pinterest.com"
|
|
||||||
HEADERS = {
|
|
||||||
"Accept" : "application/json, text/javascript, "
|
|
||||||
"*/*, q=0.01",
|
|
||||||
"Accept-Language" : "en-US,en;q=0.5",
|
|
||||||
"Referer" : BASE_URL + "/",
|
|
||||||
"X-Requested-With" : "XMLHttpRequest",
|
|
||||||
"X-APP-VERSION" : "31461e0",
|
|
||||||
"X-CSRFToken" : None,
|
|
||||||
"X-Pinterest-AppState": "active",
|
|
||||||
"Origin" : BASE_URL,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, extractor):
|
def __init__(self, extractor):
|
||||||
self.extractor = extractor
|
|
||||||
|
|
||||||
csrf_token = util.generate_token()
|
csrf_token = util.generate_token()
|
||||||
self.headers = self.HEADERS.copy()
|
|
||||||
self.headers["X-CSRFToken"] = csrf_token
|
self.extractor = extractor
|
||||||
|
self.root = extractor.root
|
||||||
self.cookies = {"csrftoken": csrf_token}
|
self.cookies = {"csrftoken": csrf_token}
|
||||||
|
self.headers = {
|
||||||
|
"Accept" : "application/json, text/javascript, "
|
||||||
|
"*/*, q=0.01",
|
||||||
|
"Accept-Language" : "en-US,en;q=0.5",
|
||||||
|
"Referer" : self.root + "/",
|
||||||
|
"X-Requested-With" : "XMLHttpRequest",
|
||||||
|
"X-APP-VERSION" : "0c4af40",
|
||||||
|
"X-CSRFToken" : csrf_token,
|
||||||
|
"X-Pinterest-AppState": "active",
|
||||||
|
"Origin" : self.root,
|
||||||
|
}
|
||||||
|
|
||||||
def pin(self, pin_id):
|
def pin(self, pin_id):
|
||||||
"""Query information about a pin"""
|
"""Query information about a pin"""
|
||||||
@@ -495,7 +499,7 @@ class PinterestAPI():
|
|||||||
def _login_impl(self, username, password):
|
def _login_impl(self, username, password):
|
||||||
self.extractor.log.info("Logging in as %s", username)
|
self.extractor.log.info("Logging in as %s", username)
|
||||||
|
|
||||||
url = self.BASE_URL + "/resource/UserSessionResource/create/"
|
url = self.root + "/resource/UserSessionResource/create/"
|
||||||
options = {
|
options = {
|
||||||
"username_or_email": username,
|
"username_or_email": username,
|
||||||
"password" : password,
|
"password" : password,
|
||||||
@@ -518,7 +522,7 @@ class PinterestAPI():
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.root, resource)
|
||||||
params = {"data": json.dumps({"options": options}), "source_url": ""}
|
params = {"data": json.dumps({"options": options}), "source_url": ""}
|
||||||
|
|
||||||
response = self.extractor.request(
|
response = self.extractor.request(
|
||||||
@@ -530,10 +534,11 @@ class PinterestAPI():
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
if response.status_code < 400 and not response.history:
|
if response.history:
|
||||||
|
self.root = text.root_from_url(response.url)
|
||||||
|
if response.status_code < 400:
|
||||||
return data
|
return data
|
||||||
|
if response.status_code == 404:
|
||||||
if response.status_code == 404 or response.history:
|
|
||||||
resource = self.extractor.subcategory.rpartition("-")[2]
|
resource = self.extractor.subcategory.rpartition("-")[2]
|
||||||
raise exception.NotFoundError(resource)
|
raise exception.NotFoundError(resource)
|
||||||
self.extractor.log.debug("Server response: %s", response.text)
|
self.extractor.log.debug("Server response: %s", response.text)
|
||||||
|
|||||||
Reference in New Issue
Block a user