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.

61 lines
2.3 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. def _real_extract(self, url):
  29. m_url = re.match(self._VALID_URL, url)
  30. video_id = m_url.group('id')
  31. blog = m_url.group('blog_name')
  32. url = 'http://%s.tumblr.com/post/%s/' % (blog, video_id)
  33. webpage = self._download_webpage(url, video_id)
  34. iframe_url = self._search_regex(
  35. r'src=\'(https?://www\.tumblr\.com/video/[^\']+)\'',
  36. webpage, 'iframe url')
  37. iframe = self._download_webpage(iframe_url, video_id)
  38. video_url = self._search_regex(r'<source src="([^"]+)"',
  39. iframe, 'video url')
  40. # The only place where you can get a title, it's not complete,
  41. # but searching in other places doesn't work for all videos
  42. video_title = self._html_search_regex(
  43. r'(?s)<title>(?P<title>.*?)(?: \| Tumblr)?</title>',
  44. webpage, 'title')
  45. return {
  46. 'id': video_id,
  47. 'url': video_url,
  48. 'ext': 'mp4',
  49. 'title': video_title,
  50. 'description': self._og_search_description(webpage),
  51. 'thumbnail': self._og_search_thumbnail(webpage),
  52. }