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.

193 lines
6.8 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/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
  33. 'info_dict': {
  34. 'id': '61924494876844374',
  35. 'ext': 'mp4',
  36. 'title': 'První republika: Zpěvačka z Dupárny Bobina',
  37. 'description': 'Sága mapující atmosféru první republiky od r. 1918 do r. 1945.',
  38. 'thumbnail': 're:^https?://.*\.jpg',
  39. 'duration': 88.4,
  40. },
  41. 'params': {
  42. # m3u8 download
  43. 'skip_download': True,
  44. },
  45. }, {
  46. # video with 18+ caution trailer
  47. 'url': 'http://www.ceskatelevize.cz/porady/10520528904-queer/215562210900007-bogotart/',
  48. 'info_dict': {
  49. 'id': '215562210900007-bogotart',
  50. 'title': 'Queer: Bogotart',
  51. 'description': 'Alternativní průvodce současným queer světem',
  52. },
  53. 'playlist': [{
  54. 'info_dict': {
  55. 'id': '61924494876844842',
  56. 'ext': 'mp4',
  57. 'title': 'Queer: Bogotart (Varování 18+)',
  58. 'duration': 10.2,
  59. },
  60. }, {
  61. 'info_dict': {
  62. 'id': '61924494877068022',
  63. 'ext': 'mp4',
  64. 'title': 'Queer: Bogotart (Queer)',
  65. 'thumbnail': 're:^https?://.*\.jpg',
  66. 'duration': 1558.3,
  67. },
  68. }],
  69. 'params': {
  70. # m3u8 download
  71. 'skip_download': True,
  72. },
  73. }]
  74. def _real_extract(self, url):
  75. url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
  76. mobj = re.match(self._VALID_URL, url)
  77. playlist_id = mobj.group('id')
  78. webpage = self._download_webpage(url, playlist_id)
  79. NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
  80. if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
  81. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  82. typ = self._html_search_regex(
  83. r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
  84. episode_id = self._html_search_regex(
  85. r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
  86. data = {
  87. 'playlist[0][type]': typ,
  88. 'playlist[0][id]': episode_id,
  89. 'requestUrl': compat_urllib_parse_urlparse(url).path,
  90. 'requestSource': 'iVysilani',
  91. }
  92. req = sanitized_Request(
  93. 'http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist',
  94. data=urlencode_postdata(data))
  95. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  96. req.add_header('x-addr', '127.0.0.1')
  97. req.add_header('X-Requested-With', 'XMLHttpRequest')
  98. req.add_header('Referer', url)
  99. playlistpage = self._download_json(req, playlist_id)
  100. playlist_url = playlistpage['url']
  101. if playlist_url == 'error_region':
  102. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  103. req = sanitized_Request(compat_urllib_parse_unquote(playlist_url))
  104. req.add_header('Referer', url)
  105. playlist_title = self._og_search_title(webpage)
  106. playlist_description = self._og_search_description(webpage)
  107. playlist = self._download_json(req, playlist_id)['playlist']
  108. playlist_len = len(playlist)
  109. entries = []
  110. for item in playlist:
  111. formats = []
  112. for format_id, stream_url in item['streamUrls'].items():
  113. formats.extend(self._extract_m3u8_formats(
  114. stream_url, playlist_id, 'mp4',
  115. entry_protocol='m3u8_native', fatal=False))
  116. self._sort_formats(formats)
  117. item_id = item.get('id') or item['assetId']
  118. title = item['title']
  119. duration = float_or_none(item.get('duration'))
  120. thumbnail = item.get('previewImageUrl')
  121. subtitles = {}
  122. if item.get('type') == 'VOD':
  123. subs = item.get('subtitles')
  124. if subs:
  125. subtitles = self.extract_subtitles(episode_id, subs)
  126. entries.append({
  127. 'id': item_id,
  128. 'title': playlist_title if playlist_len == 1 else '%s (%s)' % (playlist_title, title),
  129. 'description': playlist_description if playlist_len == 1 else None,
  130. 'thumbnail': thumbnail,
  131. 'duration': duration,
  132. 'formats': formats,
  133. 'subtitles': subtitles,
  134. })
  135. return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)
  136. def _get_subtitles(self, episode_id, subs):
  137. original_subtitles = self._download_webpage(
  138. subs[0]['url'], episode_id, 'Downloading subtitles')
  139. srt_subs = self._fix_subtitles(original_subtitles)
  140. return {
  141. 'cs': [{
  142. 'ext': 'srt',
  143. 'data': srt_subs,
  144. }]
  145. }
  146. @staticmethod
  147. def _fix_subtitles(subtitles):
  148. """ Convert millisecond-based subtitles to SRT """
  149. def _msectotimecode(msec):
  150. """ Helper utility to convert milliseconds to timecode """
  151. components = []
  152. for divider in [1000, 60, 60, 100]:
  153. components.append(msec % divider)
  154. msec //= divider
  155. return '{3:02}:{2:02}:{1:02},{0:03}'.format(*components)
  156. def _fix_subtitle(subtitle):
  157. for line in subtitle.splitlines():
  158. m = re.match(r'^\s*([0-9]+);\s*([0-9]+)\s+([0-9]+)\s*$', line)
  159. if m:
  160. yield m.group(1)
  161. start, stop = (_msectotimecode(int(t)) for t in m.groups()[1:])
  162. yield '{0} --> {1}'.format(start, stop)
  163. else:
  164. yield line
  165. return '\r\n'.join(_fix_subtitle(subtitles))