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.

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