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