vube.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. }
  25. },
  26. {
  27. 'url': 'http://vube.com/SerainaMusic/my-7-year-old-sister-and-i-singing-alive-by-krewella/UeBhTudbfS?t=s&n=1',
  28. 'md5': '5d4a52492d76f72712117ce6b0d98d08',
  29. 'info_dict': {
  30. 'id': 'UeBhTudbfS',
  31. 'ext': 'mp4',
  32. 'title': 'My 7 year old Sister and I singing "Alive" by Krewella',
  33. 'description': 'md5:40bcacb97796339f1690642c21d56f4a',
  34. 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102265d5a9f-0f17-4f6b-5753-adf08484ee1e\.jpg$',
  35. 'uploader': 'Seraina',
  36. 'timestamp': 1396492438,
  37. 'upload_date': '20140403',
  38. 'duration': 240.107
  39. }
  40. }, {
  41. 'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s',
  42. 'md5': '0584fc13b50f887127d9d1007589d27f',
  43. 'info_dict': {
  44. 'id': '0nmsMY5vEq',
  45. 'ext': 'mp4',
  46. 'title': 'Frozen - Let It Go Cover by Siren Gene',
  47. 'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.',
  48. 'uploader': 'Siren Gene',
  49. 'uploader_id': 'Siren',
  50. 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$',
  51. 'duration': 221.788,
  52. 'like_count': int,
  53. 'dislike_count': int,
  54. }
  55. }
  56. ]
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. video_id = mobj.group('id')
  60. webpage = self._download_webpage(url, video_id)
  61. data_json = self._search_regex(
  62. r'(?s)window\["(?:tapiVideoData|vubeOriginalVideoData)"\]\s*=\s*(\{.*?\n});\n',
  63. webpage, 'video data'
  64. )
  65. data = json.loads(data_json)
  66. open('/dev/shm/f', 'w').write(json.dumps(data, indent=2))
  67. video = (
  68. data.get('video') or
  69. data)
  70. assert isinstance(video, dict)
  71. public_id = video['public_id']
  72. formats = [
  73. {
  74. 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id),
  75. 'height': int(fmt['height']),
  76. 'abr': int(fmt['audio_bitrate']),
  77. 'vbr': int(fmt['video_bitrate']),
  78. 'format_id': fmt['media_resolution_id']
  79. } for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed'
  80. ]
  81. self._sort_formats(formats)
  82. title = video['title']
  83. description = video.get('description')
  84. thumbnail = self._proto_relative_url(
  85. video.get('thumbnail') or video.get('thumbnail_src'),
  86. scheme='http:')
  87. uploader = data.get('user', {}).get('channel', {}).get('name') or video.get('user_alias')
  88. uploader_id = data.get('user', {}).get('name')
  89. timestamp = int_or_none(video.get('upload_time'))
  90. duration = video['duration']
  91. view_count = video.get('raw_view_count')
  92. like_count = video.get('rlikes')
  93. dislike_count = video.get('rhates')
  94. comment = self._download_json(
  95. 'http://vube.com/api/video/%s/comment' % video_id, video_id, 'Downloading video comment JSON')
  96. comment_count = int_or_none(comment.get('total'))
  97. return {
  98. 'id': video_id,
  99. 'formats': formats,
  100. 'title': title,
  101. 'description': description,
  102. 'thumbnail': thumbnail,
  103. 'uploader': uploader,
  104. 'uploader_id': uploader_id,
  105. 'timestamp': timestamp,
  106. 'duration': duration,
  107. 'view_count': view_count,
  108. 'like_count': like_count,
  109. 'dislike_count': dislike_count,
  110. 'comment_count': comment_count,
  111. }