diff --git a/youtube_dlc/extractor/extractors.py b/youtube_dlc/extractor/extractors.py index c77ca12cc..1c8628635 100644 --- a/youtube_dlc/extractor/extractors.py +++ b/youtube_dlc/extractor/extractors.py @@ -861,6 +861,7 @@ from .picarto import ( ) from .piksel import PikselIE from .pinkbike import PinkbikeIE +from .pinterest import PinterestIE from .pladform import PladformIE from .platzi import ( PlatziIE, diff --git a/youtube_dlc/extractor/pinterest.py b/youtube_dlc/extractor/pinterest.py new file mode 100644 index 000000000..d4054bb2a --- /dev/null +++ b/youtube_dlc/extractor/pinterest.py @@ -0,0 +1,79 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import re +import json + +from .common import InfoExtractor +from ..utils import ExtractorError + + +class PinterestIE(InfoExtractor): + _VALID_URL = r"https?://(?:www\.)?pinterest\.(?:com|fr|de|ch|jp|cl|ca|it|co.uk|nz|ru|com.au|at|pt|co.kr|es|com.mx|dk|ph|biz|th|com.pt|com.uy|co|nl|info|kr|ie|vn|com.vn|ec|mx|in|pe|co.at|hu|co.in|co.nz|id|co.id|com.ec|com.py|engineering|tw|be|uk|com.bo|com.pe)/pin/(?P[0-9]+)" + _TEST = { + "url": "https://www.pinterest.ca/pin/45599014963532024", + # "md5": "f51309dfca161c82a9cccb835ab10572", + "info_dict": { + "id": "45599014963532024", + "ext": "mp4", + "title": "Look at the lil' chuskys and all of their fluff!!!", + "thumbnail": "https://i.pinimg.com/136x136/61/4f/8c/614f8c789fe217e2fb26d7911e01cf79.jpg", + "uploader": "cathwoman82", + "description": "Look at the lil' chuskys and all of their fluff!!!", + }, + } + + def _real_extract(self, url): + video_id = self._match_id(url) + clean_url = re.search(self._VALID_URL, url).group(0) + + webpage = self._download_webpage(clean_url, video_id) + + pin_info_json = self._search_regex( + r"", + webpage, + "Pin data JSON", + ) + pin_info_full = json.loads(pin_info_json) + pin_info = next( + ( + r + for r in pin_info_full["resourceResponses"] + if r["name"] == "PinResource" + ), + None, + ) + + if pin_info: + pin_data = pin_info["response"]["data"] + video_urls = pin_data.get("videos", {}).get("video_list", {}) + video_data = video_urls.get("V_HLSV4") + video_url = video_data.get("url") + video_thumbs = [ + v + for (k, v) in pin_data.get("images").items() + if v.get("width") == v.get("height") + ] + if not video_url: + raise ExtractorError("Can't find a video stream URL") + description = pin_data.get("description") + title = ( + description + or pin_data.get("title").strip() + or pin_data.get("grid_title") + or "pinterest_video" + ) + pinner = pin_data.get("pinner", {}) + uploader = pinner.get("username") + else: + raise ExtractorError("Can't find Pin data") + return { + "id": video_id, + "title": title, + "description": description, + "uploader": uploader, + "url": video_url, + "ext": "mp4", + "manifest_url": video_url, + "thumbnails": video_thumbs, + }