You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
12 KiB

10 years ago
10 years ago
10 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import datetime
  4. import re
  5. import time
  6. import base64
  7. import hashlib
  8. from .common import InfoExtractor
  9. from ..compat import (
  10. compat_urllib_parse,
  11. compat_ord,
  12. compat_str,
  13. )
  14. from ..utils import (
  15. determine_ext,
  16. ExtractorError,
  17. parse_iso8601,
  18. sanitized_Request,
  19. int_or_none,
  20. str_or_none,
  21. encode_data_uri,
  22. url_basename,
  23. )
  24. class LetvIE(InfoExtractor):
  25. IE_DESC = '乐视网'
  26. _VALID_URL = r'http://www\.letv\.com/ptv/vplay/(?P<id>\d+).html'
  27. _TESTS = [{
  28. 'url': 'http://www.letv.com/ptv/vplay/22005890.html',
  29. 'md5': 'edadcfe5406976f42f9f266057ee5e40',
  30. 'info_dict': {
  31. 'id': '22005890',
  32. 'ext': 'mp4',
  33. 'title': '第87届奥斯卡颁奖礼完美落幕 《鸟人》成最大赢家',
  34. 'description': 'md5:a9cb175fd753e2962176b7beca21a47c',
  35. },
  36. 'params': {
  37. 'hls_prefer_native': True,
  38. },
  39. }, {
  40. 'url': 'http://www.letv.com/ptv/vplay/1415246.html',
  41. 'info_dict': {
  42. 'id': '1415246',
  43. 'ext': 'mp4',
  44. 'title': '美人天下01',
  45. 'description': 'md5:f88573d9d7225ada1359eaf0dbf8bcda',
  46. },
  47. 'params': {
  48. 'hls_prefer_native': True,
  49. },
  50. }, {
  51. 'note': 'This video is available only in Mainland China, thus a proxy is needed',
  52. 'url': 'http://www.letv.com/ptv/vplay/1118082.html',
  53. 'md5': '2424c74948a62e5f31988438979c5ad1',
  54. 'info_dict': {
  55. 'id': '1118082',
  56. 'ext': 'mp4',
  57. 'title': '与龙共舞 完整版',
  58. 'description': 'md5:7506a5eeb1722bb9d4068f85024e3986',
  59. },
  60. 'params': {
  61. 'hls_prefer_native': True,
  62. },
  63. 'skip': 'Only available in China',
  64. }]
  65. @staticmethod
  66. def urshift(val, n):
  67. return val >> n if val >= 0 else (val + 0x100000000) >> n
  68. # ror() and calc_time_key() are reversed from a embedded swf file in KLetvPlayer.swf
  69. def ror(self, param1, param2):
  70. _loc3_ = 0
  71. while _loc3_ < param2:
  72. param1 = self.urshift(param1, 1) + ((param1 & 1) << 31)
  73. _loc3_ += 1
  74. return param1
  75. def calc_time_key(self, param1):
  76. _loc2_ = 773625421
  77. _loc3_ = self.ror(param1, _loc2_ % 13)
  78. _loc3_ = _loc3_ ^ _loc2_
  79. _loc3_ = self.ror(_loc3_, _loc2_ % 17)
  80. return _loc3_
  81. # see M3U8Encryption class in KLetvPlayer.swf
  82. @staticmethod
  83. def decrypt_m3u8(encrypted_data):
  84. if encrypted_data[:5].decode('utf-8').lower() != 'vc_01':
  85. return encrypted_data
  86. encrypted_data = encrypted_data[5:]
  87. _loc4_ = bytearray()
  88. while encrypted_data:
  89. b = compat_ord(encrypted_data[0])
  90. _loc4_.extend([b // 16, b & 0x0f])
  91. encrypted_data = encrypted_data[1:]
  92. idx = len(_loc4_) - 11
  93. _loc4_ = _loc4_[idx:] + _loc4_[:idx]
  94. _loc7_ = bytearray()
  95. while _loc4_:
  96. _loc7_.append(_loc4_[0] * 16 + _loc4_[1])
  97. _loc4_ = _loc4_[2:]
  98. return bytes(_loc7_)
  99. def _real_extract(self, url):
  100. media_id = self._match_id(url)
  101. page = self._download_webpage(url, media_id)
  102. params = {
  103. 'id': media_id,
  104. 'platid': 1,
  105. 'splatid': 101,
  106. 'format': 1,
  107. 'tkey': self.calc_time_key(int(time.time())),
  108. 'domain': 'www.letv.com'
  109. }
  110. play_json_req = sanitized_Request(
  111. 'http://api.letv.com/mms/out/video/playJson?' + compat_urllib_parse.urlencode(params)
  112. )
  113. cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
  114. if cn_verification_proxy:
  115. play_json_req.add_header('Ytdl-request-proxy', cn_verification_proxy)
  116. play_json = self._download_json(
  117. play_json_req,
  118. media_id, 'Downloading playJson data')
  119. # Check for errors
  120. playstatus = play_json['playstatus']
  121. if playstatus['status'] == 0:
  122. flag = playstatus['flag']
  123. if flag == 1:
  124. msg = 'Country %s auth error' % playstatus['country']
  125. else:
  126. msg = 'Generic error. flag = %d' % flag
  127. raise ExtractorError(msg, expected=True)
  128. playurl = play_json['playurl']
  129. formats = ['350', '1000', '1300', '720p', '1080p']
  130. dispatch = playurl['dispatch']
  131. urls = []
  132. for format_id in formats:
  133. if format_id in dispatch:
  134. media_url = playurl['domain'][0] + dispatch[format_id][0]
  135. media_url += '&' + compat_urllib_parse.urlencode({
  136. 'm3v': 1,
  137. 'format': 1,
  138. 'expect': 3,
  139. 'rateid': format_id,
  140. })
  141. nodes_data = self._download_json(
  142. media_url, media_id,
  143. 'Download JSON metadata for format %s' % format_id)
  144. req = self._request_webpage(
  145. nodes_data['nodelist'][0]['location'], media_id,
  146. note='Downloading m3u8 information for format %s' % format_id)
  147. m3u8_data = self.decrypt_m3u8(req.read())
  148. url_info_dict = {
  149. 'url': encode_data_uri(m3u8_data, 'application/vnd.apple.mpegurl'),
  150. 'ext': determine_ext(dispatch[format_id][1]),
  151. 'format_id': format_id,
  152. 'protocol': 'm3u8',
  153. }
  154. if format_id[-1:] == 'p':
  155. url_info_dict['height'] = int_or_none(format_id[:-1])
  156. urls.append(url_info_dict)
  157. publish_time = parse_iso8601(self._html_search_regex(
  158. r'发布时间&nbsp;([^<>]+) ', page, 'publish time', default=None),
  159. delimiter=' ', timezone=datetime.timedelta(hours=8))
  160. description = self._html_search_meta('description', page, fatal=False)
  161. return {
  162. 'id': media_id,
  163. 'formats': urls,
  164. 'title': playurl['title'],
  165. 'thumbnail': playurl['pic'],
  166. 'description': description,
  167. 'timestamp': publish_time,
  168. }
  169. class LetvTvIE(InfoExtractor):
  170. _VALID_URL = r'http://www.letv.com/tv/(?P<id>\d+).html'
  171. _TESTS = [{
  172. 'url': 'http://www.letv.com/tv/46177.html',
  173. 'info_dict': {
  174. 'id': '46177',
  175. 'title': '美人天下',
  176. 'description': 'md5:395666ff41b44080396e59570dbac01c'
  177. },
  178. 'playlist_count': 35
  179. }]
  180. def _real_extract(self, url):
  181. playlist_id = self._match_id(url)
  182. page = self._download_webpage(url, playlist_id)
  183. media_urls = list(set(re.findall(
  184. r'http://www.letv.com/ptv/vplay/\d+.html', page)))
  185. entries = [self.url_result(media_url, ie='Letv')
  186. for media_url in media_urls]
  187. title = self._html_search_meta('keywords', page,
  188. fatal=False).split('')[0]
  189. description = self._html_search_meta('description', page, fatal=False)
  190. return self.playlist_result(entries, playlist_id, playlist_title=title,
  191. playlist_description=description)
  192. class LetvPlaylistIE(LetvTvIE):
  193. _VALID_URL = r'http://tv.letv.com/[a-z]+/(?P<id>[a-z]+)/index.s?html'
  194. _TESTS = [{
  195. 'url': 'http://tv.letv.com/izt/wuzetian/index.html',
  196. 'info_dict': {
  197. 'id': 'wuzetian',
  198. 'title': '武媚娘传奇',
  199. 'description': 'md5:e12499475ab3d50219e5bba00b3cb248'
  200. },
  201. # This playlist contains some extra videos other than the drama itself
  202. 'playlist_mincount': 96
  203. }, {
  204. 'url': 'http://tv.letv.com/pzt/lswjzzjc/index.shtml',
  205. 'info_dict': {
  206. 'id': 'lswjzzjc',
  207. # The title should be "劲舞青春", but I can't find a simple way to
  208. # determine the playlist title
  209. 'title': '乐视午间自制剧场',
  210. 'description': 'md5:b1eef244f45589a7b5b1af9ff25a4489'
  211. },
  212. 'playlist_mincount': 7
  213. }]
  214. class LetvCloudIE(InfoExtractor):
  215. IE_DESC = '乐视云'
  216. _VALID_URL = r'https?://yuntv\.letv\.com/bcloud.html\?.+'
  217. _TESTS = [{
  218. 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=467623dedf',
  219. 'md5': '26450599afd64c513bc77030ad15db44',
  220. 'info_dict': {
  221. 'id': 'p7jnfw5hw9_467623dedf',
  222. 'ext': 'mp4',
  223. 'title': 'Video p7jnfw5hw9_467623dedf',
  224. },
  225. }, {
  226. 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=ec93197892&pu=2c7cd40209&auto_play=1&gpcflag=1&width=640&height=360',
  227. 'md5': 'e03d9cc8d9c13191e1caf277e42dbd31',
  228. 'info_dict': {
  229. 'id': 'p7jnfw5hw9_ec93197892',
  230. 'ext': 'mp4',
  231. 'title': 'Video p7jnfw5hw9_ec93197892',
  232. },
  233. }, {
  234. 'url': 'http://yuntv.letv.com/bcloud.html?uu=p7jnfw5hw9&vu=187060b6fd',
  235. 'md5': 'cb988699a776b22d4a41b9d43acfb3ac',
  236. 'info_dict': {
  237. 'id': 'p7jnfw5hw9_187060b6fd',
  238. 'ext': 'mp4',
  239. 'title': 'Video p7jnfw5hw9_187060b6fd',
  240. },
  241. }]
  242. @staticmethod
  243. def sign_data(obj):
  244. if obj['cf'] == 'flash':
  245. salt = '2f9d6924b33a165a6d8b5d3d42f4f987'
  246. items = ['cf', 'format', 'ran', 'uu', 'ver', 'vu']
  247. elif obj['cf'] == 'html5':
  248. salt = 'fbeh5player12c43eccf2bec3300344'
  249. items = ['cf', 'ran', 'uu', 'bver', 'vu']
  250. input_data = ''.join([item + obj[item] for item in items]) + salt
  251. obj['sign'] = hashlib.md5(input_data.encode('utf-8')).hexdigest()
  252. def _get_formats(self, cf, uu, vu, media_id):
  253. def get_play_json(cf, timestamp):
  254. data = {
  255. 'cf': cf,
  256. 'ver': '2.2',
  257. 'bver': 'firefox44.0',
  258. 'format': 'json',
  259. 'uu': uu,
  260. 'vu': vu,
  261. 'ran': compat_str(timestamp),
  262. }
  263. self.sign_data(data)
  264. return self._download_json(
  265. 'http://api.letvcloud.com/gpc.php?' + compat_urllib_parse.urlencode(data),
  266. media_id, 'Downloading playJson data for type %s' % cf)
  267. play_json = get_play_json(cf, time.time())
  268. # The server time may be different from local time
  269. if play_json.get('code') == 10071:
  270. play_json = get_play_json(cf, play_json['timestamp'])
  271. if not play_json.get('data'):
  272. if play_json.get('message'):
  273. raise ExtractorError('Letv cloud said: %s' % play_json['message'], expected=True)
  274. elif play_json.get('code'):
  275. raise ExtractorError('Letv cloud returned error %d' % play_json['code'], expected=True)
  276. else:
  277. raise ExtractorError('Letv cloud returned an unknwon error')
  278. def b64decode(s):
  279. return base64.b64decode(s.encode('utf-8')).decode('utf-8')
  280. formats = []
  281. for media in play_json['data']['video_info']['media'].values():
  282. play_url = media['play_url']
  283. url = b64decode(play_url['main_url'])
  284. decoded_url = b64decode(url_basename(url))
  285. formats.append({
  286. 'url': url,
  287. 'ext': determine_ext(decoded_url),
  288. 'format_id': int_or_none(play_url.get('vtype')),
  289. 'format_note': str_or_none(play_url.get('definition')),
  290. 'width': int_or_none(play_url.get('vwidth')),
  291. 'height': int_or_none(play_url.get('vheight')),
  292. })
  293. return formats
  294. def _real_extract(self, url):
  295. uu_mobj = re.search('uu=([\w]+)', url)
  296. vu_mobj = re.search('vu=([\w]+)', url)
  297. if not uu_mobj or not vu_mobj:
  298. raise ExtractorError('Invalid URL: %s' % url, expected=True)
  299. uu = uu_mobj.group(1)
  300. vu = vu_mobj.group(1)
  301. media_id = uu + '_' + vu
  302. formats = self._get_formats('flash', uu, vu, media_id) + self._get_formats('html5', uu, vu, media_id)
  303. self._sort_formats(formats)
  304. return {
  305. 'id': media_id,
  306. 'title': 'Video %s' % media_id,
  307. 'formats': formats,
  308. }