1 from .common
import InfoExtractor
11 class TumblrIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?P<blog_name_1>[^/?#&]+)\.tumblr\.com/(?:post|video|(?P<blog_name_2>[a-zA-Z\d-]+))/(?P<id>[0-9]+)(?:$|[/?#])'
13 _NETRC_MACHINE
= 'tumblr'
14 _LOGIN_URL
= 'https://www.tumblr.com/login'
15 _OAUTH_URL
= 'https://www.tumblr.com/api/v2/oauth2/token'
17 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
18 'md5': '479bb068e5b16462f5176a6828829767',
22 'title': 'md5:dfac39636969fe6bf1caa2d50405f069',
23 'description': 'md5:390ab77358960235b6937ab3b8528956',
24 'uploader_id': 'tatianamaslanydaily',
25 'uploader_url': 'https://tatianamaslanydaily.tumblr.com/',
26 'thumbnail': r
're:^https?://.*\.jpg',
31 'tags': ['Orphan Black', 'Tatiana Maslany', 'Interview', 'Video', 'OB S1 DVD Extras'],
34 'note': 'multiple formats',
35 'url': 'https://maskofthedragon.tumblr.com/post/626907179849564160/mona-talking-in-english',
36 'md5': 'f43ff8a8861712b6cf0e0c2bd84cfc68',
38 'id': '626907179849564160',
40 'title': 'Mona\xa0“talking” in\xa0“english”',
41 'description': 'md5:082a3a621530cb786ad2b7592a6d9e2c',
42 'uploader_id': 'maskofthedragon',
43 'uploader_url': 'https://maskofthedragon.tumblr.com/',
44 'thumbnail': r
're:^https?://.*\.jpg',
55 'note': 'non-iframe video (with related posts)',
56 'url': 'https://shieldfoss.tumblr.com/post/675519763813908480',
57 'md5': '12bdb75661ef443bffe5a4dac1dbf118',
59 'id': '675519763813908480',
61 'title': 'Shieldfoss',
62 'uploader_id': 'nerviovago',
63 'uploader_url': 'https://nerviovago.tumblr.com/',
64 'thumbnail': r
're:^https?://.*\.jpg',
72 'note': 'dashboard only (original post)',
73 'url': 'https://jujanon.tumblr.com/post/159704441298/my-baby-eating',
74 'md5': '029f7c91ab386701b211e3d494d2d95e',
78 'title': 'md5:ba79365861101f4911452728d2950561',
79 'description': 'md5:773738196cea76b6996ec71e285bdabc',
80 'uploader_id': 'jujanon',
81 'uploader_url': 'https://jujanon.tumblr.com/',
82 'thumbnail': r
're:^https?://.*\.jpg',
86 'tags': ['crabs', 'my video', 'my pets'],
89 'note': 'dashboard only (reblog)',
90 'url': 'https://bartlebyshop.tumblr.com/post/180294460076/duality-of-bird',
91 'md5': '04334e7cadb1af680d162912559f51a5',
95 'title': 'duality of bird',
96 'description': 'duality of bird',
97 'uploader_id': 'todaysbird',
98 'uploader_url': 'https://todaysbird.tumblr.com/',
99 'thumbnail': r
're:^https?://.*\.jpg',
105 'note': 'dashboard only (external)',
106 'url': 'https://afloweroutofstone.tumblr.com/post/675661759168823296/the-blues-remembers-everything-the-country-forgot',
110 'title': 'The Blues Remembers Everything the Country Forgot',
111 'alt_title': 'The Blues Remembers Everything the Country Forgot',
112 'description': 'md5:1a6b4097e451216835a24c1023707c79',
113 'creator': 'md5:c2239ba15430e87c3b971ba450773272',
114 'uploader': 'Moor Mother - Topic',
115 'upload_date': '20201223',
116 'uploader_id': 'UCxrMtFBRkFvQJ_vVM4il08w',
117 'uploader_url': 'http://www.youtube.com/channel/UCxrMtFBRkFvQJ_vVM4il08w',
118 'thumbnail': r
're:^https?://i.ytimg.com/.*',
119 'channel': 'Moor Mother',
120 'channel_id': 'UCxrMtFBRkFvQJ_vVM4il08w',
121 'channel_url': 'https://www.youtube.com/channel/UCxrMtFBRkFvQJ_vVM4il08w',
122 'channel_follower_count': int,
127 'categories': ['Music'],
129 'live_status': 'not_live',
130 'playable_in_embed': True,
131 'availability': 'public',
132 'track': 'The Blues Remembers Everything the Country Forgot',
133 'artist': 'md5:c2239ba15430e87c3b971ba450773272',
135 'release_year': 2020,
137 'add_ie': ['Youtube'],
138 'skip': 'Video Unavailable',
140 'url': 'https://prozdvoices.tumblr.com/post/673201091169681408/what-recording-voice-acting-sounds-like',
141 'md5': 'cb8328a6723c30556cef59e370202918',
145 'title': 'what recording voice acting sounds like',
146 'description': 'md5:1da3faa22d0e0b1d8b50216c284ee798',
148 'upload_date': '20220112',
149 'uploader_id': '@ProZD',
150 'uploader_url': 'https://www.youtube.com/@ProZD',
151 'thumbnail': r
're:^https?://i.ytimg.com/.*',
153 'channel_id': 'UC6MFZAOHXlKK1FI7V0XQVeA',
154 'channel_url': 'https://www.youtube.com/channel/UC6MFZAOHXlKK1FI7V0XQVeA',
155 'channel_follower_count': int,
160 'categories': ['Film & Animation'],
162 'live_status': 'not_live',
163 'playable_in_embed': True,
164 'availability': 'public',
165 'heatmap': 'count:100',
166 'channel_is_verified': True,
167 'timestamp': 1642014562,
168 'comment_count': int,
170 'add_ie': ['Youtube'],
172 'url': 'https://dominustempori.tumblr.com/post/673572712813297664/youtubes-all-right-for-some-pretty-cool',
173 'md5': '203e9eb8077e3f45bfaeb4c86c1467b8',
177 'title': 'Harold Ramis',
178 'description': 'md5:c99882405fcca0b1d348ad093f8f1672',
179 'uploader': 'Resolution Productions Group',
180 'uploader_id': 'resolutionproductions',
181 'uploader_url': 'https://vimeo.com/resolutionproductions',
182 'upload_date': '20140227',
183 'thumbnail': r
're:^https?://i.vimeocdn.com/video/.*',
184 'timestamp': 1393541719,
186 'comment_count': int,
188 'release_timestamp': 1393541719,
189 'release_date': '20140227',
193 'url': 'https://silami.tumblr.com/post/84250043974/my-bad-river-flows-in-you-impression-on-maschine',
194 'md5': '3c92d7c3d867f14ccbeefa2119022277',
198 'title': 'Video by silbulterman',
199 'description': '#maschine',
200 'uploader_id': '242859024',
201 'thumbnail': r
're:^https?://.*\.jpg',
202 'timestamp': 1398801174,
205 'channel': 'silbulterman',
206 'comment_count': int,
207 'upload_date': '20140429',
209 'add_ie': ['Instagram'],
211 'note': 'new url scheme',
212 'url': 'https://www.tumblr.com/autumnsister/765162750456578048?source=share',
214 'id': '765162750456578048',
216 'uploader_url': 'https://autumnsister.tumblr.com/',
217 'tags': ['autumn', 'food', 'curators on tumblr'],
219 'thumbnail': 'https://64.media.tumblr.com/tumblr_sklad89N3x1ygquow_frame1.jpg',
221 'uploader_id': 'autumnsister',
226 'note': 'bandcamp album embed',
227 'url': 'https://patricia-taxxon.tumblr.com/post/704473755725004800/patricia-taxxon-agnes-hilda-patricia-taxxon',
230 'title': 'Agnes & Hilda',
231 'description': 'The inexplicable joy of an artist. Wash paws after listening.',
232 'uploader_id': 'patriciataxxon',
236 'note': 'bandcamp track embeds (many)',
237 'url': 'https://www.tumblr.com/felixcosm/730460905855467520/if-youre-looking-for-new-music-to-write-or',
239 'id': '730460905855467520',
240 'uploader_id': 'felixcosm',
243 'description': 'md5:2eb3482a3c6987280cbefb6839068f32',
246 'title': 'If you\'re looking for new music to write or imagine scenerios to: STOP. This is for you.',
247 'uploader_url': 'https://felixcosm.tumblr.com/',
249 'playlist_count': 10,
251 'note': 'soundcloud track embed',
252 'url': 'https://silverfoxstole.tumblr.com/post/765305403763556352/jamie-robertson-doctor-who-8th-doctor',
256 'comment_count': int,
259 'uploader': 'Jamie Robertson',
260 'title': 'Doctor Who - 8th doctor - Stranded Theme never released and used.',
262 'uploader_id': '2731064',
263 'thumbnail': 'https://i1.sndcdn.com/artworks-MVgcPm5jN42isC5M-6Dz22w-original.jpg',
264 'timestamp': 1645181261,
265 'uploader_url': 'https://soundcloud.com/jamierobertson',
267 'upload_date': '20220218',
268 'description': 'md5:ab924dd9994d0a7d64d6d31bf2af4625',
269 'license': 'all-rights-reserved',
273 'note': 'soundcloud set embed',
274 'url': 'https://www.tumblr.com/beyourselfchulanmaria/703505323122638848/chu-lan-maria-the-playlist-%E5%BF%83%E7%9A%84%E5%91%BC%E5%96%9A-call-of-the',
277 'title': '心的呼喚 Call of the heart I',
278 'description': 'md5:25952a8d178a3aa55e40fcbb646a38c3',
280 'playlist_mincount': 19,
282 'note': 'dailymotion video embed',
283 'url': 'https://www.tumblr.com/funvibecentral/759390024460632064',
287 'description': 'Funny dailymotion shorts.\n#funny #fun#comedy #romantic #exciting',
288 'uploader': 'FunVibe Central',
291 'timestamp': 1724210553,
292 'title': 'Woman watching other Woman',
294 'upload_date': '20240821',
296 'uploader_id': 'x32m6ye',
298 'thumbnail': r
're:https://(?:s[12]\.)dmcdn\.net/v/Wtqh01cnxKNXLG1N8/x1080',
301 'note': 'tiktok video embed',
302 'url': 'https://fansofcolor.tumblr.com/post/660637918605475840/blockquote-class-tiktok-embed',
304 'id': '7000937272010935558',
306 'artists': ['Alicia Dreaming'],
309 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
310 'channel_id': 'MS4wLjABAAAAsJohwz_dU4KfAOc61cbGDAZ46-5hg2ANTXVQlRe1ipDhpX08PywR3PPiple1NTAo',
311 'uploader': 'aliciadreaming',
312 'description': 'huge casting news Greyworm will be #louisdulac #racebending #interviewwiththevampire',
313 'title': 'huge casting news Greyworm will be #louisdulac #racebending #interviewwiththevampire',
314 'channel_url': 'https://www.tiktok.com/@MS4wLjABAAAAsJohwz_dU4KfAOc61cbGDAZ46-5hg2ANTXVQlRe1ipDhpX08PywR3PPiple1NTAo',
315 'uploader_id': '7000478462196990982',
316 'uploader_url': 'https://www.tiktok.com/@aliciadreaming',
317 'timestamp': 1630032733,
318 'channel': 'Alicia Dreaming',
319 'track': 'original sound',
320 'upload_date': '20210827',
322 'comment_count': int,
326 'note': 'tumblr video AND youtube embed',
327 'url': 'https://www.tumblr.com/anyaboz/765332564457209856/my-music-video-for-selkie-by-nobodys-wolf-child',
329 'id': '765332564457209856',
330 'uploader_id': 'anyaboz',
333 'uploader_url': 'https://anyaboz.tumblr.com/',
334 'description': 'md5:9a129cf6ce9d87a80ffd3c6dedd4d1e6',
336 'title': 'md5:b18a2ac9387681d20303e485db85c1b5',
337 'tags': ['music video', 'nobodys wolf child', 'selkie', 'Stop Motion Animation', 'stop Motion', 'room guardians', 'Youtube'],
341 # twitch_live provider - error when linked account is not live
342 'url': 'https://www.tumblr.com/anarcho-skamunist/722224493650722816/hollow-knight-stream-right-now-going-to-fight',
343 'only_matching': True,
347 'instagram': 'Instagram',
349 'youtube': 'Youtube',
350 'dailymotion': 'Dailymotion',
352 'twitch_live': 'TwitchStream',
356 # known not to be supported
357 _unsupported_providers
= {
358 # seems like podcasts can't be embedded
364 def _initialize_pre_login(self
):
365 login_page
= self
._download
_webpage
(
366 self
._LOGIN
_URL
, None, 'Downloading login page', fatal
=False)
368 self
._ACCESS
_TOKEN
= self
._search
_regex
(
369 r
'"API_TOKEN":\s*"(\w+)"', login_page
, 'API access token', fatal
=False)
370 if not self
._ACCESS
_TOKEN
:
371 self
.report_warning('Failed to get access token; metadata will be missing and some videos may not work')
373 def _perform_login(self
, username
, password
):
374 if not self
._ACCESS
_TOKEN
:
378 'password': password
,
379 'grant_type': 'password',
380 'username': username
,
382 if self
.get_param('twofactor'):
383 data
['tfa_token'] = self
.get_param('twofactor')
386 return self
._download
_json
(
387 self
._OAUTH
_URL
, None, 'Logging in',
388 data
=urlencode_postdata(data
),
390 'Content-Type': 'application/x-www-form-urlencoded',
391 'Authorization': f
'Bearer {self._ACCESS_TOKEN}',
393 errnote
='Login failed', fatal
=False,
394 expected_status
=lambda s
: 400 <= s
< 500)
396 response
= _call_login()
397 if traverse_obj(response
, 'error') == 'tfa_required':
398 data
['tfa_token'] = self
._get
_tfa
_info
()
399 response
= _call_login()
400 if traverse_obj(response
, 'error'):
401 raise ExtractorError(
402 f
'API returned error {": ".join(traverse_obj(response, (("error", "error_description"), {str})))}')
404 def _real_extract(self
, url
):
405 blog_1
, blog_2
, video_id
= self
._match
_valid
_url
(url
).groups()
406 blog
= blog_2
or blog_1
408 url
= f
'http://{blog}.tumblr.com/post/{video_id}'
409 webpage
, urlh
= self
._download
_webpage
_handle
(
410 url
, video_id
, headers
={'User-Agent': 'WhatsApp/2.0'}) # whatsapp ua bypasses problems
412 redirect_url
= urlh
.url
414 api_only
= bool(self
._search
_regex
(
415 r
'(tumblr.com|^)/(safe-mode|login_required|blog/view)',
416 redirect_url
, 'redirect', default
=None))
418 if api_only
and not self
._ACCESS
_TOKEN
:
419 raise ExtractorError('Cannot get data for dashboard-only post without access token')
422 if self
._ACCESS
_TOKEN
:
423 post_json
= traverse_obj(
425 f
'https://www.tumblr.com/api/v2/blog/{blog}/posts/{video_id}/permalink',
426 video_id
, headers
={'Authorization': f
'Bearer {self._ACCESS_TOKEN}'}, fatal
=False),
427 ('response', 'timeline', 'elements', 0, {dict}
)) or {}
428 content_json
= traverse_obj(post_json
, ((('trail', 0), None), 'content', ..., {dict}
))
430 # the url we're extracting from might be an original post or it might be a reblog.
431 # if it's a reblog, og:description will be the reblogger's comment, not the uploader's.
432 # content_json is always the op, so if it exists but has no text, there's no description
434 description
= '\n\n'.join(
435 item
.get('text') for item
in content_json
if item
.get('type') == 'text') or None
437 description
= self
._og
_search
_description
(webpage
, default
=None)
438 uploader_id
= traverse_obj(post_json
, 'reblogged_root_name', 'blog_name')
442 'title': post_json
.get('summary') or (blog
if api_only
else self
._html
_search
_regex
(
443 r
'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>', webpage
, 'title', default
=blog
)),
444 'description': description
,
445 'uploader_id': uploader_id
,
446 'uploader_url': f
'https://{uploader_id}.tumblr.com/' if uploader_id
else None,
447 **traverse_obj(post_json
, {
448 'like_count': ('like_count', {int_or_none}
),
449 'repost_count': ('reblog_count', {int_or_none}
),
450 'tags': ('tags', ..., {str}
),
452 'age_limit': {True: 18, False: 0}.get(post_json
.get('is_nsfw')),
455 # for tumblr's own video hosting
456 fallback_format
= None
458 video_url
= self
._og
_search
_video
_url
(webpage
, default
=None)
459 # for external video hosts
461 ignored_providers
= set()
462 unknown_providers
= set()
464 for video_json
in traverse_obj(content_json
, lambda _
, v
: v
['type'] in ('video', 'audio')):
465 media_json
= video_json
.get('media') or {}
466 if api_only
and not media_json
.get('url') and not video_json
.get('url'):
467 raise ExtractorError('Failed to find video data for dashboard-only post')
468 provider
= video_json
.get('provider')
470 if provider
in ('tumblr', None):
472 'url': media_json
.get('url') or video_url
,
473 'width': int_or_none(
474 media_json
.get('width') or self
._og
_search
_property
('video:width', webpage
, default
=None)),
475 'height': int_or_none(
476 media_json
.get('height') or self
._og
_search
_property
('video:height', webpage
, default
=None)),
479 elif provider
in self
._unsupported
_providers
:
480 ignored_providers
.add(provider
)
482 elif provider
and provider
not in self
._providers
:
483 unknown_providers
.add(provider
)
484 if video_json
.get('url'):
485 # external video host
486 entries
.append(self
.url_result(
487 video_json
['url'], self
._providers
.get(provider
)))
491 # iframes can supply duration and sometimes additional formats, so check for one
492 iframe_url
= self
._search
_regex
(
493 fr
'src=\'(https?
://www\
.tumblr\
.com
/video
/{blog}
/{video_id}
/[^
\']+)\'',
494 webpage, 'iframe url
', default=None)
496 iframe = self._download_webpage(
497 iframe_url, video_id, 'Downloading iframe page
',
498 headers={'Referer
': redirect_url})
500 options = self._parse_json(
502 r'data
-crt
-options
=(["\'])(?P<options>.+?)\1', iframe,
503 'hd video url', default='', group='options'),
504 video_id, fatal=False)
506 duration = int_or_none(options.get('duration'))
508 hd_url = options.get('hdUrl')
510 # there are multiple formats; extract them
511 # ignore other sources of width/height data as they may be wrong
513 sd_url = self._search_regex(
514 r'<source[^>]+src=(["\'])(?P
<url
>.+?
)\
1', iframe,
515 'sd video url
', default=None, group='url
')
517 sources.append((sd_url, 'sd
'))
518 sources.append((hd_url, 'hd
'))
522 'format_id
': format_id,
523 'height
': int_or_none(self._search_regex(
524 r'_(\d
+)\
.\w
+$
', video_url, 'height
', default=None)),
526 } for quality, (video_url, format_id) in enumerate(sources)]
528 if not formats and fallback_format:
529 formats.append(fallback_format)
532 # tumblr's own video
is always above embeds
536 'duration': duration
,
537 'thumbnail': (traverse_obj(video_json
, ('poster', 0, 'url', {url_or_none}
))
538 or self
._og
_search
_thumbnail
(webpage
, default
=None)),
541 if ignored_providers
:
543 raise ExtractorError(f
'None of embed providers are supported: {", ".join(ignored_providers)!s}', video_id
=video_id
, expected
=True)
545 self
.report_warning(f
'Skipped embeds from unsupported providers: {", ".join(ignored_providers)!s}', video_id
)
546 if unknown_providers
:
547 self
.report_warning(f
'Unrecognized providers, please report: {", ".join(unknown_providers)!s}', video_id
)
550 self
.raise_no_formats('No video could be found in this post', expected
=True, video_id
=video_id
)
551 if len(entries
) == 1: