]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tumblr.py
debian/changelog: Start new release.
[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 from ..utils import (
8 ExtractorError,
9 )
10
11
12 class TumblrIE(InfoExtractor):
13 _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)($|/)'
14 _TESTS = [{
15 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
16 'md5': '479bb068e5b16462f5176a6828829767',
17 'info_dict': {
18 'id': '54196191430',
19 'ext': 'mp4',
20 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
21 'description': 'md5:dfac39636969fe6bf1caa2d50405f069',
22 'thumbnail': 're:http://.*\.jpg',
23 }
24 }, {
25 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
26 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
27 'info_dict': {
28 'id': '90208453769',
29 'ext': 'mp4',
30 'title': '5SOS STRUM ;)',
31 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
32 'thumbnail': 're:http://.*\.jpg',
33 }
34 }]
35
36 def _real_extract(self, url):
37 m_url = re.match(self._VALID_URL, url)
38 video_id = m_url.group('id')
39 blog = m_url.group('blog_name')
40
41 url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
42 webpage = self._download_webpage(url, video_id)
43
44 re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
45 video = re.search(re_video, webpage)
46 if video is None:
47 raise ExtractorError('Unable to extract video')
48 video_url = video.group('video_url')
49 ext = video.group('ext')
50
51 video_thumbnail = self._search_regex(
52 r'posters.*?\[\\x22(.*?)\\x22',
53 webpage, 'thumbnail', fatal=False) # We pick the first poster
54 if video_thumbnail:
55 video_thumbnail = video_thumbnail.replace('\\\\/', '/')
56
57 # The only place where you can get a title, it's not complete,
58 # but searching in other places doesn't work for all videos
59 video_title = self._html_search_regex(r'<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
60 webpage, 'title', flags=re.DOTALL)
61
62 return [{'id': video_id,
63 'url': video_url,
64 'title': video_title,
65 'description': self._html_search_meta('description', webpage),
66 'thumbnail': video_thumbnail,
67 'ext': ext
68 }]