]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/bambuser.py
Merge remote-tracking branch 'duncankl/airmozilla'
[yt-dlp.git] / youtube_dl / extractor / bambuser.py
CommitLineData
3798eadc
PH
1from __future__ import unicode_literals
2
72a5b4f7
JMF
3import re
4import json
165e3bb6 5import itertools
72a5b4f7
JMF
6
7from .common import InfoExtractor
1cc79574 8from ..compat import (
165e3bb6
JMF
9 compat_urllib_request,
10)
72a5b4f7
JMF
11
12
13class BambuserIE(InfoExtractor):
3798eadc 14 IE_NAME = 'bambuser'
72a5b4f7
JMF
15 _VALID_URL = r'https?://bambuser\.com/v/(?P<id>\d+)'
16 _API_KEY = '005f64509e19a868399060af746a00aa'
17
18 _TEST = {
3798eadc 19 'url': 'http://bambuser.com/v/4050584',
ce152341 20 # MD5 seems to be flaky, see https://travis-ci.org/rg3/youtube-dl/jobs/14051016#L388
dcddc10a 21 # 'md5': 'fba8f7693e48fd4e8641b3fd5539a641',
3798eadc
PH
22 'info_dict': {
23 'id': '4050584',
24 'ext': 'flv',
25 'title': 'Education engineering days - lightning talks',
26 'duration': 3741,
27 'uploader': 'pixelversity',
28 'uploader_id': '344706',
72a5b4f7 29 },
3798eadc 30 'params': {
1a62c18f
JMF
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
3798eadc 33 'skip_download': True,
1a62c18f 34 },
72a5b4f7
JMF
35 }
36
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?'
9e1a5b84 41 '&api_key=%s&vid=%s' % (self._API_KEY, video_id))
72a5b4f7
JMF
42 info_json = self._download_webpage(info_url, video_id)
43 info = json.loads(info_json)['result']
44
45 return {
46 'id': video_id,
47 'title': info['title'],
48 'url': info['url'],
165e3bb6 49 'thumbnail': info.get('preview'),
72a5b4f7
JMF
50 'duration': int(info['length']),
51 'view_count': int(info['views_total']),
52 'uploader': info['username'],
ae6423d7 53 'uploader_id': info['owner']['uid'],
72a5b4f7
JMF
54 }
55
165e3bb6
JMF
56
57class BambuserChannelIE(InfoExtractor):
3798eadc 58 IE_NAME = 'bambuser:channel'
c0ade33e 59 _VALID_URL = r'https?://bambuser\.com/channel/(?P<user>.*?)(?:/|#|\?|$)'
165e3bb6
JMF
60 # The maximum number we can get with each request
61 _STEP = 50
22a6f150
PH
62 _TEST = {
63 'url': 'http://bambuser.com/channel/pixelversity',
64 'info_dict': {
65 'title': 'pixelversity',
66 },
67 'playlist_mincount': 60,
68 }
165e3bb6
JMF
69
70 def _real_extract(self, url):
71 mobj = re.match(self._VALID_URL, url)
72 user = mobj.group('user')
73 urls = []
74 last_id = ''
75 for i in itertools.count(1):
b74e86f4
PH
76 req_url = (
77 'http://bambuser.com/xhr-api/index.php?username={user}'
78 '&sort=created&access_mode=0%2C1%2C2&limit={count}'
79 '&method=broadcast&format=json&vid_older_than={last}'
80 ).format(user=user, count=self._STEP, last=last_id)
165e3bb6
JMF
81 req = compat_urllib_request.Request(req_url)
82 # Without setting this header, we wouldn't get any result
83 req.add_header('Referer', 'http://bambuser.com/channel/%s' % user)
22a6f150
PH
84 data = self._download_json(
85 req, user, 'Downloading page %d' % i)
86 results = data['result']
87 if not results:
165e3bb6
JMF
88 break
89 last_id = results[-1]['vid']
90 urls.extend(self.url_result(v['page'], 'Bambuser') for v in results)
91
92 return {
93 '_type': 'playlist',
94 'title': user,
95 'entries': urls,
96 }