from __future__ import unicode_literals import re from .common import InfoExtractor from ..utils import ( ExtractorError, ) class TumblrIE(InfoExtractor): _VALID_URL = r'http://(?P.*?)\.tumblr\.com/((post)|(video))/(?P\d*)($|/)' _TEST = { 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', 'file': '54196191430.mp4', 'md5': '479bb068e5b16462f5176a6828829767', 'info_dict': { "title": "tatiana maslany news" } } def _real_extract(self, url): m_url = re.match(self._VALID_URL, url) video_id = m_url.group('id') blog = m_url.group('blog_name') url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id) webpage = self._download_webpage(url, video_id) re_video = r'src=\\x22(?Phttp://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P.*?)\\x22' % (blog, video_id) video = re.search(re_video, webpage) if video is None: raise ExtractorError('Unable to extract video') video_url = video.group('video_url') ext = video.group('ext') # retrieve all available thumbnails thumb_list = [] ma = re.search(r'posters.*?\[(?P\\x22.*?\\x22)]', webpage) if not ma is None: for t in ma.group('thumb').replace('\\\\/', '/').split(','): t = t.replace('\\x22','"') if (t[0]=='"') and (t[-1]=='"'): thumb_list.append(t[1:-1]) # take the first, if user only wants one single_thumb = None if len(thumb_list)>0: single_thumb = thumb_list[0] # The only place where you can get a title, it's not complete, # but searching in other places doesn't work for all videos video_title = self._html_search_regex(r'(?P<title>.*?)(?: \| Tumblr)?', webpage, 'title', flags=re.DOTALL) return [{'id': video_id, 'url': video_url, 'title': video_title, 'thumbnails': thumb_list, 'thumbnail': single_thumb, 'ext': ext }]