]>
Commit | Line | Data |
---|---|---|
7f09a662 YCH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
265bfa2c | 4 | import datetime |
57031161 | 5 | import re |
7f09a662 | 6 | import time |
7f09a662 YCH |
7 | |
8 | from .common import InfoExtractor | |
265bfa2c | 9 | from ..compat import ( |
265bfa2c | 10 | compat_urllib_parse, |
91410c9b PH |
11 | compat_urllib_request, |
12 | compat_urlparse, | |
265bfa2c PH |
13 | ) |
14 | from ..utils import ( | |
15 | determine_ext, | |
16 | ExtractorError, | |
17 | parse_iso8601, | |
593ddd85 | 18 | int_or_none, |
265bfa2c | 19 | ) |
7f09a662 YCH |
20 | |
21 | ||
22 | class LetvIE(InfoExtractor): | |
963d0ce7 | 23 | IE_DESC = '乐视网' |
57031161 | 24 | _VALID_URL = r'http://www\.letv\.com/ptv/vplay/(?P<id>\d+).html' |
7f09a662 YCH |
25 | |
26 | _TESTS = [{ | |
27 | 'url': 'http://www.letv.com/ptv/vplay/22005890.html', | |
28 | 'md5': 'cab23bd68d5a8db9be31c9a222c1e8df', | |
29 | 'info_dict': { | |
30 | 'id': '22005890', | |
31 | 'ext': 'mp4', | |
32 | 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家', | |
33 | 'timestamp': 1424747397, | |
34 | 'upload_date': '20150224', | |
67706359 | 35 | 'description': 'md5:a9cb175fd753e2962176b7beca21a47c', |
7f09a662 YCH |
36 | } |
37 | }, { | |
67706359 | 38 | 'url': 'http://www.letv.com/ptv/vplay/1415246.html', |
7f09a662 | 39 | 'info_dict': { |
67706359 | 40 | 'id': '1415246', |
7f09a662 | 41 | 'ext': 'mp4', |
67706359 YCH |
42 | 'title': '美人天下01', |
43 | 'description': 'md5:f88573d9d7225ada1359eaf0dbf8bcda', | |
44 | }, | |
91410c9b PH |
45 | }, { |
46 | 'note': 'This video is available only in Mainland China, thus a proxy is needed', | |
47 | 'url': 'http://www.letv.com/ptv/vplay/1118082.html', | |
48 | 'md5': 'f80936fbe20fb2f58648e81386ff7927', | |
49 | 'info_dict': { | |
50 | 'id': '1118082', | |
51 | 'ext': 'mp4', | |
52 | 'title': '与龙共舞 完整版', | |
53 | 'description': 'md5:7506a5eeb1722bb9d4068f85024e3986', | |
54 | }, | |
051df9ad | 55 | 'skip': 'Only available in China', |
7f09a662 YCH |
56 | }] |
57 | ||
58 | @staticmethod | |
59 | def urshift(val, n): | |
60 | return val >> n if val >= 0 else (val + 0x100000000) >> n | |
61 | ||
265bfa2c | 62 | # ror() and calc_time_key() are reversed from a embedded swf file in KLetvPlayer.swf |
7f09a662 YCH |
63 | def ror(self, param1, param2): |
64 | _loc3_ = 0 | |
65 | while _loc3_ < param2: | |
66 | param1 = self.urshift(param1, 1) + ((param1 & 1) << 31) | |
67 | _loc3_ += 1 | |
68 | return param1 | |
69 | ||
265bfa2c | 70 | def calc_time_key(self, param1): |
7f09a662 YCH |
71 | _loc2_ = 773625421 |
72 | _loc3_ = self.ror(param1, _loc2_ % 13) | |
73 | _loc3_ = _loc3_ ^ _loc2_ | |
74 | _loc3_ = self.ror(_loc3_, _loc2_ % 17) | |
75 | return _loc3_ | |
76 | ||
77 | def _real_extract(self, url): | |
78 | media_id = self._match_id(url) | |
79 | page = self._download_webpage(url, media_id) | |
80 | params = { | |
81 | 'id': media_id, | |
82 | 'platid': 1, | |
83 | 'splatid': 101, | |
84 | 'format': 1, | |
265bfa2c | 85 | 'tkey': self.calc_time_key(int(time.time())), |
7f09a662 YCH |
86 | 'domain': 'www.letv.com' |
87 | } | |
91410c9b PH |
88 | play_json_req = compat_urllib_request.Request( |
89 | 'http://api.letv.com/mms/out/video/playJson?' + compat_urllib_parse.urlencode(params) | |
90 | ) | |
63fc8000 YCH |
91 | cn_verification_proxy = self._downloader.params.get('cn_verification_proxy') |
92 | if cn_verification_proxy: | |
93 | play_json_req.add_header('Ytdl-request-proxy', cn_verification_proxy) | |
94 | ||
7f09a662 | 95 | play_json = self._download_json( |
91410c9b | 96 | play_json_req, |
576904bc | 97 | media_id, 'Downloading playJson data') |
7f09a662 YCH |
98 | |
99 | # Check for errors | |
100 | playstatus = play_json['playstatus'] | |
101 | if playstatus['status'] == 0: | |
102 | flag = playstatus['flag'] | |
103 | if flag == 1: | |
104 | msg = 'Country %s auth error' % playstatus['country'] | |
105 | else: | |
106 | msg = 'Generic error. flag = %d' % flag | |
107 | raise ExtractorError(msg, expected=True) | |
108 | ||
109 | playurl = play_json['playurl'] | |
110 | ||
111 | formats = ['350', '1000', '1300', '720p', '1080p'] | |
112 | dispatch = playurl['dispatch'] | |
113 | ||
114 | urls = [] | |
115 | for format_id in formats: | |
116 | if format_id in dispatch: | |
117 | media_url = playurl['domain'][0] + dispatch[format_id][0] | |
118 | ||
119 | # Mimic what flvxz.com do | |
120 | url_parts = list(compat_urlparse.urlparse(media_url)) | |
121 | qs = dict(compat_urlparse.parse_qs(url_parts[4])) | |
122 | qs.update({ | |
123 | 'platid': '14', | |
124 | 'splatid': '1401', | |
125 | 'tss': 'no', | |
126 | 'retry': 1 | |
127 | }) | |
128 | url_parts[4] = compat_urllib_parse.urlencode(qs) | |
129 | media_url = compat_urlparse.urlunparse(url_parts) | |
130 | ||
131 | url_info_dict = { | |
132 | 'url': media_url, | |
91410c9b PH |
133 | 'ext': determine_ext(dispatch[format_id][1]), |
134 | 'format_id': format_id, | |
7f09a662 YCH |
135 | } |
136 | ||
137 | if format_id[-1:] == 'p': | |
593ddd85 | 138 | url_info_dict['height'] = int_or_none(format_id[:-1]) |
7f09a662 YCH |
139 | |
140 | urls.append(url_info_dict) | |
141 | ||
142 | publish_time = parse_iso8601(self._html_search_regex( | |
91410c9b | 143 | r'发布时间 ([^<>]+) ', page, 'publish time', default=None), |
7f09a662 | 144 | delimiter=' ', timezone=datetime.timedelta(hours=8)) |
67706359 | 145 | description = self._html_search_meta('description', page, fatal=False) |
7f09a662 YCH |
146 | |
147 | return { | |
148 | 'id': media_id, | |
149 | 'formats': urls, | |
150 | 'title': playurl['title'], | |
151 | 'thumbnail': playurl['pic'], | |
67706359 | 152 | 'description': description, |
7f09a662 YCH |
153 | 'timestamp': publish_time, |
154 | } | |
57031161 YCH |
155 | |
156 | ||
157 | class LetvTvIE(InfoExtractor): | |
158 | _VALID_URL = r'http://www.letv.com/tv/(?P<id>\d+).html' | |
159 | _TESTS = [{ | |
160 | 'url': 'http://www.letv.com/tv/46177.html', | |
161 | 'info_dict': { | |
162 | 'id': '46177', | |
163 | 'title': '美人天下', | |
164 | 'description': 'md5:395666ff41b44080396e59570dbac01c' | |
165 | }, | |
166 | 'playlist_count': 35 | |
167 | }] | |
168 | ||
169 | def _real_extract(self, url): | |
170 | playlist_id = self._match_id(url) | |
171 | page = self._download_webpage(url, playlist_id) | |
172 | ||
173 | media_urls = list(set(re.findall( | |
174 | r'http://www.letv.com/ptv/vplay/\d+.html', page))) | |
175 | entries = [self.url_result(media_url, ie='Letv') | |
176 | for media_url in media_urls] | |
177 | ||
67706359 YCH |
178 | title = self._html_search_meta('keywords', page, |
179 | fatal=False).split(',')[0] | |
57031161 YCH |
180 | description = self._html_search_meta('description', page, fatal=False) |
181 | ||
182 | return self.playlist_result(entries, playlist_id, playlist_title=title, | |
183 | playlist_description=description) | |
184 | ||
185 | ||
186 | class LetvPlaylistIE(LetvTvIE): | |
187 | _VALID_URL = r'http://tv.letv.com/[a-z]+/(?P<id>[a-z]+)/index.s?html' | |
188 | _TESTS = [{ | |
189 | 'url': 'http://tv.letv.com/izt/wuzetian/index.html', | |
190 | 'info_dict': { | |
191 | 'id': 'wuzetian', | |
192 | 'title': '武媚娘传奇', | |
193 | 'description': 'md5:e12499475ab3d50219e5bba00b3cb248' | |
194 | }, | |
67706359 YCH |
195 | # This playlist contains some extra videos other than the drama itself |
196 | 'playlist_mincount': 96 | |
57031161 YCH |
197 | }, { |
198 | 'url': 'http://tv.letv.com/pzt/lswjzzjc/index.shtml', | |
199 | 'info_dict': { | |
200 | 'id': 'lswjzzjc', | |
67706359 YCH |
201 | # The title should be "劲舞青春", but I can't find a simple way to |
202 | # determine the playlist title | |
57031161 YCH |
203 | 'title': '乐视午间自制剧场', |
204 | 'description': 'md5:b1eef244f45589a7b5b1af9ff25a4489' | |
205 | }, | |
206 | 'playlist_mincount': 7 | |
207 | }] |