vube.py 5.2 KB

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