You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.8 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. )
  6. class TumblrIE(InfoExtractor):
  7. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/((post)|(video))/(?P<id>\d*)/(.*?)'
  8. _TEST = {
  9. u'url': u'http://resigno.tumblr.com/post/53364321212/e-de-extrema-importancia-que-esse-video-seja',
  10. u'file': u'53364321212.mp4',
  11. u'md5': u'0716d3dd51baf68a28b40fdf1251494e',
  12. u'info_dict': {
  13. u"title": u"Rafael Lemos | Tumblr"
  14. }
  15. }
  16. def _real_extract(self, url):
  17. m_url = re.match(self._VALID_URL, url)
  18. video_id = m_url.group('id')
  19. blog = m_url.group('blog_name')
  20. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  21. webpage = self._download_webpage(url, video_id)
  22. re_video = r'src=\\x22(?P<video_url>http://%s\.tumblr\.com/video_file/%s/(.*?))\\x22 type=\\x22video/(?P<ext>.*?)\\x22' % (blog, video_id)
  23. video = re.search(re_video, webpage)
  24. if video is None:
  25. raise ExtractorError(u'Unable to extract video')
  26. video_url = video.group('video_url')
  27. ext = video.group('ext')
  28. video_thumbnail = self._search_regex(r'posters(.*?)\[\\x22(?P<thumb>.*?)\\x22',
  29. webpage, u'thumbnail', fatal=False) # We pick the first poster
  30. if video_thumbnail: video_thumbnail = video_thumbnail.replace('\\', '')
  31. # The only place where you can get a title, it's not complete,
  32. # but searching in other places doesn't work for all videos
  33. video_title = self._html_search_regex(r'<title>(?P<title>.*?)</title>',
  34. webpage, u'title', flags=re.DOTALL)
  35. return [{'id': video_id,
  36. 'url': video_url,
  37. 'title': video_title,
  38. 'thumbnail': video_thumbnail,
  39. 'ext': ext
  40. }]