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.

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