]>
Commit | Line | Data |
---|---|---|
9b27e6c3 | 1 | # -*- coding: utf-8 -*- |
c060b774 PH |
2 | from __future__ import unicode_literals |
3 | ||
ae287755 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
140ac739 | 7 | from ..utils import int_or_none |
ae287755 PH |
8 | |
9 | ||
10 | class TumblrIE(InfoExtractor): | |
3da0e1f8 | 11 | _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])' |
62f1f950 | 12 | _TESTS = [{ |
c060b774 | 13 | 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', |
c060b774 PH |
14 | 'md5': '479bb068e5b16462f5176a6828829767', |
15 | 'info_dict': { | |
62f1f950 PP |
16 | 'id': '54196191430', |
17 | 'ext': 'mp4', | |
18 | 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...', | |
681b9caa | 19 | 'description': 'md5:37db8211e40b50c7c44e95da14f630b7', |
62f1f950 | 20 | 'thumbnail': 're:http://.*\.jpg', |
6f5ac90c | 21 | } |
62f1f950 PP |
22 | }, { |
23 | 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all', | |
24 | 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359', | |
25 | 'info_dict': { | |
26 | 'id': '90208453769', | |
27 | 'ext': 'mp4', | |
681b9caa | 28 | 'title': '5SOS STRUM ;]', |
62f1f950 PP |
29 | 'description': 'md5:dba62ac8639482759c8eb10ce474586a', |
30 | 'thumbnail': 're:http://.*\.jpg', | |
31 | } | |
2a27e662 OA |
32 | }, { |
33 | 'url': 'http://hdvideotest.tumblr.com/post/130323439814/test-description-for-my-hd-video', | |
34 | 'md5': '7ae503065ad150122dc3089f8cf1546c', | |
35 | 'info_dict': { | |
36 | 'id': '130323439814', | |
37 | 'ext': 'mp4', | |
38 | 'title': 'HD Video Testing \u2014 Test description for my HD video', | |
39 | 'description': 'md5:97cc3ab5fcd27ee4af6356701541319c', | |
40 | 'thumbnail': 're:http://.*\.jpg', | |
41 | }, | |
42 | 'params': { | |
43 | 'format': 'hd', | |
44 | }, | |
8f947841 YCH |
45 | }, { |
46 | 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching', | |
47 | 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab', | |
48 | 'info_dict': { | |
49 | 'id': 'Wmur', | |
50 | 'ext': 'mp4', | |
51 | 'title': 'naked smoking & stretching', | |
52 | 'upload_date': '20150506', | |
53 | 'timestamp': 1430931613, | |
88c86d21 S |
54 | 'age_limit': 18, |
55 | 'uploader_id': '1638622', | |
56 | 'uploader': 'naked-yogi', | |
8f947841 YCH |
57 | }, |
58 | 'add_ie': ['Vidme'], | |
c5895d5d YCH |
59 | }, { |
60 | 'url': 'http://camdamage.tumblr.com/post/98846056295/', | |
61 | 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6', | |
62 | 'info_dict': { | |
63 | 'id': '105463834', | |
64 | 'ext': 'mp4', | |
65 | 'title': 'Cam Damage-HD 720p', | |
66 | 'uploader': 'John Moyer', | |
67 | 'uploader_id': 'user32021558', | |
68 | }, | |
69 | 'add_ie': ['Vimeo'], | |
62f1f950 | 70 | }] |
ae287755 PH |
71 | |
72 | def _real_extract(self, url): | |
73 | m_url = re.match(self._VALID_URL, url) | |
74 | video_id = m_url.group('id') | |
75 | blog = m_url.group('blog_name') | |
76 | ||
77 | url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id) | |
c909e582 | 78 | webpage, urlh = self._download_webpage_handle(url, video_id) |
c5895d5d | 79 | |
681b9caa JMF |
80 | iframe_url = self._search_regex( |
81 | r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'', | |
c909e582 YCH |
82 | webpage, 'iframe url', default=None) |
83 | if iframe_url is None: | |
84 | return self.url_result(urlh.geturl(), 'Generic') | |
85 | ||
140ac739 S |
86 | iframe = self._download_webpage(iframe_url, video_id, 'Downloading iframe page') |
87 | ||
88 | duration = None | |
89 | sources = [] | |
90 | ||
91 | sd_url = self._search_regex( | |
92 | r'<source[^>]+src=(["\'])(?P<url>.+?)\1', iframe, | |
93 | 'sd video url', default=None, group='url') | |
94 | if sd_url: | |
95 | sources.append((sd_url, 'sd')) | |
96 | ||
97 | options = self._parse_json( | |
98 | self._search_regex( | |
99 | r'data-crt-options=(["\'])(?P<options>.+?)\1', iframe, | |
100 | 'hd video url', default='', group='options'), | |
101 | video_id, fatal=False) | |
102 | if options: | |
103 | duration = int_or_none(options.get('duration')) | |
104 | hd_url = options.get('hdUrl') | |
105 | if hd_url: | |
106 | sources.append((hd_url, 'hd')) | |
2a27e662 | 107 | |
140ac739 S |
108 | formats = [{ |
109 | 'url': video_url, | |
2a27e662 | 110 | 'ext': 'mp4', |
140ac739 S |
111 | 'format_id': format_id, |
112 | 'height': int_or_none(self._search_regex( | |
113 | r'/(\d{3,4})$', video_url, 'height', default=None)), | |
114 | 'quality': quality, | |
115 | } for quality, (video_url, format_id) in enumerate(sources)] | |
2a27e662 | 116 | |
140ac739 | 117 | self._sort_formats(formats) |
ae287755 PH |
118 | |
119 | # The only place where you can get a title, it's not complete, | |
120 | # but searching in other places doesn't work for all videos | |
3da0e1f8 PH |
121 | video_title = self._html_search_regex( |
122 | r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>', | |
123 | webpage, 'title') | |
ae287755 | 124 | |
3da0e1f8 PH |
125 | return { |
126 | 'id': video_id, | |
681b9caa | 127 | 'title': video_title, |
ae849ca1 YCH |
128 | 'description': self._og_search_description(webpage, default=None), |
129 | 'thumbnail': self._og_search_thumbnail(webpage, default=None), | |
140ac739 S |
130 | 'duration': duration, |
131 | 'formats': formats, | |
3da0e1f8 | 132 | } |