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.

53 lines
1.9 KiB

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