vube.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. compat_str,
  7. ExtractorError,
  8. )
  9. class VubeIE(InfoExtractor):
  10. IE_NAME = 'vube'
  11. IE_DESC = 'Vube.com'
  12. _VALID_URL = r'http://vube\.com/(?:[^/]+/)+(?P<id>[\da-zA-Z]{10})\b'
  13. _TESTS = [
  14. {
  15. 'url': 'http://vube.com/Chiara+Grispo+Video+Channel/YL2qNPkqon',
  16. 'md5': 'db7aba89d4603dadd627e9d1973946fe',
  17. 'info_dict': {
  18. 'id': 'YL2qNPkqon',
  19. 'ext': 'mp4',
  20. 'title': 'Chiara Grispo - Price Tag by Jessie J',
  21. 'description': 'md5:8ea652a1f36818352428cb5134933313',
  22. 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102e7e63057-5ebc-4f5c-4065-6ce4ebde131f\.jpg$',
  23. 'uploader': 'Chiara.Grispo',
  24. 'timestamp': 1388743358,
  25. 'upload_date': '20140103',
  26. 'duration': 170.56,
  27. 'like_count': int,
  28. 'dislike_count': int,
  29. 'comment_count': int,
  30. 'categories': ['pop', 'music', 'cover', 'singing', 'jessie j', 'price tag', 'chiara grispo'],
  31. }
  32. },
  33. {
  34. 'url': 'http://vube.com/SerainaMusic/my-7-year-old-sister-and-i-singing-alive-by-krewella/UeBhTudbfS?t=s&n=1',
  35. 'md5': '5d4a52492d76f72712117ce6b0d98d08',
  36. 'info_dict': {
  37. 'id': 'UeBhTudbfS',
  38. 'ext': 'mp4',
  39. 'title': 'My 7 year old Sister and I singing "Alive" by Krewella',
  40. 'description': 'md5:40bcacb97796339f1690642c21d56f4a',
  41. 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102265d5a9f-0f17-4f6b-5753-adf08484ee1e\.jpg$',
  42. 'uploader': 'Seraina',
  43. 'timestamp': 1396492438,
  44. 'upload_date': '20140403',
  45. 'duration': 240.107,
  46. 'like_count': int,
  47. 'dislike_count': int,
  48. 'comment_count': int,
  49. 'categories': ['seraina', 'jessica', 'krewella', 'alive'],
  50. }
  51. }, {
  52. 'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s',
  53. 'md5': '0584fc13b50f887127d9d1007589d27f',
  54. 'info_dict': {
  55. 'id': '0nmsMY5vEq',
  56. 'ext': 'mp4',
  57. 'title': 'Frozen - Let It Go Cover by Siren Gene',
  58. 'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.',
  59. 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$',
  60. 'uploader': 'Siren',
  61. 'timestamp': 1395448018,
  62. 'upload_date': '20140322',
  63. 'duration': 221.788,
  64. 'like_count': int,
  65. 'dislike_count': int,
  66. 'comment_count': int,
  67. 'categories': ['let it go', 'cover', 'idina menzel', 'frozen', 'singing', 'disney', 'siren gene'],
  68. }
  69. }
  70. ]
  71. def _real_extract(self, url):
  72. mobj = re.match(self._VALID_URL, url)
  73. video_id = mobj.group('id')
  74. video = self._download_json(
  75. 'http://vube.com/t-api/v1/video/%s' % video_id, video_id, 'Downloading video JSON')
  76. public_id = video['public_id']
  77. formats = []
  78. for media in video['media'].get('video', []) + video['media'].get('audio', []):
  79. if media['transcoding_status'] != 'processed':
  80. continue
  81. fmt = {
  82. 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (media['media_resolution_id'], public_id),
  83. 'abr': int(media['audio_bitrate']),
  84. 'format_id': compat_str(media['media_resolution_id']),
  85. }
  86. vbr = int(media['video_bitrate'])
  87. if vbr:
  88. fmt.update({
  89. 'vbr': vbr,
  90. 'height': int(media['height']),
  91. })
  92. formats.append(fmt)
  93. self._sort_formats(formats)
  94. if not formats and video.get('vst') == 'dmca':
  95. raise ExtractorError(
  96. 'This video has been removed in response to a complaint received under the US Digital Millennium Copyright Act.',
  97. expected=True)
  98. title = video['title']
  99. description = video.get('description')
  100. thumbnail = self._proto_relative_url(video.get('thumbnail_src'), scheme='http:')
  101. uploader = video.get('user_alias') or video.get('channel')
  102. timestamp = int_or_none(video.get('upload_time'))
  103. duration = video['duration']
  104. view_count = video.get('raw_view_count')
  105. like_count = video.get('total_likes')
  106. dislike_count = video.get('total_hates')
  107. comments = video.get('comments')
  108. comment_count = None
  109. if comments is None:
  110. comment_data = self._download_json(
  111. 'http://vube.com/api/video/%s/comment' % video_id,
  112. video_id, 'Downloading video comment JSON', fatal=False)
  113. if comment_data is not None:
  114. comment_count = int_or_none(comment_data.get('total'))
  115. else:
  116. comment_count = len(comments)
  117. categories = [tag['text'] for tag in video['tags']]
  118. return {
  119. 'id': video_id,
  120. 'formats': formats,
  121. 'title': title,
  122. 'description': description,
  123. 'thumbnail': thumbnail,
  124. 'uploader': uploader,
  125. 'timestamp': timestamp,
  126. 'duration': duration,
  127. 'view_count': view_count,
  128. 'like_count': like_count,
  129. 'dislike_count': dislike_count,
  130. 'comment_count': comment_count,
  131. 'categories': categories,
  132. }