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.

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