]>
Commit | Line | Data |
---|---|---|
e1f6e61e | 1 | # coding: utf-8 |
84c92dc0 | 2 | from __future__ import unicode_literals |
e1f6e61e JMF |
3 | |
4 | import re | |
e1f6e61e JMF |
5 | |
6 | from .common import InfoExtractor | |
1b77ee62 | 7 | from ..utils import js_to_json |
84c92dc0 | 8 | |
e1f6e61e JMF |
9 | |
10 | class C56IE(InfoExtractor): | |
4a419b88 | 11 | _VALID_URL = r'https?://(?:(?:www|player)\.)?56\.com/(?:.+?/)?(?:v_|(?:play_album.+-))(?P<textid>.+?)\.(?:html|swf)' |
84c92dc0 | 12 | IE_NAME = '56.com' |
1b77ee62 | 13 | _TESTS = [{ |
84c92dc0 | 14 | 'url': 'http://www.56.com/u39/v_OTM0NDA3MTY.html', |
84c92dc0 PH |
15 | 'md5': 'e59995ac63d0457783ea05f93f12a866', |
16 | 'info_dict': { | |
4a419b88 S |
17 | 'id': '93440716', |
18 | 'ext': 'flv', | |
84c92dc0 | 19 | 'title': '网事知多少 第32期:车怒', |
4a419b88 | 20 | 'duration': 283.813, |
e1f6e61e | 21 | }, |
1b77ee62 YCH |
22 | }, { |
23 | 'url': 'http://www.56.com/u47/v_MTM5NjQ5ODc2.html', | |
24 | 'md5': '', | |
25 | 'info_dict': { | |
26 | 'id': '82247482', | |
27 | 'title': '爱的诅咒之杜鹃花开', | |
28 | }, | |
29 | 'playlist_count': 7, | |
30 | 'add_ie': ['Sohu'], | |
31 | }] | |
e1f6e61e JMF |
32 | |
33 | def _real_extract(self, url): | |
34 | mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE) | |
35 | text_id = mobj.group('textid') | |
4a419b88 | 36 | |
1b77ee62 YCH |
37 | webpage = self._download_webpage(url, text_id) |
38 | sohu_video_info_str = self._search_regex( | |
39 | r'var\s+sohuVideoInfo\s*=\s*({[^}]+});', webpage, 'Sohu video info', default=None) | |
40 | if sohu_video_info_str: | |
41 | sohu_video_info = self._parse_json( | |
42 | sohu_video_info_str, text_id, transform_source=js_to_json) | |
43 | return self.url_result(sohu_video_info['url'], 'Sohu') | |
44 | ||
4a419b88 S |
45 | page = self._download_json( |
46 | 'http://vxml.56.com/json/%s/' % text_id, text_id, 'Downloading video info') | |
47 | ||
48 | info = page['info'] | |
49 | ||
50 | formats = [ | |
51 | { | |
52 | 'format_id': f['type'], | |
53 | 'filesize': int(f['filesize']), | |
54 | 'url': f['url'] | |
55 | } for f in info['rfiles'] | |
56 | ] | |
84c92dc0 | 57 | self._sort_formats(formats) |
e1f6e61e | 58 | |
84c92dc0 PH |
59 | return { |
60 | 'id': info['vid'], | |
61 | 'title': info['Subject'], | |
4a419b88 | 62 | 'duration': int(info['duration']) / 1000.0, |
84c92dc0 PH |
63 | 'formats': formats, |
64 | 'thumbnail': info.get('bimg') or info.get('img'), | |
65 | } |