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.

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