2 from __future__ import unicode_literals
8 from .common import InfoExtractor
11 compat_urllib_request,
21 class LetvIE(InfoExtractor):
22 _VALID_URL = r'http://www\.letv\.com/ptv/vplay/(?P<id>\d+).html'
25 'url': 'http://www.letv.com/ptv/vplay/22005890.html',
26 'md5': 'cab23bd68d5a8db9be31c9a222c1e8df',
30 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家',
31 'timestamp': 1424747397,
32 'upload_date': '20150224',
33 'description': 'md5:a9cb175fd753e2962176b7beca21a47c',
36 'url': 'http://www.letv.com/ptv/vplay/1415246.html',
41 'description': 'md5:f88573d9d7225ada1359eaf0dbf8bcda',
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',
51 'description': 'md5:7506a5eeb1722bb9d4068f85024e3986',
54 'cn_verification_proxy': 'http://proxy.uku.im:8888'
60 return val >> n if val >= 0 else (val + 0x100000000) >> n
62 # ror() and calc_time_key() are reversed from a embedded swf file in KLetvPlayer.swf
63 def ror(self, param1, param2):
65 while _loc3_ < param2:
66 param1 = self.urshift(param1, 1) + ((param1 & 1) << 31)
70 def calc_time_key(self, param1):
72 _loc3_ = self.ror(param1, _loc2_ % 13)
73 _loc3_ = _loc3_ ^ _loc2_
74 _loc3_ = self.ror(_loc3_, _loc2_ % 17)
77 def _real_extract(self, url):
78 media_id = self._match_id(url)
79 page = self._download_webpage(url, media_id)
85 'tkey': self.calc_time_key(int(time.time())),
86 'domain': 'www.letv.com'
88 play_json_req = compat_urllib_request.Request(
89 'http://api.letv.com/mms/out/video/playJson?' + compat_urllib_parse.urlencode(params)
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)
95 play_json = self._download_json(
97 media_id, 'Downloading playJson data')
100 playstatus = play_json['playstatus']
101 if playstatus['status'] == 0:
102 flag = playstatus['flag']
104 msg = 'Country %s auth error' % playstatus['country']
106 msg = 'Generic error. flag = %d' % flag
107 raise ExtractorError(msg, expected=True)
109 playurl = play_json['playurl']
111 formats = ['350', '1000', '1300', '720p', '1080p']
112 dispatch = playurl['dispatch']
115 for format_id in formats:
116 if format_id in dispatch:
117 media_url = playurl['domain'][0] + dispatch[format_id][0]
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]))
128 url_parts[4] = compat_urllib_parse.urlencode(qs)
129 media_url = compat_urlparse.urlunparse(url_parts)
133 'ext': determine_ext(dispatch[format_id][1]),
134 'format_id': format_id,
137 if format_id[-1:] == 'p':
138 url_info_dict['height'] = format_id[:-1]
140 urls.append(url_info_dict)
142 publish_time = parse_iso8601(self._html_search_regex(
143 r'发布时间 ([^<>]+) ', page, 'publish time', default=None),
144 delimiter=' ', timezone=datetime.timedelta(hours=8))
145 description = self._html_search_meta('description', page, fatal=False)
150 'title': playurl['title'],
151 'thumbnail': playurl['pic'],
152 'description': description,
153 'timestamp': publish_time,
157 class LetvTvIE(InfoExtractor):
158 _VALID_URL = r'http://www.letv.com/tv/(?P<id>\d+).html'
160 'url': 'http://www.letv.com/tv/46177.html',
164 'description': 'md5:395666ff41b44080396e59570dbac01c'
169 def _real_extract(self, url):
170 playlist_id = self._match_id(url)
171 page = self._download_webpage(url, playlist_id)
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]
178 title = self._html_search_meta('keywords', page,
179 fatal=False).split(',')[0]
180 description = self._html_search_meta('description', page, fatal=False)
182 return self.playlist_result(entries, playlist_id, playlist_title=title,
183 playlist_description=description)
186 class LetvPlaylistIE(LetvTvIE):
187 _VALID_URL = r'http://tv.letv.com/[a-z]+/(?P<id>[a-z]+)/index.s?html'
189 'url': 'http://tv.letv.com/izt/wuzetian/index.html',
193 'description': 'md5:e12499475ab3d50219e5bba00b3cb248'
195 # This playlist contains some extra videos other than the drama itself
196 'playlist_mincount': 96
198 'url': 'http://tv.letv.com/pzt/lswjzzjc/index.shtml',
201 # The title should be "劲舞青春", but I can't find a simple way to
202 # determine the playlist title
204 'description': 'md5:b1eef244f45589a7b5b1af9ff25a4489'
206 'playlist_mincount': 7