2 from __future__ import unicode_literals
6 from .common import InfoExtractor
15 class TumblrIE(InfoExtractor):
16 _VALID_URL = r'https?://(?P<blog_name>[^/?#&]+)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
17 _NETRC_MACHINE = 'tumblr'
18 _LOGIN_URL = 'https://www.tumblr.com/login'
20 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
21 'md5': '479bb068e5b16462f5176a6828829767',
25 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
26 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
27 'thumbnail': r're:http://.*\.jpg',
30 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
31 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
35 'title': '5SOS STRUM ;]',
36 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
37 'thumbnail': r're:http://.*\.jpg',
40 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video',
41 'md5': '7ae503065ad150122dc3089f8cf1546c',
45 'title': 'HD Video Testing \u2014 Test description for my HD video',
46 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c',
47 'thumbnail': r're:http://.*\.jpg',
53 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
54 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
58 'title': 'naked smoking & stretching',
59 'upload_date': '20150506',
60 'timestamp': 1430931613,
62 'uploader_id': '1638622',
63 'uploader': 'naked-yogi',
67 'url': 'http://camdamage.tumblr.com/post/98846056295/',
68 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
72 'title': 'Cam Damage-HD 720p',
73 'uploader': 'John Moyer',
74 'uploader_id': 'user32021558',
78 'url': 'http://sutiblr.tumblr.com/post/139638707273',
79 'md5': '2dd184b3669e049ba40563a7d423f95c',
83 'title': 'Vine by sutiblr',
84 'alt_title': 'Vine by sutiblr',
85 'uploader': 'sutiblr',
86 'uploader_id': '1198993975374495744',
87 'upload_date': '20160220',
94 'url': 'http://vitasidorkina.tumblr.com/post/134652425014/joskriver-victoriassecret-invisibility-or',
95 'md5': '01c12ceb82cbf6b2fe0703aa56b3ad72',
99 'title': 'Video by victoriassecret',
100 'description': 'Invisibility or flight…which superpower would YOU choose? #VSFashionShow #ThisOrThat',
101 'uploader_id': 'victoriassecret',
102 'thumbnail': r're:^https?://.*\.jpg'
104 'add_ie': ['Instagram'],
107 def _real_initialize(self):
111 (username, password) = self._get_login_info()
115 webpage = self._download_webpage(self._LOGIN_URL, None, False)
116 form = self._hidden_inputs(webpage)
118 'user[email]': username,
119 'user[password]': password
121 login_response = self._download_webpage(
122 sanitized_Request(self._LOGIN_URL, urlencode_postdata(form), {
123 'Content-Type': 'application/x-www-form-urlencoded',
124 'Referer': self._LOGIN_URL
125 }), None, False, 'Wrong login info')
127 # Check the login response from Tumblr for an error message and fail the extraction if we find one.
128 login_errors = self._search_regex(r'Tumblr\.RegistrationForm\.errors\s*=\s*\[[\"|\'](.+)[\"|\']\]', login_response, 'login errors', False)
130 raise ExtractorError('Error logging in: %s' % login_errors, expected=True)
132 def _real_extract(self, url):
133 m_url = re.match(self._VALID_URL, url)
134 video_id = m_url.group('id')
135 blog = m_url.group('blog_name')
137 url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
138 webpage, urlh = self._download_webpage_handle(url, video_id)
140 iframe_url = self._search_regex(
141 r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
142 webpage, 'iframe url', default=None)
143 if iframe_url is None:
144 return self.url_result(urlh.geturl(), 'Generic')
146 iframe = self._download_webpage(iframe_url, video_id, 'Downloading iframe page')
151 sd_url = self._search_regex(
152 r'<source[^>]+src=(["\'])(?P<url>.+?)\1', iframe,
153 'sd video url', default=None, group='url')
155 sources.append((sd_url, 'sd'))
157 options = self._parse_json(
159 r'data-crt-options=(["\'])(?P<options>.+?)\1', iframe,
160 'hd video url', default='', group='options'),
161 video_id, fatal=False)
163 duration = int_or_none(options.get('duration'))
164 hd_url = options.get('hdUrl')
166 sources.append((hd_url, 'hd'))
171 'format_id': format_id,
172 'height': int_or_none(self._search_regex(
173 r'/(\d{3,4})$', video_url, 'height', default=None)),
175 } for quality, (video_url, format_id) in enumerate(sources)]
177 self._sort_formats(formats)
179 # The only place where you can get a title, it's not complete,
180 # but searching in other places doesn't work for all videos
181 video_title = self._html_search_regex(
182 r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
187 'title': video_title,
188 'description': self._og_search_description(webpage, default=None),
189 'thumbnail': self._og_search_thumbnail(webpage, default=None),
190 'duration': duration,