]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/c56.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / c56.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import js_to_json
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 _TESTS = [{
14 'url': 'http://www.56.com/u39/v_OTM0NDA3MTY.html',
15 'md5': 'e59995ac63d0457783ea05f93f12a866',
16 'info_dict': {
17 'id': '93440716',
18 'ext': 'flv',
19 'title': '网事知多少 第32期:车怒',
20 'duration': 283.813,
21 },
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 }]
32
33 def _real_extract(self, url):
34 mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
35 text_id = mobj.group('textid')
36
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
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 ]
57 self._sort_formats(formats)
58
59 return {
60 'id': info['vid'],
61 'title': info['Subject'],
62 'duration': int(info['duration']) / 1000.0,
63 'formats': formats,
64 'thumbnail': info.get('bimg') or info.get('img'),
65 }