]>
Commit | Line | Data |
---|---|---|
7f09a662 YCH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import os.path | |
5 | import time | |
6 | import datetime | |
7 | ||
8 | from .common import InfoExtractor | |
9 | from ..compat import (compat_urlparse, compat_urllib_parse) | |
10 | from ..utils import (ExtractorError, parse_iso8601) | |
11 | ||
12 | ||
13 | class LetvIE(InfoExtractor): | |
14 | _VALID_URL = r'http://www.letv.com/ptv/vplay/(?P<id>\d+).html' | |
15 | ||
16 | _TESTS = [{ | |
17 | 'url': 'http://www.letv.com/ptv/vplay/22005890.html', | |
18 | 'md5': 'cab23bd68d5a8db9be31c9a222c1e8df', | |
19 | 'info_dict': { | |
20 | 'id': '22005890', | |
21 | 'ext': 'mp4', | |
22 | 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家', | |
23 | 'timestamp': 1424747397, | |
24 | 'upload_date': '20150224', | |
25 | } | |
26 | }, { | |
27 | 'url': 'http://www.letv.com/ptv/vplay/1118082.html', | |
28 | 'info_dict': { | |
29 | 'id': '1118082', | |
30 | 'ext': 'mp4', | |
31 | } | |
32 | }] | |
33 | ||
34 | @staticmethod | |
35 | def urshift(val, n): | |
36 | return val >> n if val >= 0 else (val + 0x100000000) >> n | |
37 | ||
38 | # ror() and calcTimeKey() are reversed from a embedded swf file in KLetvPlayer.swf | |
39 | def ror(self, param1, param2): | |
40 | _loc3_ = 0 | |
41 | while _loc3_ < param2: | |
42 | param1 = self.urshift(param1, 1) + ((param1 & 1) << 31) | |
43 | _loc3_ += 1 | |
44 | return param1 | |
45 | ||
46 | def calcTimeKey(self, param1): | |
47 | _loc2_ = 773625421 | |
48 | _loc3_ = self.ror(param1, _loc2_ % 13) | |
49 | _loc3_ = _loc3_ ^ _loc2_ | |
50 | _loc3_ = self.ror(_loc3_, _loc2_ % 17) | |
51 | return _loc3_ | |
52 | ||
53 | def _real_extract(self, url): | |
54 | media_id = self._match_id(url) | |
55 | page = self._download_webpage(url, media_id) | |
56 | params = { | |
57 | 'id': media_id, | |
58 | 'platid': 1, | |
59 | 'splatid': 101, | |
60 | 'format': 1, | |
61 | 'tkey': self.calcTimeKey(int(time.time())), | |
62 | 'domain': 'www.letv.com' | |
63 | } | |
64 | play_json = self._download_json( | |
65 | 'http://api.letv.com/mms/out/video/playJson?' + compat_urllib_parse.urlencode(params), | |
66 | media_id, 'playJson data') | |
67 | ||
68 | # Check for errors | |
69 | playstatus = play_json['playstatus'] | |
70 | if playstatus['status'] == 0: | |
71 | flag = playstatus['flag'] | |
72 | if flag == 1: | |
73 | msg = 'Country %s auth error' % playstatus['country'] | |
74 | else: | |
75 | msg = 'Generic error. flag = %d' % flag | |
76 | raise ExtractorError(msg, expected=True) | |
77 | ||
78 | playurl = play_json['playurl'] | |
79 | ||
80 | formats = ['350', '1000', '1300', '720p', '1080p'] | |
81 | dispatch = playurl['dispatch'] | |
82 | ||
83 | urls = [] | |
84 | for format_id in formats: | |
85 | if format_id in dispatch: | |
86 | media_url = playurl['domain'][0] + dispatch[format_id][0] | |
87 | ||
88 | # Mimic what flvxz.com do | |
89 | url_parts = list(compat_urlparse.urlparse(media_url)) | |
90 | qs = dict(compat_urlparse.parse_qs(url_parts[4])) | |
91 | qs.update({ | |
92 | 'platid': '14', | |
93 | 'splatid': '1401', | |
94 | 'tss': 'no', | |
95 | 'retry': 1 | |
96 | }) | |
97 | url_parts[4] = compat_urllib_parse.urlencode(qs) | |
98 | media_url = compat_urlparse.urlunparse(url_parts) | |
99 | ||
100 | url_info_dict = { | |
101 | 'url': media_url, | |
102 | 'ext': os.path.splitext(dispatch[format_id][1])[1][1:] | |
103 | } | |
104 | ||
105 | if format_id[-1:] == 'p': | |
106 | url_info_dict['height'] = format_id[:-1] | |
107 | ||
108 | urls.append(url_info_dict) | |
109 | ||
110 | publish_time = parse_iso8601(self._html_search_regex( | |
111 | r'发布时间 ([^<>]+) ', page, 'publish time', fatal=False), | |
112 | delimiter=' ', timezone=datetime.timedelta(hours=8)) | |
113 | ||
114 | return { | |
115 | 'id': media_id, | |
116 | 'formats': urls, | |
117 | 'title': playurl['title'], | |
118 | 'thumbnail': playurl['pic'], | |
119 | 'timestamp': publish_time, | |
120 | } |