vidme.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor, ExtractorError
  3. from ..utils import (
  4. int_or_none,
  5. float_or_none,
  6. parse_iso8601,
  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': 'c62f1156138dc3323902188c5b5a8bd6',
  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. 'comment_count': int,
  25. },
  26. }, {
  27. 'url': 'https://vid.me/Gc6M',
  28. 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
  29. 'info_dict': {
  30. 'id': 'Gc6M',
  31. 'ext': 'mp4',
  32. 'title': 'O Mere Dil ke chain - Arnav and Khushi VM',
  33. 'duration': 223.72,
  34. 'timestamp': 1441211642,
  35. 'upload_date': '20150902',
  36. 'thumbnail': 're:^https?://.*\.jpg',
  37. 'view_count': int,
  38. 'like_count': int,
  39. 'comment_count': int,
  40. 'comment_count': int,
  41. },
  42. 'params': {
  43. 'skip_download': True,
  44. },
  45. }, {
  46. # tests uploader field
  47. 'url': 'https://vid.me/4Iib',
  48. 'info_dict': {
  49. 'id': '4Iib',
  50. 'ext': 'mp4',
  51. 'title': 'The Carver',
  52. 'description': 'md5:e9c24870018ae8113be936645b93ba3c',
  53. 'duration': 97.859999999999999,
  54. 'timestamp': 1433203629,
  55. 'upload_date': '20150602',
  56. 'uploader': 'Thomas',
  57. 'thumbnail': 're:^https?://.*\.jpg',
  58. 'view_count': int,
  59. 'like_count': int,
  60. 'comment_count': int,
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. }, {
  66. # From http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
  67. 'url': 'https://vid.me/e/Wmur',
  68. 'only_matching': True,
  69. }]
  70. def _real_extract(self, url):
  71. video_id = self._match_id(url)
  72. api_url = 'https://api.vid.me/videoByUrl/' + video_id
  73. data = self._download_json(api_url, video_id)
  74. video_data = data.get('video')
  75. if video_data is None:
  76. raise ExtractorError('Could not extract the vid.me video data')
  77. title = video_data.get('title')
  78. description = video_data.get('description')
  79. thumbnail = video_data.get('thumbnail_url')
  80. timestamp = parse_iso8601(video_data.get('date_created'), ' ')
  81. duration = float_or_none(video_data.get('duration'))
  82. view_count = int_or_none(video_data.get('view_count'))
  83. like_count = int_or_none(video_data.get('likes_count'))
  84. comment_count = int_or_none(video_data.get('comment_count'))
  85. uploader = None
  86. user_data = video_data.get('user')
  87. if user_data is not None:
  88. uploader = user_data.get('username')
  89. formats = [{
  90. 'format_id': format['type'],
  91. 'url': format['uri'],
  92. 'width': int_or_none(format['width']),
  93. 'height': int_or_none(format['height']),
  94. } for format in video_data.get('formats', [])]
  95. self._sort_formats(formats)
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'description': description,
  100. 'thumbnail': thumbnail,
  101. 'timestamp': timestamp,
  102. 'duration': duration,
  103. 'view_count': view_count,
  104. 'like_count': like_count,
  105. 'comment_count': comment_count,
  106. 'uploader': uploader,
  107. 'formats': formats,
  108. }