3 from .common
import InfoExtractor
16 class PinterestBaseIE(InfoExtractor
):
17 _VALID_URL_BASE
= r
'''(?x)
18 https?://(?:[^/]+\.)?pinterest\.(?:
19 com|fr|de|ch|jp|cl|ca|it|co\.uk|nz|ru|com\.au|at|pt|co\.kr|es|com\.mx|
20 dk|ph|th|com\.uy|co|nl|info|kr|ie|vn|com\.vn|ec|mx|in|pe|co\.at|hu|
21 co\.in|co\.nz|id|com\.ec|com\.py|tw|be|uk|com\.bo|com\.pe)'''
23 def _call_api(self
, resource
, video_id
, options
):
24 return self
._download
_json
(
25 f
'https://www.pinterest.com/resource/{resource}Resource/get/',
26 video_id
, f
'Download {resource} JSON metadata', query
={
27 'data': json
.dumps({'options': options
}),
28 })['resource_response']
30 def _extract_video(self
, data
, extract_formats
=True):
33 images
= data
.get('images')
34 if isinstance(images
, dict):
35 for thumbnail
in images
.values():
36 if not isinstance(thumbnail
, dict):
38 thumbnail_url
= url_or_none(thumbnail
.get('url'))
43 'width': int_or_none(thumbnail
.get('width')),
44 'height': int_or_none(thumbnail
.get('height')),
48 'title': strip_or_none(traverse_obj(data
, 'title', 'grid_title', default
='')),
49 'description': traverse_obj(data
, 'seo_description', 'description'),
50 'timestamp': unified_timestamp(data
.get('created_at')),
51 'thumbnails': thumbnails
,
52 'uploader': traverse_obj(data
, ('closeup_attribution', 'full_name')),
53 'uploader_id': str_or_none(traverse_obj(data
, ('closeup_attribution', 'id'))),
54 'repost_count': int_or_none(data
.get('repin_count')),
55 'comment_count': int_or_none(data
.get('comment_count')),
56 'categories': traverse_obj(data
, ('pin_join', 'visual_annotation'), expected_type
=list),
57 'tags': traverse_obj(data
, 'hashtags', expected_type
=list),
63 domain
= data
.get('domain', '')
64 if domain
.lower() != 'uploaded by user' and traverse_obj(data
, ('embed', 'src')):
68 '_type': 'url_transparent',
69 'url': data
['embed']['src'],
74 video_list
= traverse_obj(
75 data
, ('videos', 'video_list'),
76 ('story_pin_data', 'pages', ..., 'blocks', ..., 'video', 'video_list'),
77 expected_type
=dict, get_all
=False, default
={})
78 for format_id
, format_dict
in video_list
.items():
79 if not isinstance(format_dict
, dict):
81 format_url
= url_or_none(format_dict
.get('url'))
82 if not format_url
or format_url
in urls
:
84 urls
.append(format_url
)
85 duration
= float_or_none(format_dict
.get('duration'), scale
=1000)
86 ext
= determine_ext(format_url
)
87 if 'hls' in format_id
.lower() or ext
== 'm3u8':
88 formats
.extend(self
._extract
_m
3u8_formats
(
89 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
90 m3u8_id
=format_id
, fatal
=False))
94 'format_id': format_id
,
95 'width': int_or_none(format_dict
.get('width')),
96 'height': int_or_none(format_dict
.get('height')),
103 'duration': duration
,
104 'webpage_url': f
'https://www.pinterest.com/pin/{video_id}/',
105 'extractor_key': PinterestIE
.ie_key(),
106 'extractor': PinterestIE
.IE_NAME
,
111 class PinterestIE(PinterestBaseIE
):
112 _VALID_URL
= rf
'{PinterestBaseIE._VALID_URL_BASE}/pin/(?:[\w-]+--)?(?P<id>\d+)'
114 # formats found in data['videos']
115 'url': 'https://www.pinterest.com/pin/664281013778109217/',
116 'md5': '6550c2af85d6d9f3fe3b88954d1577fc',
118 'id': '664281013778109217',
121 'description': 'md5:e29801cab7d741ea8c741bc50c8d00ab',
123 'timestamp': 1593073622,
124 'upload_date': '20200625',
126 'comment_count': int,
129 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
132 # formats found in data['story_pin_data']
133 'url': 'https://www.pinterest.com/pin/1084663891475263837/',
134 'md5': '069ac19919ab9e1e13fa60de46290b03',
136 'id': '1084663891475263837',
138 'title': 'Gadget, Cool products, Amazon product, technology, Kitchen gadgets',
139 'description': 'md5:d0a4b6ae996ff0c6eed83bc869598d13',
140 'uploader': 'CoolCrazyGadgets',
141 'uploader_id': '1084664028912989237',
142 'upload_date': '20211003',
143 'timestamp': 1633246654.0,
145 'comment_count': int,
147 'categories': 'count:9',
149 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
153 'url': 'https://www.pinterest.ca/pin/441282463481903715/',
157 'title': 'Tonite Let\'s All Make Love In London (1967)',
158 'description': 'md5:8190f37b3926807809ec57ec21aa77b2',
160 'uploader_id': '473792960706651251',
161 'upload_date': '20180120',
162 'timestamp': 1516409040,
164 'comment_count': int,
166 'categories': 'count:9',
168 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
169 'uploader_url': 'https://vimeo.com/willardandrade',
172 'skip_download': 'm3u8',
175 'url': 'https://co.pinterest.com/pin/824721750502199491/',
176 'only_matching': True,
179 'url': 'https://pinterest.com/pin/dive-into-serenity-blue-lagoon-pedi-nails-for-a-tranquil-and-refreshing-spa-experience-video-in-2024--2885187256207927',
181 'id': '2885187256207927',
183 'title': 'Dive into Serenity: Blue Lagoon Pedi Nails for a Tranquil and Refreshing Spa Experience! 💙💅',
184 'description': 'md5:5da41c767d2317e42e49b663b0b2150f',
185 'uploader': 'Glamour Artistry |Everyday Outfits, Luxury Fashion & Nail Designs',
186 'uploader_id': '1142999717836434688',
187 'upload_date': '20240702',
188 'timestamp': 1719939156,
190 'comment_count': int,
192 'categories': 'count:9',
193 'tags': ['#BlueLagoonPediNails', '#SpaExperience'],
194 'thumbnail': r
're:^https?://.*\.(?:jpg|png)$',
198 def _real_extract(self
, url
):
199 video_id
= self
._match
_id
(url
)
200 data
= self
._call
_api
(
202 'field_set_key': 'unauth_react_main_pin',
205 return self
._extract
_video
(data
)
208 class PinterestCollectionIE(PinterestBaseIE
):
209 _VALID_URL
= rf
'{PinterestBaseIE._VALID_URL_BASE}/(?P<username>[^/]+)/(?P<id>[^/?#&]+)'
211 'url': 'https://www.pinterest.ca/mashal0407/cool-diys/',
213 'id': '585890301462791043',
214 'title': 'cool diys',
218 'url': 'https://www.pinterest.ca/fudohub/videos/',
220 'id': '682858430939307450',
223 'playlist_mincount': 365,
224 'skip': 'Test with extract_formats=False',
228 def suitable(cls
, url
):
229 return False if PinterestIE
.suitable(url
) else super().suitable(url
)
231 def _real_extract(self
, url
):
232 username
, slug
= self
._match
_valid
_url
(url
).groups()
233 board
= self
._call
_api
(
236 'username': username
,
238 board_id
= board
['id']
240 'board_id': board_id
,
247 options
['bookmarks'] = [bookmark
]
248 board_feed
= self
._call
_api
('BoardFeed', board_id
, options
)
249 for item
in (board_feed
.get('data') or []):
250 if not isinstance(item
, dict) or item
.get('type') != 'pin':
252 video_id
= item
.get('id')
254 # Some pins may not be available anonymously via pin URL
255 # video = self._extract_video(item, extract_formats=False)
257 # '_type': 'url_transparent',
258 # 'url': 'https://www.pinterest.com/pin/%s/' % video_id,
260 # entries.append(video)
261 entries
.append(self
._extract
_video
(item
))
262 bookmark
= board_feed
.get('bookmark')
265 return self
.playlist_result(
266 entries
, playlist_id
=board_id
, playlist_title
=board
.get('name'))