]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tumblr.py
2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
13 class TumblrIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?P<blog_name>[^/?#&]+)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
15 _NETRC_MACHINE
= 'tumblr'
16 _LOGIN_URL
= 'https://www.tumblr.com/login'
18 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
19 'md5': '479bb068e5b16462f5176a6828829767',
23 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
24 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
25 'thumbnail': r
're:http://.*\.jpg',
28 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
29 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
33 'title': '5SOS STRUM ;]',
34 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
35 'thumbnail': r
're:http://.*\.jpg',
38 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video',
39 'md5': '7ae503065ad150122dc3089f8cf1546c',
43 'title': 'HD Video Testing \u2014 Test description for my HD video',
44 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c',
45 'thumbnail': r
're:http://.*\.jpg',
51 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
52 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
56 'title': 'naked smoking & stretching',
57 'upload_date': '20150506',
58 'timestamp': 1430931613,
60 'uploader_id': '1638622',
61 'uploader': 'naked-yogi',
65 'url': 'http://camdamage.tumblr.com/post/98846056295/',
66 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
70 'title': 'Cam Damage-HD 720p',
71 'uploader': 'John Moyer',
72 'uploader_id': 'user32021558',
76 'url': 'http://sutiblr.tumblr.com/post/139638707273',
77 'md5': '2dd184b3669e049ba40563a7d423f95c',
81 'title': 'Vine by sutiblr',
82 'alt_title': 'Vine by sutiblr',
83 'uploader': 'sutiblr',
84 'uploader_id': '1198993975374495744',
85 'upload_date': '20160220',
92 'url': 'http://vitasidorkina.tumblr.com/post/134652425014/joskriver-victoriassecret-invisibility-or',
93 'md5': '01c12ceb82cbf6b2fe0703aa56b3ad72',
97 'title': 'Video by victoriassecret',
98 'description': 'Invisibility or flight…which superpower would YOU choose? #VSFashionShow #ThisOrThat',
99 'uploader_id': 'victoriassecret',
100 'thumbnail': r
're:^https?://.*\.jpg'
102 'add_ie': ['Instagram'],
105 def _real_initialize(self
):
109 username
, password
= self
._get
_login
_info
()
113 login_page
= self
._download
_webpage
(
114 self
._LOGIN
_URL
, None, 'Downloading login page')
116 login_form
= self
._hidden
_inputs
(login_page
)
118 'user[email]': username
,
119 'user[password]': password
122 response
, urlh
= self
._download
_webpage
_handle
(
123 self
._LOGIN
_URL
, None, 'Logging in',
124 data
=urlencode_postdata(login_form
), headers
={
125 'Content-Type': 'application/x-www-form-urlencoded',
126 'Referer': self
._LOGIN
_URL
,
130 if '/dashboard' in urlh
.geturl():
133 login_errors
= self
._parse
_json
(
135 r
'RegistrationForm\.errors\s*=\s*(\[.+?\])\s*;', response
,
136 'login errors', default
='[]'),
139 raise ExtractorError(
140 'Unable to login: %s' % login_errors
[0], expected
=True)
142 self
.report_warning('Login has probably failed')
144 def _real_extract(self
, url
):
145 m_url
= self
._match
_valid
_url
(url
)
146 video_id
= m_url
.group('id')
147 blog
= m_url
.group('blog_name')
149 url
= 'http://%s.tumblr.com/post/%s/' % (blog
, video_id
)
150 webpage
, urlh
= self
._download
_webpage
_handle
(url
, video_id
)
152 redirect_url
= urlh
.geturl()
153 if 'tumblr.com/safe-mode' in redirect_url
or redirect_url
.startswith('/safe-mode'):
154 raise ExtractorError(
155 'This Tumblr may contain sensitive media. '
156 'Disable safe mode in your account settings '
157 'at https://www.tumblr.com/settings/account#safe_mode',
160 iframe_url
= self
._search
_regex
(
161 r
'src=\'(https?
://www\
.tumblr\
.com
/video
/[^
\']+)\'',
162 webpage, 'iframe url
', default=None)
163 if iframe_url is None:
164 return self.url_result(redirect_url, 'Generic
')
166 iframe = self._download_webpage(iframe_url, video_id, 'Downloading iframe page
')
171 sd_url = self._search_regex(
172 r'<source
[^
>]+src
=(["\'])(?P<url>.+?)\1', iframe,
173 'sd video url', default=None, group='url')
175 sources.append((sd_url, 'sd'))
177 options = self._parse_json(
179 r'data-crt-options=(["\'])(?P
<options
>.+?
)\
1', iframe,
180 'hd video url
', default='', group='options
'),
181 video_id, fatal=False)
183 duration = int_or_none(options.get('duration
'))
184 hd_url = options.get('hdUrl
')
186 sources.append((hd_url, 'hd
'))
191 'format_id
': format_id,
192 'height
': int_or_none(self._search_regex(
193 r'/(\d{3,4}
)$
', video_url, 'height
', default=None)),
195 } for quality, (video_url, format_id) in enumerate(sources)]
197 self._sort_formats(formats)
199 # The only place where you can get a title, it's
not complete
,
200 # but searching in other places doesn't work for all videos
201 video_title
= self
._html
_search
_regex
(
202 r
'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
207 'title': video_title
,
208 'description': self
._og
_search
_description
(webpage
, default
=None),
209 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
210 'duration': duration
,