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