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.

78 lines
2.9 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. def _real_extract(self, url):
  40. m_url = re.match(self._VALID_URL, url)
  41. video_id = m_url.group('id')
  42. blog = m_url.group('blog_name')
  43. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  44. webpage = self._download_webpage(url, video_id)
  45. vid_me_embed_url = self._search_regex(
  46. r'src=[\'"](https?://vid\.me/[^\'"]+)[\'"]',
  47. webpage, 'vid.me embed', default=None)
  48. if vid_me_embed_url is not None:
  49. return self.url_result(vid_me_embed_url, 'Vidme')
  50. iframe_url = self._search_regex(
  51. r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
  52. webpage, 'iframe url')
  53. iframe = self._download_webpage(iframe_url, video_id)
  54. video_url = self._search_regex(r'<source src="([^"]+)"',
  55. iframe, 'video url')
  56. # The only place where you can get a title, it's not complete,
  57. # but searching in other places doesn't work for all videos
  58. video_title = self._html_search_regex(
  59. r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
  60. webpage, 'title')
  61. return {
  62. 'id': video_id,
  63. 'url': video_url,
  64. 'ext': 'mp4',
  65. 'title': video_title,
  66. 'description': self._og_search_description(webpage, default=None),
  67. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  68. }