]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tumblr.py
debian/control: Prefer mplayer to mplayer2 in Recommends.
[youtubedl] / 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
8
9 class TumblrIE(InfoExtractor):
10 _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
11 _TESTS = [{
12 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
13 'md5': '479bb068e5b16462f5176a6828829767',
14 'info_dict': {
15 'id': '54196191430',
16 'ext': 'mp4',
17 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
18 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
19 'thumbnail': 're:http://.*\.jpg',
20 }
21 }, {
22 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
23 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
24 'info_dict': {
25 'id': '90208453769',
26 'ext': 'mp4',
27 'title': '5SOS STRUM ;]',
28 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
29 'thumbnail': 're:http://.*\.jpg',
30 }
31 }, {
32 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
33 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
34 'info_dict': {
35 'id': 'Wmur',
36 'ext': 'mp4',
37 'title': 'naked smoking & stretching',
38 'upload_date': '20150506',
39 'timestamp': 1430931613,
40 },
41 'add_ie': ['Vidme'],
42 }, {
43 'url': 'http://camdamage.tumblr.com/post/98846056295/',
44 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
45 'info_dict': {
46 'id': '105463834',
47 'ext': 'mp4',
48 'title': 'Cam Damage-HD 720p',
49 'uploader': 'John Moyer',
50 'uploader_id': 'user32021558',
51 },
52 'add_ie': ['Vimeo'],
53 }]
54
55 def _real_extract(self, url):
56 m_url = re.match(self._VALID_URL, url)
57 video_id = m_url.group('id')
58 blog = m_url.group('blog_name')
59
60 url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
61 webpage, urlh = self._download_webpage_handle(url, video_id)
62
63 iframe_url = self._search_regex(
64 r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
65 webpage, 'iframe url', default=None)
66 if iframe_url is None:
67 return self.url_result(urlh.geturl(), 'Generic')
68
69 iframe = self._download_webpage(iframe_url, video_id,
70 'Downloading iframe page')
71 video_url = self._search_regex(r'<source src="([^"]+)"',
72 iframe, 'video url')
73
74 # The only place where you can get a title, it's not complete,
75 # but searching in other places doesn't work for all videos
76 video_title = self._html_search_regex(
77 r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
78 webpage, 'title')
79
80 return {
81 'id': video_id,
82 'url': video_url,
83 'ext': 'mp4',
84 'title': video_title,
85 'description': self._og_search_description(webpage, default=None),
86 'thumbnail': self._og_search_thumbnail(webpage, default=None),
87 }