bambuser.py 3.1 KB

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