]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/tumblr.py
[spiegeltv] Skip invalid m3u8 manifests (closes #6157)
[youtube-dl] / youtube_dl / extractor / tumblr.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .pornhub import PornHubIE
8 from .vimeo import VimeoIE
9
10
11 class TumblrIE(InfoExtractor):
12     _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
13     _TESTS = [{
14         'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
15         'md5': '479bb068e5b16462f5176a6828829767',
16         'info_dict': {
17             'id': '54196191430',
18             'ext': 'mp4',
19             'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
20             'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
21             'thumbnail': 're:http://.*\.jpg',
22         }
23     }, {
24         'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
25         'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
26         'info_dict': {
27             'id': '90208453769',
28             'ext': 'mp4',
29             'title': '5SOS STRUM ;]',
30             'description': 'md5:dba62ac8639482759c8eb10ce474586a',
31             'thumbnail': 're:http://.*\.jpg',
32         }
33     }, {
34         'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
35         'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
36         'info_dict': {
37             'id': 'Wmur',
38             'ext': 'mp4',
39             'title': 'naked smoking & stretching',
40             'upload_date': '20150506',
41             'timestamp': 1430931613,
42         },
43         'add_ie': ['Vidme'],
44     }, {
45         'url': 'http://camdamage.tumblr.com/post/98846056295/',
46         'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
47         'info_dict': {
48             'id': '105463834',
49             'ext': 'mp4',
50             'title': 'Cam Damage-HD 720p',
51             'uploader': 'John Moyer',
52             'uploader_id': 'user32021558',
53         },
54         'add_ie': ['Vimeo'],
55     }]
56
57     def _real_extract(self, url):
58         m_url = re.match(self._VALID_URL, url)
59         video_id = m_url.group('id')
60         blog = m_url.group('blog_name')
61
62         url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
63         webpage = self._download_webpage(url, video_id)
64
65         vid_me_embed_url = self._search_regex(
66             r'src=[\'"](https?://vid\.me/[^\'"]+)[\'"]',
67             webpage, 'vid.me embed', default=None)
68         if vid_me_embed_url is not None:
69             return self.url_result(vid_me_embed_url, 'Vidme')
70
71         pornhub_url = PornHubIE._extract_url(webpage)
72         if pornhub_url:
73             return self.url_result(pornhub_url, 'PornHub')
74
75         vimeo_url = VimeoIE._extract_vimeo_url(url, webpage)
76         if vimeo_url:
77             return self.url_result(vimeo_url, 'Vimeo')
78
79         iframe_url = self._search_regex(
80             r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
81             webpage, 'iframe url')
82         iframe = self._download_webpage(iframe_url, video_id)
83         video_url = self._search_regex(r'<source src="([^"]+)"',
84                                        iframe, 'video url')
85
86         # The only place where you can get a title, it's not complete,
87         # but searching in other places doesn't work for all videos
88         video_title = self._html_search_regex(
89             r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
90             webpage, 'title')
91
92         return {
93             'id': video_id,
94             'url': video_url,
95             'ext': 'mp4',
96             'title': video_title,
97             'description': self._og_search_description(webpage, default=None),
98             'thumbnail': self._og_search_thumbnail(webpage, default=None),
99         }