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.

99 lines
3.6 KiB

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