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.

87 lines
3.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class TumblrIE(InfoExtractor):
  6. _VALID_URL = r'http://(?P<blog_name>.*?)\.tumblr\.com/(?:post|video)/(?P<id>[0-9]+)(?:$|[/?#])'
  7. _TESTS = [{
  8. 'url': 'http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes',
  9. 'md5': '479bb068e5b16462f5176a6828829767',
  10. 'info_dict': {
  11. 'id': '54196191430',
  12. 'ext': 'mp4',
  13. 'title': 'tatiana maslany news, Orphan Black || DVD extra - behind the scenes ↳...',
  14. 'description': 'md5:37db8211e40b50c7c44e95da14f630b7',
  15. 'thumbnail': 're:http://.*\.jpg',
  16. }
  17. }, {
  18. 'url': 'http://5sostrum.tumblr.com/post/90208453769/yall-forgetting-the-greatest-keek-of-them-all',
  19. 'md5': 'bf348ef8c0ef84fbf1cbd6fa6e000359',
  20. 'info_dict': {
  21. 'id': '90208453769',
  22. 'ext': 'mp4',
  23. 'title': '5SOS STRUM ;]',
  24. 'description': 'md5:dba62ac8639482759c8eb10ce474586a',
  25. 'thumbnail': 're:http://.*\.jpg',
  26. }
  27. }, {
  28. 'url': 'http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching',
  29. 'md5': 'de07e5211d60d4f3a2c3df757ea9f6ab',
  30. 'info_dict': {
  31. 'id': 'Wmur',
  32. 'ext': 'mp4',
  33. 'title': 'naked smoking & stretching',
  34. 'upload_date': '20150506',
  35. 'timestamp': 1430931613,
  36. },
  37. 'add_ie': ['Vidme'],
  38. }, {
  39. 'url': 'http://camdamage.tumblr.com/post/98846056295/',
  40. 'md5': 'a9e0c8371ea1ca306d6554e3fecf50b6',
  41. 'info_dict': {
  42. 'id': '105463834',
  43. 'ext': 'mp4',
  44. 'title': 'Cam Damage-HD 720p',
  45. 'uploader': 'John Moyer',
  46. 'uploader_id': 'user32021558',
  47. },
  48. 'add_ie': ['Vimeo'],
  49. }]
  50. def _real_extract(self, url):
  51. m_url = re.match(self._VALID_URL, url)
  52. video_id = m_url.group('id')
  53. blog = m_url.group('blog_name')
  54. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  55. webpage, urlh = self._download_webpage_handle(url, video_id)
  56. iframe_url = self._search_regex(
  57. r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
  58. webpage, 'iframe url', default=None)
  59. if iframe_url is None:
  60. return self.url_result(urlh.geturl(), 'Generic')
  61. iframe = self._download_webpage(iframe_url, video_id,
  62. 'Downloading iframe page')
  63. video_url = self._search_regex(r'<source src="([^"]+)"',
  64. iframe, 'video url')
  65. # The only place where you can get a title, it's not complete,
  66. # but searching in other places doesn't work for all videos
  67. video_title = self._html_search_regex(
  68. r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
  69. webpage, 'title')
  70. return {
  71. 'id': video_id,
  72. 'url': video_url,
  73. 'ext': 'mp4',
  74. 'title': video_title,
  75. 'description': self._og_search_description(webpage, default=None),
  76. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  77. }