2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import (compat_urlparse, compat_urllib_parse)
11 from ..utils import (ExtractorError, parse_iso8601)
14 class LetvIE(InfoExtractor):
15 _VALID_URL = r'http://www\.letv\.com/ptv/vplay/(?P<id>\d+).html'
18 'url': 'http://www.letv.com/ptv/vplay/22005890.html',
19 'md5': 'cab23bd68d5a8db9be31c9a222c1e8df',
23 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家',
24 'timestamp': 1424747397,
25 'upload_date': '20150224',
26 'description': 'md5:a9cb175fd753e2962176b7beca21a47c',
29 'url': 'http://www.letv.com/ptv/vplay/1415246.html',
34 'description': 'md5:f88573d9d7225ada1359eaf0dbf8bcda',
36 'expected_warnings': [
40 # http://www.letv.com/ptv/vplay/1118082.html
41 # This video is available only in Mainland China
45 return val >> n if val >= 0 else (val + 0x100000000) >> n
47 # ror() and calcTimeKey() are reversed from a embedded swf file in KLetvPlayer.swf
48 def ror(self, param1, param2):
50 while _loc3_ < param2:
51 param1 = self.urshift(param1, 1) + ((param1 & 1) << 31)
55 def calcTimeKey(self, param1):
57 _loc3_ = self.ror(param1, _loc2_ % 13)
58 _loc3_ = _loc3_ ^ _loc2_
59 _loc3_ = self.ror(_loc3_, _loc2_ % 17)
62 def _real_extract(self, url):
63 media_id = self._match_id(url)
64 page = self._download_webpage(url, media_id)
70 'tkey': self.calcTimeKey(int(time.time())),
71 'domain': 'www.letv.com'
73 play_json = self._download_json(
74 'http://api.letv.com/mms/out/video/playJson?' + compat_urllib_parse.urlencode(params),
75 media_id, 'playJson data')
78 playstatus = play_json['playstatus']
79 if playstatus['status'] == 0:
80 flag = playstatus['flag']
82 msg = 'Country %s auth error' % playstatus['country']
84 msg = 'Generic error. flag = %d' % flag
85 raise ExtractorError(msg, expected=True)
87 playurl = play_json['playurl']
89 formats = ['350', '1000', '1300', '720p', '1080p']
90 dispatch = playurl['dispatch']
93 for format_id in formats:
94 if format_id in dispatch:
95 media_url = playurl['domain'][0] + dispatch[format_id][0]
97 # Mimic what flvxz.com do
98 url_parts = list(compat_urlparse.urlparse(media_url))
99 qs = dict(compat_urlparse.parse_qs(url_parts[4]))
106 url_parts[4] = compat_urllib_parse.urlencode(qs)
107 media_url = compat_urlparse.urlunparse(url_parts)
111 'ext': os.path.splitext(dispatch[format_id][1])[1][1:]
114 if format_id[-1:] == 'p':
115 url_info_dict['height'] = format_id[:-1]
117 urls.append(url_info_dict)
119 publish_time = parse_iso8601(self._html_search_regex(
120 r'发布时间 ([^<>]+) ', page, 'publish time', fatal=False),
121 delimiter=' ', timezone=datetime.timedelta(hours=8))
122 description = self._html_search_meta('description', page, fatal=False)
127 'title': playurl['title'],
128 'thumbnail': playurl['pic'],
129 'description': description,
130 'timestamp': publish_time,
134 class LetvTvIE(InfoExtractor):
135 _VALID_URL = r'http://www.letv.com/tv/(?P<id>\d+).html'
137 'url': 'http://www.letv.com/tv/46177.html',
141 'description': 'md5:395666ff41b44080396e59570dbac01c'
146 def _real_extract(self, url):
147 playlist_id = self._match_id(url)
148 page = self._download_webpage(url, playlist_id)
150 media_urls = list(set(re.findall(
151 r'http://www.letv.com/ptv/vplay/\d+.html', page)))
152 entries = [self.url_result(media_url, ie='Letv')
153 for media_url in media_urls]
155 title = self._html_search_meta('keywords', page,
156 fatal=False).split(',')[0]
157 description = self._html_search_meta('description', page, fatal=False)
159 return self.playlist_result(entries, playlist_id, playlist_title=title,
160 playlist_description=description)
163 class LetvPlaylistIE(LetvTvIE):
164 _VALID_URL = r'http://tv.letv.com/[a-z]+/(?P<id>[a-z]+)/index.s?html'
166 'url': 'http://tv.letv.com/izt/wuzetian/index.html',
170 'description': 'md5:e12499475ab3d50219e5bba00b3cb248'
172 # This playlist contains some extra videos other than the drama itself
173 'playlist_mincount': 96
175 'url': 'http://tv.letv.com/pzt/lswjzzjc/index.shtml',
178 # The title should be "劲舞青春", but I can't find a simple way to
179 # determine the playlist title
181 'description': 'md5:b1eef244f45589a7b5b1af9ff25a4489'
183 'playlist_mincount': 7