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.

86 lines
3.0 KiB

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