]>
Commit | Line | Data |
---|---|---|
c060b774 PH |
1 | from __future__ import unicode_literals |
2 | ||
ae287755 PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | ExtractorError, | |
8 | ) | |
9 | ||
10 | ||
11 | class TumblrIE(InfoExtractor): | |
9e8ee545 | 12 | _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)($|/)' |
6f5ac90c | 13 | _TEST = { |
c060b774 PH |
14 | 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', |
15 | 'file': '54196191430.mp4', | |
16 | 'md5': '479bb068e5b16462f5176a6828829767', | |
17 | 'info_dict': { | |
18 | "title": "tatiana maslany news" | |
6f5ac90c PH |
19 | } |
20 | } | |
ae287755 PH |
21 | |
22 | def _real_extract(self, url): | |
23 | m_url = re.match(self._VALID_URL, url) | |
24 | video_id = m_url.group('id') | |
25 | blog = m_url.group('blog_name') | |
26 | ||
27 | url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id) | |
28 | webpage = self._download_webpage(url, video_id) | |
29 | ||
30 | re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id) | |
31 | video = re.search(re_video, webpage) | |
32 | if video is None: | |
c060b774 | 33 | raise ExtractorError('Unable to extract video') |
ae287755 PH |
34 | video_url = video.group('video_url') |
35 | ext = video.group('ext') | |
36 | ||
67379078 MC |
37 | video_thumbnail = self._search_regex( |
38 | r'posters.*?\[\\x22(.*?)\\x22', | |
c060b774 | 39 | webpage, 'thumbnail', fatal=False) # We pick the first poster |
67379078 MC |
40 | if video_thumbnail: |
41 | video_thumbnail = video_thumbnail.replace('\\\\/', '/') | |
ae287755 PH |
42 | |
43 | # The only place where you can get a title, it's not complete, | |
44 | # but searching in other places doesn't work for all videos | |
3f223f7b | 45 | video_title = self._html_search_regex(r'<title>(?P<title>.*?)(?: \| Tumblr)?</title>', |
c060b774 | 46 | webpage, 'title', flags=re.DOTALL) |
ae287755 PH |
47 | |
48 | return [{'id': video_id, | |
49 | 'url': video_url, | |
50 | 'title': video_title, | |
51 | 'thumbnail': video_thumbnail, | |
52 | 'ext': ext | |
53 | }] |