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.

210 lines
7.0 KiB

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
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. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. compat_urllib_parse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. sanitized_Request,
  12. )
  13. class SohuIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
  15. _TESTS = [{
  16. 'note': 'This video is available only in Mainland China',
  17. 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
  18. 'md5': '29175c8cadd8b5cc4055001e85d6b372',
  19. 'info_dict': {
  20. 'id': '382479172',
  21. 'ext': 'mp4',
  22. 'title': 'MV:Far East Movement《The Illest》',
  23. },
  24. 'skip': 'On available in China',
  25. }, {
  26. 'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
  27. 'md5': '699060e75cf58858dd47fb9c03c42cfb',
  28. 'info_dict': {
  29. 'id': '409385080',
  30. 'ext': 'mp4',
  31. 'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
  32. }
  33. }, {
  34. 'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
  35. 'md5': '9bf34be48f2f4dadcb226c74127e203c',
  36. 'info_dict': {
  37. 'id': '78693464',
  38. 'ext': 'mp4',
  39. 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
  40. }
  41. }, {
  42. 'note': 'Multipart video',
  43. 'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
  44. 'info_dict': {
  45. 'id': '78910339',
  46. 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
  47. },
  48. 'playlist': [{
  49. 'md5': 'bdbfb8f39924725e6589c146bc1883ad',
  50. 'info_dict': {
  51. 'id': '78910339_part1',
  52. 'ext': 'mp4',
  53. 'duration': 294,
  54. 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
  55. }
  56. }, {
  57. 'md5': '3e1f46aaeb95354fd10e7fca9fc1804e',
  58. 'info_dict': {
  59. 'id': '78910339_part2',
  60. 'ext': 'mp4',
  61. 'duration': 300,
  62. 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
  63. }
  64. }, {
  65. 'md5': '8407e634175fdac706766481b9443450',
  66. 'info_dict': {
  67. 'id': '78910339_part3',
  68. 'ext': 'mp4',
  69. 'duration': 150,
  70. 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
  71. }
  72. }]
  73. }, {
  74. 'note': 'Video with title containing dash',
  75. 'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
  76. 'info_dict': {
  77. 'id': '78932792',
  78. 'ext': 'mp4',
  79. 'title': 'youtube-dl testing video',
  80. },
  81. 'params': {
  82. 'skip_download': True
  83. }
  84. }]
  85. def _real_extract(self, url):
  86. def _fetch_data(vid_id, mytv=False):
  87. if mytv:
  88. base_data_url = 'http://my.tv.sohu.com/play/videonew.do?vid='
  89. else:
  90. base_data_url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
  91. req = sanitized_Request(base_data_url + vid_id)
  92. cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
  93. if cn_verification_proxy:
  94. req.add_header('Ytdl-request-proxy', cn_verification_proxy)
  95. return self._download_json(
  96. req, video_id,
  97. 'Downloading JSON data for %s' % vid_id)
  98. mobj = re.match(self._VALID_URL, url)
  99. video_id = mobj.group('id')
  100. mytv = mobj.group('mytv') is not None
  101. webpage = self._download_webpage(url, video_id)
  102. title = re.sub(r' - 搜狐视频$', '', self._og_search_title(webpage))
  103. vid = self._html_search_regex(
  104. r'var vid ?= ?["\'](\d+)["\']',
  105. webpage, 'video path')
  106. vid_data = _fetch_data(vid, mytv)
  107. if vid_data['play'] != 1:
  108. if vid_data.get('status') == 12:
  109. raise ExtractorError(
  110. 'Sohu said: There\'s something wrong in the video.',
  111. expected=True)
  112. else:
  113. raise ExtractorError(
  114. 'Sohu said: The video is only licensed to users in Mainland China.',
  115. expected=True)
  116. formats_json = {}
  117. for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
  118. vid_id = vid_data['data'].get('%sVid' % format_id)
  119. if not vid_id:
  120. continue
  121. vid_id = compat_str(vid_id)
  122. formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
  123. part_count = vid_data['data']['totalBlocks']
  124. playlist = []
  125. for i in range(part_count):
  126. formats = []
  127. for format_id, format_data in formats_json.items():
  128. allot = format_data['allot']
  129. data = format_data['data']
  130. clips_url = data['clipsURL']
  131. su = data['su']
  132. video_url = 'newflv.sohu.ccgslb.net'
  133. cdnId = None
  134. retries = 0
  135. while 'newflv.sohu.ccgslb.net' in video_url:
  136. params = {
  137. 'prot': 9,
  138. 'file': clips_url[i],
  139. 'new': su[i],
  140. 'prod': 'flash',
  141. }
  142. if cdnId is not None:
  143. params['idc'] = cdnId
  144. download_note = 'Downloading %s video URL part %d of %d' % (
  145. format_id, i + 1, part_count)
  146. if retries > 0:
  147. download_note += ' (retry #%d)' % retries
  148. part_info = self._parse_json(self._download_webpage(
  149. 'http://%s/?%s' % (allot, compat_urllib_parse.urlencode(params)),
  150. video_id, download_note), video_id)
  151. video_url = part_info['url']
  152. cdnId = part_info.get('nid')
  153. retries += 1
  154. if retries > 5:
  155. raise ExtractorError('Failed to get video URL')
  156. formats.append({
  157. 'url': video_url,
  158. 'format_id': format_id,
  159. 'filesize': data['clipsBytes'][i],
  160. 'width': data['width'],
  161. 'height': data['height'],
  162. 'fps': data['fps'],
  163. })
  164. self._sort_formats(formats)
  165. playlist.append({
  166. 'id': '%s_part%d' % (video_id, i + 1),
  167. 'title': title,
  168. 'duration': vid_data['data']['clipsDuration'][i],
  169. 'formats': formats,
  170. })
  171. if len(playlist) == 1:
  172. info = playlist[0]
  173. info['id'] = video_id
  174. else:
  175. info = {
  176. '_type': 'multi_video',
  177. 'entries': playlist,
  178. 'id': video_id,
  179. 'title': title,
  180. }
  181. return info