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.

217 lines
7.5 KiB

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
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
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 re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_unquote,
  7. compat_urllib_parse_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. float_or_none,
  12. sanitized_Request,
  13. urlencode_postdata,
  14. )
  15. class CeskaTelevizeIE(InfoExtractor):
  16. _VALID_URL = r'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(?:[^/]+/)*(?P<id>[^/#?]+)/*(?:[#?].*)?$'
  17. _TESTS = [{
  18. 'url': 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220',
  19. 'info_dict': {
  20. 'id': '61924494876951776',
  21. 'ext': 'mp4',
  22. 'title': 'Hyde Park Civilizace',
  23. 'description': 'md5:fe93f6eda372d150759d11644ebbfb4a',
  24. 'thumbnail': 're:^https?://.*\.jpg',
  25. 'duration': 3350,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. }, {
  32. 'url': 'http://www.ceskatelevize.cz/ivysilani/10441294653-hyde-park-civilizace/215411058090502/bonus/20641-bonus-01-en',
  33. 'info_dict': {
  34. 'id': '61924494877028507',
  35. 'ext': 'mp4',
  36. 'title': 'Hyde Park Civilizace: Bonus 01 - En',
  37. 'description': 'English Subtittles',
  38. 'thumbnail': 're:^https?://.*\.jpg',
  39. 'duration': 81.3,
  40. },
  41. 'params': {
  42. # m3u8 download
  43. 'skip_download': True,
  44. },
  45. }, {
  46. # live stream
  47. 'url': 'http://www.ceskatelevize.cz/ivysilani/zive/ct4/',
  48. 'info_dict': {
  49. 'id': 402,
  50. 'ext': 'mp4',
  51. 'title': 're:^ČT Sport \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  52. 'is_live': True,
  53. },
  54. 'params': {
  55. # m3u8 download
  56. 'skip_download': True,
  57. },
  58. 'skip': 'Georestricted to Czech Republic',
  59. }, {
  60. # video with 18+ caution trailer
  61. 'url': 'http://www.ceskatelevize.cz/porady/10520528904-queer/215562210900007-bogotart/',
  62. 'info_dict': {
  63. 'id': '215562210900007-bogotart',
  64. 'title': 'Queer: Bogotart',
  65. 'description': 'Alternativní průvodce současným queer světem',
  66. },
  67. 'playlist': [{
  68. 'info_dict': {
  69. 'id': '61924494876844842',
  70. 'ext': 'mp4',
  71. 'title': 'Queer: Bogotart (Varování 18+)',
  72. 'duration': 10.2,
  73. },
  74. }, {
  75. 'info_dict': {
  76. 'id': '61924494877068022',
  77. 'ext': 'mp4',
  78. 'title': 'Queer: Bogotart (Queer)',
  79. 'thumbnail': 're:^https?://.*\.jpg',
  80. 'duration': 1558.3,
  81. },
  82. }],
  83. 'params': {
  84. # m3u8 download
  85. 'skip_download': True,
  86. },
  87. }]
  88. def _real_extract(self, url):
  89. url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
  90. mobj = re.match(self._VALID_URL, url)
  91. playlist_id = mobj.group('id')
  92. webpage = self._download_webpage(url, playlist_id)
  93. NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
  94. if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
  95. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  96. typ = self._html_search_regex(
  97. r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
  98. episode_id = self._html_search_regex(
  99. r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
  100. data = {
  101. 'playlist[0][type]': typ,
  102. 'playlist[0][id]': episode_id,
  103. 'requestUrl': compat_urllib_parse_urlparse(url).path,
  104. 'requestSource': 'iVysilani',
  105. }
  106. req = sanitized_Request(
  107. 'http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist',
  108. data=urlencode_postdata(data))
  109. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  110. req.add_header('x-addr', '127.0.0.1')
  111. req.add_header('X-Requested-With', 'XMLHttpRequest')
  112. req.add_header('Referer', url)
  113. playlistpage = self._download_json(req, playlist_id)
  114. playlist_url = playlistpage['url']
  115. if playlist_url == 'error_region':
  116. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  117. req = sanitized_Request(compat_urllib_parse_unquote(playlist_url))
  118. req.add_header('Referer', url)
  119. playlist_title = self._og_search_title(webpage, default=None)
  120. playlist_description = self._og_search_description(webpage, default=None)
  121. playlist = self._download_json(req, playlist_id)['playlist']
  122. playlist_len = len(playlist)
  123. entries = []
  124. for item in playlist:
  125. is_live = item.get('type') == 'LIVE'
  126. formats = []
  127. for format_id, stream_url in item['streamUrls'].items():
  128. formats.extend(self._extract_m3u8_formats(
  129. stream_url, playlist_id, 'mp4',
  130. entry_protocol='m3u8' if is_live else 'm3u8_native',
  131. fatal=False))
  132. self._sort_formats(formats)
  133. item_id = item.get('id') or item['assetId']
  134. title = item['title']
  135. duration = float_or_none(item.get('duration'))
  136. thumbnail = item.get('previewImageUrl')
  137. subtitles = {}
  138. if item.get('type') == 'VOD':
  139. subs = item.get('subtitles')
  140. if subs:
  141. subtitles = self.extract_subtitles(episode_id, subs)
  142. if playlist_len == 1:
  143. final_title = playlist_title or title
  144. if is_live:
  145. final_title = self._live_title(final_title)
  146. else:
  147. final_title = '%s (%s)' % (playlist_title, title)
  148. entries.append({
  149. 'id': item_id,
  150. 'title': final_title,
  151. 'description': playlist_description if playlist_len == 1 else None,
  152. 'thumbnail': thumbnail,
  153. 'duration': duration,
  154. 'formats': formats,
  155. 'subtitles': subtitles,
  156. 'is_live': is_live,
  157. })
  158. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  159. def _get_subtitles(self, episode_id, subs):
  160. original_subtitles = self._download_webpage(
  161. subs[0]['url'], episode_id, 'Downloading subtitles')
  162. srt_subs = self._fix_subtitles(original_subtitles)
  163. return {
  164. 'cs': [{
  165. 'ext': 'srt',
  166. 'data': srt_subs,
  167. }]
  168. }
  169. @staticmethod
  170. def _fix_subtitles(subtitles):
  171. """ Convert millisecond-based subtitles to SRT """
  172. def _msectotimecode(msec):
  173. """ Helper utility to convert milliseconds to timecode """
  174. components = []
  175. for divider in [1000, 60, 60, 100]:
  176. components.append(msec % divider)
  177. msec //= divider
  178. return '{3:02}:{2:02}:{1:02},{0:03}'.format(*components)
  179. def _fix_subtitle(subtitle):
  180. for line in subtitle.splitlines():
  181. m = re.match(r'^\s*([0-9]+);\s*([0-9]+)\s+([0-9]+)\s*$', line)
  182. if m:
  183. yield m.group(1)
  184. start, stop = (_msectotimecode(int(t)) for t in m.groups()[1:])
  185. yield '{0} --> {1}'.format(start, stop)
  186. else:
  187. yield line
  188. return '\r\n'.join(_fix_subtitle(subtitles))