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': 'http://sutiblr.tumblr.com/post/139638707273',
194 'md5': '2dd184b3669e049ba40563a7d423f95c',
198 'title': 'Vine by sutiblr',
199 'alt_title': 'Vine by sutiblr',
200 'uploader': 'sutiblr',
201 'uploader_id': '1198993975374495744',
202 'upload_date': '20160220',
204 'comment_count': int,
206 'thumbnail': r
're:^https?://.*\.jpg',
207 'timestamp': 1455940159,
211 'skip': 'Vine is unavailable',
213 'url': 'https://silami.tumblr.com/post/84250043974/my-bad-river-flows-in-you-impression-on-maschine',
214 'md5': '3c92d7c3d867f14ccbeefa2119022277',
218 'title': 'Video by silbulterman',
219 'description': '#maschine',
220 'uploader_id': '242859024',
221 'thumbnail': r
're:^https?://.*\.jpg',
222 'timestamp': 1398801174,
225 'channel': 'silbulterman',
226 'comment_count': int,
227 'upload_date': '20140429',
229 'add_ie': ['Instagram'],
231 'note': 'new url scheme',
232 'url': 'https://www.tumblr.com/autumnsister/765162750456578048?source=share',
234 'id': '765162750456578048',
236 'uploader_url': 'https://autumnsister.tumblr.com/',
237 'tags': ['autumn', 'food', 'curators on tumblr'],
239 'thumbnail': 'https://64.media.tumblr.com/tumblr_sklad89N3x1ygquow_frame1.jpg',
241 'uploader_id': 'autumnsister',
246 'note': 'bandcamp album embed',
247 'url': 'https://patricia-taxxon.tumblr.com/post/704473755725004800/patricia-taxxon-agnes-hilda-patricia-taxxon',
250 'title': 'Agnes & Hilda',
251 'description': 'The inexplicable joy of an artist. Wash paws after listening.',
252 'uploader_id': 'patriciataxxon',
256 'note': 'bandcamp track embeds (many)',
257 'url': 'https://www.tumblr.com/felixcosm/730460905855467520/if-youre-looking-for-new-music-to-write-or',
259 'id': '730460905855467520',
260 'uploader_id': 'felixcosm',
263 'description': 'md5:2eb3482a3c6987280cbefb6839068f32',
266 'title': 'If you\'re looking for new music to write or imagine scenerios to: STOP. This is for you.',
267 'uploader_url': 'https://felixcosm.tumblr.com/',
269 'playlist_count': 10,
271 'note': 'soundcloud track embed',
272 'url': 'https://silverfoxstole.tumblr.com/post/765305403763556352/jamie-robertson-doctor-who-8th-doctor',
276 'comment_count': int,
279 'uploader': 'Jamie Robertson',
280 'title': 'Doctor Who - 8th doctor - Stranded Theme never released and used.',
282 'uploader_id': '2731064',
283 'thumbnail': 'https://i1.sndcdn.com/artworks-MVgcPm5jN42isC5M-6Dz22w-original.jpg',
284 'timestamp': 1645181261,
285 'uploader_url': 'https://soundcloud.com/jamierobertson',
287 'upload_date': '20220218',
288 'description': 'md5:ab924dd9994d0a7d64d6d31bf2af4625',
289 'license': 'all-rights-reserved',
293 'note': 'soundcloud set embed',
294 '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',
297 'title': '心的呼喚 Call of the heart I',
298 'description': 'md5:25952a8d178a3aa55e40fcbb646a38c3',
300 'playlist_mincount': 19,
302 'note': 'dailymotion video embed',
303 'url': 'https://www.tumblr.com/funvibecentral/759390024460632064',
307 'description': 'Funny dailymotion shorts.\n#funny #fun#comedy #romantic #exciting',
308 'uploader': 'FunVibe Central',
311 'timestamp': 1724210553,
312 'title': 'Woman watching other Woman',
314 'upload_date': '20240821',
316 'uploader_id': 'x32m6ye',
318 'thumbnail': r
're:https://(?:s[12]\.)dmcdn\.net/v/Wtqh01cnxKNXLG1N8/x1080',
321 'note': 'tiktok video embed',
322 'url': 'https://fansofcolor.tumblr.com/post/660637918605475840/blockquote-class-tiktok-embed',
324 'id': '7000937272010935558',
326 'artists': ['Alicia Dreaming'],
329 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
330 'channel_id': 'MS4wLjABAAAAsJohwz_dU4KfAOc61cbGDAZ46-5hg2ANTXVQlRe1ipDhpX08PywR3PPiple1NTAo',
331 'uploader': 'aliciadreaming',
332 'description': 'huge casting news Greyworm will be #louisdulac #racebending #interviewwiththevampire',
333 'title': 'huge casting news Greyworm will be #louisdulac #racebending #interviewwiththevampire',
334 'channel_url': 'https://www.tiktok.com/@MS4wLjABAAAAsJohwz_dU4KfAOc61cbGDAZ46-5hg2ANTXVQlRe1ipDhpX08PywR3PPiple1NTAo',
335 'uploader_id': '7000478462196990982',
336 'uploader_url': 'https://www.tiktok.com/@aliciadreaming',
337 'timestamp': 1630032733,
338 'channel': 'Alicia Dreaming',
339 'track': 'original sound',
340 'upload_date': '20210827',
342 'comment_count': int,
346 'note': 'tumblr video AND youtube embed',
347 'url': 'https://www.tumblr.com/anyaboz/765332564457209856/my-music-video-for-selkie-by-nobodys-wolf-child',
349 'id': '765332564457209856',
350 'uploader_id': 'anyaboz',
353 'uploader_url': 'https://anyaboz.tumblr.com/',
354 'description': 'md5:9a129cf6ce9d87a80ffd3c6dedd4d1e6',
356 'title': 'md5:b18a2ac9387681d20303e485db85c1b5',
357 'tags': ['music video', 'nobodys wolf child', 'selkie', 'Stop Motion Animation', 'stop Motion', 'room guardians', 'Youtube'],
361 # twitch_live provider - error when linked account is not live
362 'url': 'https://www.tumblr.com/anarcho-skamunist/722224493650722816/hollow-knight-stream-right-now-going-to-fight',
363 'only_matching': True,
367 'instagram': 'Instagram',
370 'youtube': 'Youtube',
371 'dailymotion': 'Dailymotion',
373 'twitch_live': 'TwitchStream',
377 # known not to be supported
378 _unsupported_providers
= {
379 # seems like podcasts can't be embedded
385 def _initialize_pre_login(self
):
386 login_page
= self
._download
_webpage
(
387 self
._LOGIN
_URL
, None, 'Downloading login page', fatal
=False)
389 self
._ACCESS
_TOKEN
= self
._search
_regex
(
390 r
'"API_TOKEN":\s*"(\w+)"', login_page
, 'API access token', fatal
=False)
391 if not self
._ACCESS
_TOKEN
:
392 self
.report_warning('Failed to get access token; metadata will be missing and some videos may not work')
394 def _perform_login(self
, username
, password
):
395 if not self
._ACCESS
_TOKEN
:
399 'password': password
,
400 'grant_type': 'password',
401 'username': username
,
403 if self
.get_param('twofactor'):
404 data
['tfa_token'] = self
.get_param('twofactor')
407 return self
._download
_json
(
408 self
._OAUTH
_URL
, None, 'Logging in',
409 data
=urlencode_postdata(data
),
411 'Content-Type': 'application/x-www-form-urlencoded',
412 'Authorization': f
'Bearer {self._ACCESS_TOKEN}',
414 errnote
='Login failed', fatal
=False,
415 expected_status
=lambda s
: 400 <= s
< 500)
417 response
= _call_login()
418 if traverse_obj(response
, 'error') == 'tfa_required':
419 data
['tfa_token'] = self
._get
_tfa
_info
()
420 response
= _call_login()
421 if traverse_obj(response
, 'error'):
422 raise ExtractorError(
423 f
'API returned error {": ".join(traverse_obj(response, (("error", "error_description"), {str})))}')
425 def _real_extract(self
, url
):
426 blog_1
, blog_2
, video_id
= self
._match
_valid
_url
(url
).groups()
427 blog
= blog_2
or blog_1
429 url
= f
'http://{blog}.tumblr.com/post/{video_id}'
430 webpage
, urlh
= self
._download
_webpage
_handle
(
431 url
, video_id
, headers
={'User-Agent': 'WhatsApp/2.0'}) # whatsapp ua bypasses problems
433 redirect_url
= urlh
.url
435 api_only
= bool(self
._search
_regex
(
436 r
'(tumblr.com|^)/(safe-mode|login_required|blog/view)',
437 redirect_url
, 'redirect', default
=None))
439 if api_only
and not self
._ACCESS
_TOKEN
:
440 raise ExtractorError('Cannot get data for dashboard-only post without access token')
443 if self
._ACCESS
_TOKEN
:
444 post_json
= traverse_obj(
446 f
'https://www.tumblr.com/api/v2/blog/{blog}/posts/{video_id}/permalink',
447 video_id
, headers
={'Authorization': f
'Bearer {self._ACCESS_TOKEN}'}, fatal
=False),
448 ('response', 'timeline', 'elements', 0, {dict}
)) or {}
449 content_json
= traverse_obj(post_json
, ((('trail', 0), None), 'content', ..., {dict}
))
451 # the url we're extracting from might be an original post or it might be a reblog.
452 # if it's a reblog, og:description will be the reblogger's comment, not the uploader's.
453 # content_json is always the op, so if it exists but has no text, there's no description
455 description
= '\n\n'.join(
456 item
.get('text') for item
in content_json
if item
.get('type') == 'text') or None
458 description
= self
._og
_search
_description
(webpage
, default
=None)
459 uploader_id
= traverse_obj(post_json
, 'reblogged_root_name', 'blog_name')
463 'title': post_json
.get('summary') or (blog
if api_only
else self
._html
_search
_regex
(
464 r
'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>', webpage
, 'title', default
=blog
)),
465 'description': description
,
466 'uploader_id': uploader_id
,
467 'uploader_url': f
'https://{uploader_id}.tumblr.com/' if uploader_id
else None,
468 **traverse_obj(post_json
, {
469 'like_count': ('like_count', {int_or_none}
),
470 'repost_count': ('reblog_count', {int_or_none}
),
471 'tags': ('tags', ..., {str}
),
473 'age_limit': {True: 18, False: 0}.get(post_json
.get('is_nsfw')),
476 # for tumblr's own video hosting
477 fallback_format
= None
479 video_url
= self
._og
_search
_video
_url
(webpage
, default
=None)
480 # for external video hosts
482 ignored_providers
= set()
483 unknown_providers
= set()
485 for video_json
in traverse_obj(content_json
, lambda _
, v
: v
['type'] in ('video', 'audio')):
486 media_json
= video_json
.get('media') or {}
487 if api_only
and not media_json
.get('url') and not video_json
.get('url'):
488 raise ExtractorError('Failed to find video data for dashboard-only post')
489 provider
= video_json
.get('provider')
491 if provider
in ('tumblr', None):
493 'url': media_json
.get('url') or video_url
,
494 'width': int_or_none(
495 media_json
.get('width') or self
._og
_search
_property
('video:width', webpage
, default
=None)),
496 'height': int_or_none(
497 media_json
.get('height') or self
._og
_search
_property
('video:height', webpage
, default
=None)),
500 elif provider
in self
._unsupported
_providers
:
501 ignored_providers
.add(provider
)
503 elif provider
and provider
not in self
._providers
:
504 unknown_providers
.add(provider
)
505 if video_json
.get('url'):
506 # external video host
507 entries
.append(self
.url_result(
508 video_json
['url'], self
._providers
.get(provider
)))
512 # iframes can supply duration and sometimes additional formats, so check for one
513 iframe_url
= self
._search
_regex
(
514 fr
'src=\'(https?
://www\
.tumblr\
.com
/video
/{blog}
/{video_id}
/[^
\']+)\'',
515 webpage, 'iframe url
', default=None)
517 iframe = self._download_webpage(
518 iframe_url, video_id, 'Downloading iframe page
',
519 headers={'Referer
': redirect_url})
521 options = self._parse_json(
523 r'data
-crt
-options
=(["\'])(?P<options>.+?)\1', iframe,
524 'hd video url', default='', group='options'),
525 video_id, fatal=False)
527 duration = int_or_none(options.get('duration'))
529 hd_url = options.get('hdUrl')
531 # there are multiple formats; extract them
532 # ignore other sources of width/height data as they may be wrong
534 sd_url = self._search_regex(
535 r'<source[^>]+src=(["\'])(?P
<url
>.+?
)\
1', iframe,
536 'sd video url
', default=None, group='url
')
538 sources.append((sd_url, 'sd
'))
539 sources.append((hd_url, 'hd
'))
543 'format_id
': format_id,
544 'height
': int_or_none(self._search_regex(
545 r'_(\d
+)\
.\w
+$
', video_url, 'height
', default=None)),
547 } for quality, (video_url, format_id) in enumerate(sources)]
549 if not formats and fallback_format:
550 formats.append(fallback_format)
553 # tumblr's own video
is always above embeds
557 'duration': duration
,
558 'thumbnail': (traverse_obj(video_json
, ('poster', 0, 'url', {url_or_none}
))
559 or self
._og
_search
_thumbnail
(webpage
, default
=None)),
562 if ignored_providers
:
564 raise ExtractorError(f
'None of embed providers are supported: {", ".join(ignored_providers)!s}', video_id
=video_id
, expected
=True)
566 self
.report_warning(f
'Skipped embeds from unsupported providers: {", ".join(ignored_providers)!s}', video_id
)
567 if unknown_providers
:
568 self
.report_warning(f
'Unrecognized providers, please report: {", ".join(unknown_providers)!s}', video_id
)
571 self
.raise_no_formats('No video could be found in this post', expected
=True, video_id
=video_id
)
572 if len(entries
) == 1: