1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 class TumblrIE(InfoExtractor):
10 _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
12 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
13 'md5': '479bb068e5b16462f5176a6828829767',
17 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
18 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
19 'thumbnail': 're:http://.*\.jpg',
22 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
23 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
27 'title': '5SOS STRUM ;]',
28 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
29 'thumbnail': 're:http://.*\.jpg',
32 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video',
33 'md5': '99a84522f60972bf064a0b80f87bcbb5',
37 'title': 'HD Video Testing \u2014 Test description for my HD video',
38 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c',
39 'thumbnail': 're:http://.*\.jpg',
45 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video',
46 'md5': '7ae503065ad150122dc3089f8cf1546c',
50 'title': 'HD Video Testing \u2014 Test description for my HD video',
51 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c',
52 'thumbnail': 're:http://.*\.jpg',
58 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
59 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
63 'title': 'naked smoking & stretching',
64 'upload_date': '20150506',
65 'timestamp': 1430931613,
69 'url': 'http://camdamage.tumblr.com/post/98846056295/',
70 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
74 'title': 'Cam Damage-HD 720p',
75 'uploader': 'John Moyer',
76 'uploader_id': 'user32021558',
81 def _real_extract(self, url):
82 m_url = re.match(self._VALID_URL, url)
83 video_id = m_url.group('id')
84 blog = m_url.group('blog_name')
88 url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
89 webpage, urlh = self._download_webpage_handle(url, video_id)
91 iframe_url = self._search_regex(
92 r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
93 webpage, 'iframe url', default=None)
94 if iframe_url is None:
95 return self.url_result(urlh.geturl(), 'Generic')
97 iframe = self._download_webpage(iframe_url, video_id,
98 'Downloading iframe page')
100 sd_video_url = self._search_regex(r'<source src="([^"]+)"',
101 iframe, 'sd video url')
102 resolution_id = sd_video_url.split("/")[-1] + 'p'
103 if len(resolution_id) != 4:
109 'resolution': resolution_id,
112 hd_video_url = self._search_regex(r'hdUrl":"([^"]+)"', iframe,
113 'hd video url', default=None)
115 hd_video_url = hd_video_url.replace("\\", "")
116 resolution_id = hd_video_url.split("/")[-1] + 'p'
117 if len(resolution_id) != 4:
123 'resolution': resolution_id,
126 # The only place where you can get a title, it's not complete,
127 # but searching in other places doesn't work for all videos
128 video_title = self._html_search_regex(
129 r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
134 'formats': video_urls,
136 'title': video_title,
137 'description': self._og_search_description(webpage, default=None),
138 'thumbnail': self._og_search_thumbnail(webpage, default=None),