]>
Commit | Line | Data |
---|---|---|
4435c6e9 YCH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4435c6e9 YCH |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..compat import compat_parse_qs | |
7 | from ..utils import ExtractorError | |
8 | ||
9 | ||
10 | class BokeCCBaseIE(InfoExtractor): | |
11 | def _extract_bokecc_formats(self, webpage, video_id, format_id=None): | |
12 | player_params_str = self._html_search_regex( | |
2af01c02 RA |
13 | r'<(?:script|embed)[^>]+src=(?P<q>["\'])(?:https?:)?//p\.bokecc\.com/(?:player|flash/player\.swf)\?(?P<query>.+?)(?P=q)', |
14 | webpage, 'player params', group='query') | |
4435c6e9 YCH |
15 | |
16 | player_params = compat_parse_qs(player_params_str) | |
17 | ||
18 | info_xml = self._download_xml( | |
19 | 'http://p.bokecc.com/servlet/playinfo?uid=%s&vid=%s&m=1' % ( | |
20 | player_params['siteid'][0], player_params['vid'][0]), video_id) | |
21 | ||
22 | formats = [{ | |
23 | 'format_id': format_id, | |
24 | 'url': quality.find('./copy').attrib['playurl'], | |
f983b875 | 25 | 'quality': int(quality.attrib['value']), |
4435c6e9 YCH |
26 | } for quality in info_xml.findall('./video/quality')] |
27 | ||
28 | self._sort_formats(formats) | |
29 | ||
30 | return formats | |
31 | ||
32 | ||
33 | class BokeCCIE(BokeCCBaseIE): | |
34 | _IE_DESC = 'CC视频' | |
5886b38d | 35 | _VALID_URL = r'https?://union\.bokecc\.com/playvideo\.bo\?(?P<query>.*)' |
4435c6e9 YCH |
36 | |
37 | _TESTS = [{ | |
2af01c02 | 38 | 'url': 'http://union.bokecc.com/playvideo.bo?vid=E0ABAE9D4F509B189C33DC5901307461&uid=FE644790DE9D154A', |
4435c6e9 | 39 | 'info_dict': { |
2af01c02 | 40 | 'id': 'FE644790DE9D154A_E0ABAE9D4F509B189C33DC5901307461', |
4435c6e9 YCH |
41 | 'ext': 'flv', |
42 | 'title': 'BokeCC Video', | |
43 | }, | |
44 | }] | |
45 | ||
46 | def _real_extract(self, url): | |
5ad28e7f | 47 | qs = compat_parse_qs(self._match_valid_url(url).group('query')) |
4435c6e9 YCH |
48 | if not qs.get('vid') or not qs.get('uid'): |
49 | raise ExtractorError('Invalid URL', expected=True) | |
50 | ||
51 | video_id = '%s_%s' % (qs['uid'][0], qs['vid'][0]) | |
52 | ||
53 | webpage = self._download_webpage(url, video_id) | |
54 | ||
55 | return { | |
56 | 'id': video_id, | |
57 | 'title': 'BokeCC Video', # no title provided in the webpage | |
58 | 'formats': self._extract_bokecc_formats(webpage, video_id), | |
59 | } |