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.

114 lines
4.0 KiB

10 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_request,
  7. compat_urllib_parse,
  8. compat_urllib_parse_urlparse,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. float_or_none,
  13. )
  14. class CeskaTelevizeIE(InfoExtractor):
  15. _VALID_URL = r'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(.+/)?(?P<id>[^?#]+)'
  16. _TESTS = [
  17. {
  18. 'url': 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220',
  19. 'info_dict': {
  20. 'id': '214411058091220',
  21. 'ext': 'mp4',
  22. 'title': 'Hyde Park Civilizace',
  23. 'description': 'Věda a současná civilizace. Interaktivní pořad - prostor pro vaše otázky a komentáře',
  24. 'thumbnail': 're:^https?://.*\.jpg',
  25. 'duration': 3350,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. },
  32. {
  33. 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
  34. 'info_dict': {
  35. 'id': '14716',
  36. 'ext': 'mp4',
  37. 'title': 'První republika: Zpěvačka z Dupárny Bobina',
  38. 'description': 'Sága mapující atmosféru první republiky od r. 1918 do r. 1945.',
  39. 'thumbnail': 're:^https?://.*\.jpg',
  40. 'duration': 88.4,
  41. },
  42. 'params': {
  43. # m3u8 download
  44. 'skip_download': True,
  45. },
  46. },
  47. ]
  48. def _real_extract(self, url):
  49. url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. webpage = self._download_webpage(url, video_id)
  53. NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
  54. if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
  55. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  56. typ = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
  57. episode_id = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
  58. data = {
  59. 'playlist[0][type]': typ,
  60. 'playlist[0][id]': episode_id,
  61. 'requestUrl': compat_urllib_parse_urlparse(url).path,
  62. 'requestSource': 'iVysilani',
  63. }
  64. req = compat_urllib_request.Request(
  65. 'http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist',
  66. data=compat_urllib_parse.urlencode(data))
  67. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  68. req.add_header('x-addr', '127.0.0.1')
  69. req.add_header('X-Requested-With', 'XMLHttpRequest')
  70. req.add_header('Referer', url)
  71. playlistpage = self._download_json(req, video_id)
  72. playlist_url = playlistpage['url']
  73. if playlist_url == 'error_region':
  74. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  75. req = compat_urllib_request.Request(compat_urllib_parse.unquote(playlist_url))
  76. req.add_header('Referer', url)
  77. playlist = self._download_json(req, video_id)
  78. item = playlist['playlist'][0]
  79. formats = []
  80. for format_id, stream_url in item['streamUrls'].items():
  81. formats.extend(self._extract_m3u8_formats(stream_url, video_id, 'mp4'))
  82. self._sort_formats(formats)
  83. title = self._og_search_title(webpage)
  84. description = self._og_search_description(webpage)
  85. duration = float_or_none(item.get('duration'))
  86. thumbnail = item.get('previewImageUrl')
  87. return {
  88. 'id': episode_id,
  89. 'title': title,
  90. 'description': description,
  91. 'thumbnail': thumbnail,
  92. 'duration': duration,
  93. 'formats': formats,
  94. }