summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/pinterest.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-04-09 00:15:19 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2022-04-09 00:15:19 -0400
commit2fe1dfed848fc26b7419e3bfe91a62e686960429 (patch)
tree901cb64e2a1748df2bb8c7abc60ff6d72ae4bc27 /gallery_dl/extractor/pinterest.py
parentc2e774d3f5a4499b8beb5a12ab46a0099b16b1e7 (diff)
New upstream version 1.21.1.upstream/1.21.1
Diffstat (limited to 'gallery_dl/extractor/pinterest.py')
-rw-r--r--gallery_dl/extractor/pinterest.py86
1 files changed, 65 insertions, 21 deletions
diff --git a/gallery_dl/extractor/pinterest.py b/gallery_dl/extractor/pinterest.py
index 25344e8..2079b73 100644
--- a/gallery_dl/extractor/pinterest.py
+++ b/gallery_dl/extractor/pinterest.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2016-2021 Mike Fährmann
+# Copyright 2016-2022 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -20,8 +20,8 @@ BASE_PATTERN = r"(?:https?://)?(?:\w+\.)?pinterest\.[\w.]+"
class PinterestExtractor(Extractor):
"""Base class for pinterest extractors"""
category = "pinterest"
- filename_fmt = "{category}_{id}.{extension}"
- archive_fmt = "{id}"
+ filename_fmt = "{category}_{id}{media_id:?_//}.{extension}"
+ archive_fmt = "{id}{media_id}"
root = "https://www.pinterest.com"
def __init__(self, match):
@@ -35,28 +35,39 @@ class PinterestExtractor(Extractor):
yield Message.Directory, data
for pin in self.pins():
+ pin.update(data)
- try:
- media = self._media_from_pin(pin)
- except Exception:
- self.log.debug("Unable to fetch download URL for pin %s",
- pin.get("id"))
- continue
+ carousel_data = pin.get("carousel_data")
+ if carousel_data:
+ for num, slot in enumerate(carousel_data["carousel_slots"], 1):
+ slot["media_id"] = slot.pop("id")
+ pin.update(slot)
+ pin["num"] = num
+ size, image = next(iter(slot["images"].items()))
+ url = image["url"].replace("/" + size + "/", "/originals/")
+ yield Message.Url, url, text.nameext_from_url(url, pin)
- if not videos and media.get("duration") is not None:
- continue
+ else:
+ try:
+ media = self._media_from_pin(pin)
+ except Exception:
+ self.log.debug("Unable to fetch download URL for pin %s",
+ pin.get("id"))
+ continue
- pin.update(data)
- pin.update(media)
- url = media["url"]
- text.nameext_from_url(url, pin)
+ if videos or media.get("duration") is None:
+ pin.update(media)
+ pin["num"] = 0
+ pin["media_id"] = ""
+
+ url = media["url"]
+ text.nameext_from_url(url, pin)
- if pin["extension"] == "m3u8":
- url = "ytdl:" + url
- pin["extension"] = "mp4"
- pin["_ytdl_extra"] = {"protocol": "m3u8_native"}
+ if pin["extension"] == "m3u8":
+ url = "ytdl:" + url
+ pin["extension"] = "mp4"
- yield Message.Url, url, pin
+ yield Message.Url, url, pin
def metadata(self):
"""Return general metadata"""
@@ -124,7 +135,8 @@ class PinterestBoardExtractor(PinterestExtractor):
subcategory = "board"
directory_fmt = ("{category}", "{board[owner][username]}", "{board[name]}")
archive_fmt = "{board[id]}_{id}"
- pattern = BASE_PATTERN + r"/(?!pin/)([^/?#&]+)/(?!_saved)([^/?#&]+)/?$"
+ pattern = (BASE_PATTERN + r"/(?!pin/)([^/?#&]+)"
+ "/(?!_saved|_created)([^/?#&]+)/?$")
test = (
("https://www.pinterest.com/g1952849/test-/", {
"pattern": r"https://i\.pinimg\.com/originals/",
@@ -192,6 +204,28 @@ class PinterestUserExtractor(PinterestExtractor):
yield Message.Queue, self.root + url, board
+class PinterestCreatedExtractor(PinterestExtractor):
+ """Extractor for a user's created pins"""
+ subcategory = "created"
+ directory_fmt = ("{category}", "{user}")
+ pattern = BASE_PATTERN + r"/(?!pin/)([^/?#&]+)/_created/?$"
+ test = ("https://www.pinterest.com/amazon/_created", {
+ "pattern": r"https://i\.pinimg\.com/originals/[0-9a-f]{2}"
+ r"/[0-9a-f]{2}/[0-9a-f]{2}/[0-9a-f]{32}\.jpg",
+ "count": 10,
+ })
+
+ def __init__(self, match):
+ PinterestExtractor.__init__(self, match)
+ self.user = text.unquote(match.group(1))
+
+ def metadata(self):
+ return {"user": self.user}
+
+ def pins(self):
+ return self.api.user_activity_pins(self.user)
+
+
class PinterestSectionExtractor(PinterestExtractor):
"""Extractor for board sections on pinterest.com"""
subcategory = "section"
@@ -385,6 +419,16 @@ class PinterestAPI():
options = {"board_id": board_id, "add_vase": True}
return self._pagination("BoardRelatedPixieFeed", options)
+ def user_activity_pins(self, user):
+ """Yield pins created by 'user'"""
+ options = {
+ "exclude_add_pin_rep": True,
+ "field_set_key" : "grid_item",
+ "is_own_profile_pins": False,
+ "username" : user,
+ }
+ return self._pagination("UserActivityPins", options)
+
def search(self, query):
"""Yield pins from searches"""
options = {"query": query, "scope": "pins", "rs": "typed"}