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.

195 lines
6.4 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': 'f42d05e7149aeaec5c037b17e5d3dc82',
  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. # nsfw, user-disabled
  95. 'url': 'https://vid.me/dzGJ',
  96. 'only_matching': True,
  97. }, {
  98. # suspended
  99. 'url': 'https://vid.me/Ox3G',
  100. 'only_matching': True,
  101. }, {
  102. # no formats in the API response
  103. 'url': 'https://vid.me/e5g',
  104. 'info_dict': {
  105. 'id': 'e5g',
  106. 'ext': 'mp4',
  107. 'title': 'Video upload (e5g)',
  108. 'thumbnail': 're:^https?://.*\.jpg',
  109. 'timestamp': 1401480195,
  110. 'upload_date': '20140530',
  111. 'uploader': None,
  112. 'uploader_id': None,
  113. 'age_limit': 0,
  114. 'duration': 483,
  115. 'view_count': int,
  116. 'like_count': int,
  117. 'comment_count': int,
  118. },
  119. 'params': {
  120. 'skip_download': True,
  121. },
  122. }]
  123. def _real_extract(self, url):
  124. video_id = self._match_id(url)
  125. try:
  126. response = self._download_json(
  127. 'https://api.vid.me/videoByUrl/%s' % video_id, video_id)
  128. except ExtractorError as e:
  129. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  130. response = self._parse_json(e.cause.read(), video_id)
  131. else:
  132. raise
  133. error = response.get('error')
  134. if error:
  135. raise ExtractorError(
  136. '%s returned error: %s' % (self.IE_NAME, error), expected=True)
  137. video = response['video']
  138. if video.get('state') in ('user-disabled', 'suspended'):
  139. raise ExtractorError(
  140. 'Vidme said: This video has been suspended either due to a copyright claim, '
  141. 'or for violating the terms of use.',
  142. expected=True)
  143. formats = [{
  144. 'format_id': f.get('type'),
  145. 'url': f['uri'],
  146. 'width': int_or_none(f.get('width')),
  147. 'height': int_or_none(f.get('height')),
  148. 'preference': 0 if f.get('type', '').endswith('clip') else 1,
  149. } for f in video.get('formats', []) if f.get('uri')]
  150. if not formats and video.get('complete_url'):
  151. formats.append({
  152. 'url': video.get('complete_url'),
  153. 'width': int_or_none(video.get('width')),
  154. 'height': int_or_none(video.get('height')),
  155. })
  156. self._sort_formats(formats)
  157. title = video['title']
  158. description = video.get('description')
  159. thumbnail = video.get('thumbnail_url')
  160. timestamp = parse_iso8601(video.get('date_created'), ' ')
  161. uploader = video.get('user', {}).get('username')
  162. uploader_id = video.get('user', {}).get('user_id')
  163. age_limit = 18 if video.get('nsfw') is True else 0
  164. duration = float_or_none(video.get('duration'))
  165. view_count = int_or_none(video.get('view_count'))
  166. like_count = int_or_none(video.get('likes_count'))
  167. comment_count = int_or_none(video.get('comment_count'))
  168. return {
  169. 'id': video_id,
  170. 'title': title or 'Video upload (%s)' % video_id,
  171. 'description': description,
  172. 'thumbnail': thumbnail,
  173. 'uploader': uploader,
  174. 'uploader_id': uploader_id,
  175. 'age_limit': age_limit,
  176. 'timestamp': timestamp,
  177. 'duration': duration,
  178. 'view_count': view_count,
  179. 'like_count': like_count,
  180. 'comment_count': comment_count,
  181. 'formats': formats,
  182. }