]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tumblr.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
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 login_page
= self
._download
_webpage
(
116 self
._LOGIN
_URL
, None, 'Downloading login page')
118 login_form
= self
._hidden
_inputs
(login_page
)
120 'user[email]': username
,
121 'user[password]': password
124 response
, urlh
= self
._download
_webpage
_handle
(
125 self
._LOGIN
_URL
, None, 'Logging in',
126 data
=urlencode_postdata(login_form
), headers
={
127 'Content-Type': 'application/x-www-form-urlencoded',
128 'Referer': self
._LOGIN
_URL
,
132 if '/dashboard' in urlh
.geturl():
135 login_errors
= self
._parse
_json
(
137 r
'RegistrationForm\.errors\s*=\s*(\[.+?\])\s*;', response
,
138 'login errors', default
='[]'),
141 raise ExtractorError(
142 'Unable to login: %s' % login_errors
[0], expected
=True)
144 self
.report_warning('Login has probably failed')
146 def _real_extract(self
, url
):
147 m_url
= re
.match(self
._VALID
_URL
, url
)
148 video_id
= m_url
.group('id')
149 blog
= m_url
.group('blog_name')
151 url
= 'http://%s.tumblr.com/post/%s/' % (blog
, video_id
)
152 webpage
, urlh
= self
._download
_webpage
_handle
(url
, video_id
)
154 redirect_url
= compat_str(urlh
.geturl())
155 if 'tumblr.com/safe-mode' in redirect_url
or redirect_url
.startswith('/safe-mode'):
156 raise ExtractorError(
157 'This Tumblr may contain sensitive media. '
158 'Disable safe mode in your account settings '
159 'at https://www.tumblr.com/settings/account#safe_mode',
162 iframe_url
= self
._search
_regex
(
163 r
'src=\'(https?
://www\
.tumblr\
.com
/video
/[^
\']+)\'',
164 webpage, 'iframe url
', default=None)
165 if iframe_url is None:
166 return self.url_result(redirect_url, 'Generic
')
168 iframe = self._download_webpage(iframe_url, video_id, 'Downloading iframe page
')
173 sd_url = self._search_regex(
174 r'<source
[^
>]+src
=(["\'])(?P<url>.+?)\1', iframe,
175 'sd video url', default=None, group='url')
177 sources.append((sd_url, 'sd'))
179 options = self._parse_json(
181 r'data-crt-options=(["\'])(?P
<options
>.+?
)\
1', iframe,
182 'hd video url
', default='', group='options
'),
183 video_id, fatal=False)
185 duration = int_or_none(options.get('duration
'))
186 hd_url = options.get('hdUrl
')
188 sources.append((hd_url, 'hd
'))
193 'format_id
': format_id,
194 'height
': int_or_none(self._search_regex(
195 r'/(\d
{3,4})$
', video_url, 'height
', default=None)),
197 } for quality, (video_url, format_id) in enumerate(sources)]
199 self._sort_formats(formats)
201 # The only place where you can get a title, it's
not complete
,
202 # but searching in other places doesn't work for all videos
203 video_title
= self
._html
_search
_regex
(
204 r
'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
209 'title': video_title
,
210 'description': self
._og
_search
_description
(webpage
, default
=None),
211 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
212 'duration': duration
,