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.

152 lines
5.0 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_HTTPError
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. float_or_none,
  8. parse_iso8601,
  9. )
  10. class VidmeIE(InfoExtractor):
  11. _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)'
  12. _TESTS = [{
  13. 'url': 'https://vid.me/QNB',
  14. 'md5': 'c62f1156138dc3323902188c5b5a8bd6',
  15. 'info_dict': {
  16. 'id': 'QNB',
  17. 'ext': 'mp4',
  18. 'title': 'Fishing for piranha - the easy way',
  19. 'description': 'source: https://www.facebook.com/photo.php?v=312276045600871',
  20. 'thumbnail': 're:^https?://.*\.jpg',
  21. 'timestamp': 1406313244,
  22. 'upload_date': '20140725',
  23. 'age_limit': 0,
  24. 'duration': 119.92,
  25. 'view_count': int,
  26. 'like_count': int,
  27. 'comment_count': int,
  28. },
  29. }, {
  30. 'url': 'https://vid.me/Gc6M',
  31. 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
  32. 'info_dict': {
  33. 'id': 'Gc6M',
  34. 'ext': 'mp4',
  35. 'title': 'O Mere Dil ke chain - Arnav and Khushi VM',
  36. 'thumbnail': 're:^https?://.*\.jpg',
  37. 'timestamp': 1441211642,
  38. 'upload_date': '20150902',
  39. 'uploader': 'SunshineM',
  40. 'uploader_id': '3552827',
  41. 'age_limit': 0,
  42. 'duration': 223.72,
  43. 'view_count': int,
  44. 'like_count': int,
  45. 'comment_count': int,
  46. },
  47. 'params': {
  48. 'skip_download': True,
  49. },
  50. }, {
  51. # tests uploader field
  52. 'url': 'https://vid.me/4Iib',
  53. 'info_dict': {
  54. 'id': '4Iib',
  55. 'ext': 'mp4',
  56. 'title': 'The Carver',
  57. 'description': 'md5:e9c24870018ae8113be936645b93ba3c',
  58. 'thumbnail': 're:^https?://.*\.jpg',
  59. 'timestamp': 1433203629,
  60. 'upload_date': '20150602',
  61. 'uploader': 'Thomas',
  62. 'uploader_id': '109747',
  63. 'age_limit': 0,
  64. 'duration': 97.859999999999999,
  65. 'view_count': int,
  66. 'like_count': int,
  67. 'comment_count': int,
  68. },
  69. 'params': {
  70. 'skip_download': True,
  71. },
  72. }, {
  73. # nsfw test from http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
  74. 'url': 'https://vid.me/e/Wmur',
  75. 'info_dict': {
  76. 'id': 'Wmur',
  77. 'ext': 'mp4',
  78. 'title': 'naked smoking & stretching',
  79. 'thumbnail': 're:^https?://.*\.jpg',
  80. 'timestamp': 1430931613,
  81. 'upload_date': '20150506',
  82. 'uploader': 'naked-yogi',
  83. 'uploader_id': '1638622',
  84. 'age_limit': 18,
  85. 'duration': 653.26999999999998,
  86. 'view_count': int,
  87. 'like_count': int,
  88. 'comment_count': int,
  89. },
  90. 'params': {
  91. 'skip_download': True,
  92. },
  93. }]
  94. def _real_extract(self, url):
  95. video_id = self._match_id(url)
  96. try:
  97. response = self._download_json(
  98. 'https://api.vid.me/videoByUrl/%s' % video_id, video_id)
  99. except ExtractorError as e:
  100. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  101. response = self._parse_json(e.cause.read(), video_id)
  102. else:
  103. raise
  104. error = response.get('error')
  105. if error:
  106. raise ExtractorError(
  107. '%s returned error: %s' % (self.IE_NAME, error), expected=True)
  108. video = response['video']
  109. formats = [{
  110. 'format_id': f.get('type'),
  111. 'url': f['uri'],
  112. 'width': int_or_none(f.get('width')),
  113. 'height': int_or_none(f.get('height')),
  114. 'preference': 0 if f.get('type', '').endswith('clip') else 1,
  115. } for f in video.get('formats', []) if f.get('uri')]
  116. self._sort_formats(formats)
  117. title = video['title']
  118. description = video.get('description')
  119. thumbnail = video.get('thumbnail_url')
  120. timestamp = parse_iso8601(video.get('date_created'), ' ')
  121. uploader = video.get('user', {}).get('username')
  122. uploader_id = video.get('user', {}).get('user_id')
  123. age_limit = 18 if video.get('nsfw') is True else 0
  124. duration = float_or_none(video.get('duration'))
  125. view_count = int_or_none(video.get('view_count'))
  126. like_count = int_or_none(video.get('likes_count'))
  127. comment_count = int_or_none(video.get('comment_count'))
  128. return {
  129. 'id': video_id,
  130. 'title': title,
  131. 'description': description,
  132. 'thumbnail': thumbnail,
  133. 'uploader': uploader,
  134. 'uploader_id': uploader_id,
  135. 'age_limit': age_limit,
  136. 'timestamp': timestamp,
  137. 'duration': duration,
  138. 'view_count': view_count,
  139. 'like_count': like_count,
  140. 'comment_count': comment_count,
  141. 'formats': formats,
  142. }