bambuser.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from __future__ import unicode_literals
  2. import re
  3. import itertools
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_request
  6. from ..utils import ExtractorError
  7. class BambuserIE(InfoExtractor):
  8. IE_NAME = 'bambuser'
  9. _VALID_URL = r'https?://bambuser\.com/v/(?P<id>\d+)'
  10. _API_KEY = '005f64509e19a868399060af746a00aa'
  11. _TEST = {
  12. 'url': 'http://bambuser.com/v/4050584',
  13. # MD5 seems to be flaky, see https://travis-ci.org/rg3/youtube-dl/jobs/14051016#L388
  14. # 'md5': 'fba8f7693e48fd4e8641b3fd5539a641',
  15. 'info_dict': {
  16. 'id': '4050584',
  17. 'ext': 'flv',
  18. 'title': 'Education engineering days - lightning talks',
  19. 'duration': 3741,
  20. 'uploader': 'pixelversity',
  21. 'uploader_id': '344706',
  22. },
  23. 'params': {
  24. # It doesn't respect the 'Range' header, it would download the whole video
  25. # caused the travis builds to fail: https://travis-ci.org/rg3/youtube-dl/jobs/14493845#L59
  26. 'skip_download': True,
  27. },
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. info = self._download_json(
  32. 'http://player-c.api.bambuser.com/getVideo.json?api_key=%s&vid=%s'
  33. % (self._API_KEY, video_id), video_id)
  34. error = info.get('error')
  35. if error:
  36. raise ExtractorError(
  37. '%s returned error: %s' % (self.IE_NAME, error), expected=True)
  38. result = info['result']
  39. return {
  40. 'id': video_id,
  41. 'title': result['title'],
  42. 'url': result['url'],
  43. 'thumbnail': result.get('preview'),
  44. 'duration': int(result['length']),
  45. 'view_count': int(result['views_total']),
  46. 'uploader': result['username'],
  47. 'uploader_id': result['owner']['uid'],
  48. }
  49. class BambuserChannelIE(InfoExtractor):
  50. IE_NAME = 'bambuser:channel'
  51. _VALID_URL = r'https?://bambuser\.com/channel/(?P<user>.*?)(?:/|#|\?|$)'
  52. # The maximum number we can get with each request
  53. _STEP = 50
  54. _TEST = {
  55. 'url': 'http://bambuser.com/channel/pixelversity',
  56. 'info_dict': {
  57. 'title': 'pixelversity',
  58. },
  59. 'playlist_mincount': 60,
  60. }
  61. def _real_extract(self, url):
  62. mobj = re.match(self._VALID_URL, url)
  63. user = mobj.group('user')
  64. urls = []
  65. last_id = ''
  66. for i in itertools.count(1):
  67. req_url = (
  68. 'http://bambuser.com/xhr-api/index.php?username={user}'
  69. '&sort=created&access_mode=0%2C1%2C2&limit={count}'
  70. '&method=broadcast&format=json&vid_older_than={last}'
  71. ).format(user=user, count=self._STEP, last=last_id)
  72. req = compat_urllib_request.Request(req_url)
  73. # Without setting this header, we wouldn't get any result
  74. req.add_header('Referer', 'http://bambuser.com/channel/%s' % user)
  75. data = self._download_json(
  76. req, user, 'Downloading page %d' % i)
  77. results = data['result']
  78. if not results:
  79. break
  80. last_id = results[-1]['vid']
  81. urls.extend(self.url_result(v['page'], 'Bambuser') for v in results)
  82. return {
  83. '_type': 'playlist',
  84. 'title': user,
  85. 'entries': urls,
  86. }