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.

68 lines
2.6 KiB

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