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.

95 lines
3.3 KiB

10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. float_or_none,
  6. str_to_int,
  7. )
  8. class VidmeIE(InfoExtractor):
  9. _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)'
  10. _TESTS = [{
  11. 'url': 'https://vid.me/QNB',
  12. 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
  13. 'info_dict': {
  14. 'id': 'QNB',
  15. 'ext': 'mp4',
  16. 'title': 'Fishing for piranha - the easy way',
  17. 'description': 'source: https://www.facebook.com/photo.php?v=312276045600871',
  18. 'duration': 119.92,
  19. 'timestamp': 1406313244,
  20. 'upload_date': '20140725',
  21. 'thumbnail': 're:^https?://.*\.jpg',
  22. 'view_count': int,
  23. 'like_count': int,
  24. },
  25. }, {
  26. # tests uploader field
  27. 'url': 'https://vid.me/4Iib',
  28. 'info_dict': {
  29. 'id': '4Iib',
  30. 'ext': 'mp4',
  31. 'title': 'The Carver',
  32. 'description': 'md5:e9c24870018ae8113be936645b93ba3c',
  33. 'duration': 97.859999999999999,
  34. 'timestamp': 1433203629,
  35. 'upload_date': '20150602',
  36. 'uploader': 'Thomas',
  37. 'thumbnail': 're:^https?://.*\.jpg',
  38. 'view_count': int,
  39. 'like_count': int,
  40. },
  41. 'params': {
  42. 'skip_download': True,
  43. },
  44. }, {
  45. # From http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
  46. 'url': 'https://vid.me/e/Wmur',
  47. 'only_matching': True,
  48. }]
  49. def _real_extract(self, url):
  50. url = url.replace('vid.me/e/', 'vid.me/')
  51. video_id = self._match_id(url)
  52. webpage = self._download_webpage(url, video_id)
  53. video_url = self._html_search_regex(
  54. r'<source src="([^"]+)"', webpage, 'video URL')
  55. title = self._og_search_title(webpage)
  56. description = self._og_search_description(webpage, default='')
  57. thumbnail = self._og_search_thumbnail(webpage)
  58. timestamp = int_or_none(self._og_search_property(
  59. 'updated_time', webpage, fatal=False))
  60. width = int_or_none(self._og_search_property(
  61. 'video:width', webpage, fatal=False))
  62. height = int_or_none(self._og_search_property(
  63. 'video:height', webpage, fatal=False))
  64. duration = float_or_none(self._html_search_regex(
  65. r'data-duration="([^"]+)"', webpage, 'duration', fatal=False))
  66. view_count = str_to_int(self._html_search_regex(
  67. r'<(?:li|span) class="video_views">\s*([\d,\.]+)\s*plays?',
  68. webpage, 'view count', fatal=False))
  69. like_count = str_to_int(self._html_search_regex(
  70. r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">',
  71. webpage, 'like count', fatal=False))
  72. uploader = self._html_search_regex(
  73. 'class="video_author_username"[^>]*>([^<]+)',
  74. webpage, 'uploader', default=None)
  75. return {
  76. 'id': video_id,
  77. 'url': video_url,
  78. 'title': title,
  79. 'description': description,
  80. 'thumbnail': thumbnail,
  81. 'timestamp': timestamp,
  82. 'width': width,
  83. 'height': height,
  84. 'duration': duration,
  85. 'view_count': view_count,
  86. 'like_count': like_count,
  87. 'uploader': uploader,
  88. }