]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tumblr.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class TumblrIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?P<blog_name>[^/?#&]+)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
16 _NETRC_MACHINE
= 'tumblr'
17 _LOGIN_URL
= 'https://www.tumblr.com/login'
19 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
20 'md5': '479bb068e5b16462f5176a6828829767',
24 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
25 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
26 'thumbnail': r
're:http://.*\.jpg',
29 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
30 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
34 'title': '5SOS STRUM ;]',
35 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
36 'thumbnail': r
're:http://.*\.jpg',
39 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video',
40 'md5': '7ae503065ad150122dc3089f8cf1546c',
44 'title': 'HD Video Testing \u2014 Test description for my HD video',
45 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c',
46 'thumbnail': r
're:http://.*\.jpg',
52 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
53 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
57 'title': 'naked smoking & stretching',
58 'upload_date': '20150506',
59 'timestamp': 1430931613,
61 'uploader_id': '1638622',
62 'uploader': 'naked-yogi',
66 'url': 'http://camdamage.tumblr.com/post/98846056295/',
67 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
71 'title': 'Cam Damage-HD 720p',
72 'uploader': 'John Moyer',
73 'uploader_id': 'user32021558',
77 'url': 'http://sutiblr.tumblr.com/post/139638707273',
78 'md5': '2dd184b3669e049ba40563a7d423f95c',
82 'title': 'Vine by sutiblr',
83 'alt_title': 'Vine by sutiblr',
84 'uploader': 'sutiblr',
85 'uploader_id': '1198993975374495744',
86 'upload_date': '20160220',
93 'url': 'http://vitasidorkina.tumblr.com/post/134652425014/joskriver-victoriassecret-invisibility-or',
94 'md5': '01c12ceb82cbf6b2fe0703aa56b3ad72',
98 'title': 'Video by victoriassecret',
99 'description': 'Invisibility or flight…which superpower would YOU choose? #VSFashionShow #ThisOrThat',
100 'uploader_id': 'victoriassecret',
101 'thumbnail': r
're:^https?://.*\.jpg'
103 'add_ie': ['Instagram'],
106 def _real_initialize(self
):
110 username
, password
= self
._get
_login
_info
()
114 login_page
= self
._download
_webpage
(
115 self
._LOGIN
_URL
, None, 'Downloading login page')
117 login_form
= self
._hidden
_inputs
(login_page
)
119 'user[email]': username
,
120 'user[password]': password
123 response
, urlh
= self
._download
_webpage
_handle
(
124 self
._LOGIN
_URL
, None, 'Logging in',
125 data
=urlencode_postdata(login_form
), headers
={
126 'Content-Type': 'application/x-www-form-urlencoded',
127 'Referer': self
._LOGIN
_URL
,
131 if '/dashboard' in urlh
.geturl():
134 login_errors
= self
._parse
_json
(
136 r
'RegistrationForm\.errors\s*=\s*(\[.+?\])\s*;', response
,
137 'login errors', default
='[]'),
140 raise ExtractorError(
141 'Unable to login: %s' % login_errors
[0], expected
=True)
143 self
.report_warning('Login has probably failed')
145 def _real_extract(self
, url
):
146 m_url
= re
.match(self
._VALID
_URL
, url
)
147 video_id
= m_url
.group('id')
148 blog
= m_url
.group('blog_name')
150 url
= 'http://%s.tumblr.com/post/%s/' % (blog
, video_id
)
151 webpage
, urlh
= self
._download
_webpage
_handle
(url
, video_id
)
153 redirect_url
= urlh
.geturl()
154 if 'tumblr.com/safe-mode' in redirect_url
or redirect_url
.startswith('/safe-mode'):
155 raise ExtractorError(
156 'This Tumblr may contain sensitive media. '
157 'Disable safe mode in your account settings '
158 'at https://www.tumblr.com/settings/account#safe_mode',
161 iframe_url
= self
._search
_regex
(
162 r
'src=\'(https?
://www\
.tumblr\
.com
/video
/[^
\']+)\'',
163 webpage, 'iframe url
', default=None)
164 if iframe_url is None:
165 return self.url_result(redirect_url, 'Generic
')
167 iframe = self._download_webpage(iframe_url, video_id, 'Downloading iframe page
')
172 sd_url = self._search_regex(
173 r'<source
[^
>]+src
=(["\'])(?P<url>.+?)\1', iframe,
174 'sd video url', default=None, group='url')
176 sources.append((sd_url, 'sd'))
178 options = self._parse_json(
180 r'data-crt-options=(["\'])(?P
<options
>.+?
)\
1', iframe,
181 'hd video url
', default='', group='options
'),
182 video_id, fatal=False)
184 duration = int_or_none(options.get('duration
'))
185 hd_url = options.get('hdUrl
')
187 sources.append((hd_url, 'hd
'))
192 'format_id
': format_id,
193 'height
': int_or_none(self._search_regex(
194 r'/(\d
{3,4})$
', video_url, 'height
', default=None)),
196 } for quality, (video_url, format_id) in enumerate(sources)]
198 self._sort_formats(formats)
200 # The only place where you can get a title, it's
not complete
,
201 # but searching in other places doesn't work for all videos
202 video_title
= self
._html
_search
_regex
(
203 r
'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
208 'title': video_title
,
209 'description': self
._og
_search
_description
(webpage
, default
=None),
210 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
211 'duration': duration
,