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.

141 lines
5.3 KiB

  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. webpage = self._download_webpage(url, video_id)
  68. data_json = self._search_regex(
  69. r'(?s)window\["(?:tapiVideoData|vubeOriginalVideoData)"\]\s*=\s*(\{.*?\n});\n',
  70. webpage, 'video data'
  71. )
  72. data = json.loads(data_json)
  73. video = (
  74. data.get('video') or
  75. data)
  76. assert isinstance(video, dict)
  77. public_id = video['public_id']
  78. formats = [
  79. {
  80. 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id),
  81. 'height': int(fmt['height']),
  82. 'abr': int(fmt['audio_bitrate']),
  83. 'vbr': int(fmt['video_bitrate']),
  84. 'format_id': fmt['media_resolution_id']
  85. } for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed'
  86. ]
  87. self._sort_formats(formats)
  88. title = video['title']
  89. description = video.get('description')
  90. thumbnail = self._proto_relative_url(
  91. video.get('thumbnail') or video.get('thumbnail_src'),
  92. scheme='http:')
  93. uploader = data.get('user', {}).get('channel', {}).get('name') or video.get('user_alias')
  94. uploader_id = data.get('user', {}).get('name')
  95. timestamp = int_or_none(video.get('upload_time'))
  96. duration = video['duration']
  97. view_count = video.get('raw_view_count')
  98. like_count = video.get('rlikes')
  99. if like_count is None:
  100. like_count = video.get('total_likes')
  101. dislike_count = video.get('rhates')
  102. if dislike_count is None:
  103. dislike_count = video.get('total_hates')
  104. comments = video.get('comments')
  105. comment_count = None
  106. if comments is None:
  107. comment_data = self._download_json(
  108. 'http://vube.com/api/video/%s/comment' % video_id,
  109. video_id, 'Downloading video comment JSON', fatal=False)
  110. if comment_data is not None:
  111. comment_count = int_or_none(comment_data.get('total'))
  112. else:
  113. comment_count = len(comments)
  114. return {
  115. 'id': video_id,
  116. 'formats': formats,
  117. 'title': title,
  118. 'description': description,
  119. 'thumbnail': thumbnail,
  120. 'uploader': uploader,
  121. 'uploader_id': uploader_id,
  122. 'timestamp': timestamp,
  123. 'duration': duration,
  124. 'view_count': view_count,
  125. 'like_count': like_count,
  126. 'dislike_count': dislike_count,
  127. 'comment_count': comment_count,
  128. }