]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/c56.py
Merge pull request #2340 from Fnordlab/master
[youtube-dl.git] / youtube_dl / extractor / c56.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import json
6
7 from .common import InfoExtractor
8
9
10 class C56IE(InfoExtractor):
11     _VALID_URL = r'https?://((www|player)\.)?56\.com/(.+?/)?(v_|(play_album.+-))(?P<textid>.+?)\.(html|swf)'
12     IE_NAME = '56.com'
13     _TEST = {
14         'url': 'http://www.56.com/u39/v_OTM0NDA3MTY.html',
15         'file': '93440716.flv',
16         'md5': 'e59995ac63d0457783ea05f93f12a866',
17         'info_dict': {
18             'title': '网事知多少 第32期:车怒',
19         },
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
24         text_id = mobj.group('textid')
25         info_page = self._download_webpage('http://vxml.56.com/json/%s/' % text_id,
26                                            text_id, 'Downloading video info')
27         info = json.loads(info_page)['info']
28         formats = [{
29             'format_id': f['type'],
30             'filesize': int(f['filesize']),
31             'url': f['url']
32         } for f in info['rfiles']]
33         self._sort_formats(formats)
34
35         return {
36             'id': info['vid'],
37             'title': info['Subject'],
38             'formats': formats,
39             'thumbnail': info.get('bimg') or info.get('img'),
40         }