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