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.

81 lines
2.8 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. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. info_url = ('http://player-c.api.bambuser.com/getVideo.json?'
  29. '&api_key=%s&vid=%s' % (self._API_KEY, video_id))
  30. info_json = self._download_webpage(info_url, video_id)
  31. info = json.loads(info_json)['result']
  32. return {
  33. 'id': video_id,
  34. 'title': info['title'],
  35. 'url': info['url'],
  36. 'thumbnail': info.get('preview'),
  37. 'duration': int(info['length']),
  38. 'view_count': int(info['views_total']),
  39. 'uploader': info['username'],
  40. 'uploader_id': info['uid'],
  41. }
  42. class BambuserChannelIE(InfoExtractor):
  43. IE_NAME = u'bambuser:channel'
  44. _VALID_URL = r'http://bambuser.com/channel/(?P<user>.*?)(?:/|#|\?|$)'
  45. # The maximum number we can get with each request
  46. _STEP = 50
  47. def _real_extract(self, url):
  48. mobj = re.match(self._VALID_URL, url)
  49. user = mobj.group('user')
  50. urls = []
  51. last_id = ''
  52. for i in itertools.count(1):
  53. req_url = ('http://bambuser.com/xhr-api/index.php?username={user}'
  54. '&sort=created&access_mode=0%2C1%2C2&limit={count}'
  55. '&method=broadcast&format=json&vid_older_than={last}'
  56. ).format(user=user, count=self._STEP, last=last_id)
  57. req = compat_urllib_request.Request(req_url)
  58. # Without setting this header, we wouldn't get any result
  59. req.add_header('Referer', 'http://bambuser.com/channel/%s' % user)
  60. info_json = self._download_webpage(req, user,
  61. u'Downloading page %d' % i)
  62. results = json.loads(info_json)['result']
  63. if len(results) == 0:
  64. break
  65. last_id = results[-1]['vid']
  66. urls.extend(self.url_result(v['page'], 'Bambuser') for v in results)
  67. return {
  68. '_type': 'playlist',
  69. 'title': user,
  70. 'entries': urls,
  71. }