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.

128 lines
4.6 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. )
  13. class CeskaTelevizeIE(InfoExtractor):
  14. _VALID_URL = r'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(.+/)?(?P<id>[^?#]+)'
  15. _TESTS = [
  16. {
  17. 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/213512120230004-spanelska-chripka',
  18. 'info_dict': {
  19. 'id': '213512120230004',
  20. 'ext': 'flv',
  21. 'title': 'První republika: Španělská chřipka',
  22. 'duration': 3107.4,
  23. },
  24. 'params': {
  25. 'skip_download': True, # requires rtmpdump
  26. },
  27. 'skip': 'Works only from Czech Republic.',
  28. },
  29. {
  30. 'url': 'http://www.ceskatelevize.cz/ivysilani/1030584952-tsatsiki-maminka-a-policajt',
  31. 'info_dict': {
  32. 'id': '20138143440',
  33. 'ext': 'flv',
  34. 'title': 'Tsatsiki, maminka a policajt',
  35. 'duration': 6754.1,
  36. },
  37. 'params': {
  38. 'skip_download': True, # requires rtmpdump
  39. },
  40. 'skip': 'Works only from Czech Republic.',
  41. },
  42. {
  43. 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
  44. 'info_dict': {
  45. 'id': '14716',
  46. 'ext': 'flv',
  47. 'title': 'První republika: Zpěvačka z Dupárny Bobina',
  48. 'duration': 90,
  49. },
  50. 'params': {
  51. 'skip_download': True, # requires rtmpdump
  52. },
  53. },
  54. ]
  55. def _real_extract(self, url):
  56. url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
  57. mobj = re.match(self._VALID_URL, url)
  58. video_id = mobj.group('id')
  59. webpage = self._download_webpage(url, video_id)
  60. NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
  61. if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
  62. raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
  63. typ = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
  64. episode_id = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
  65. data = {
  66. 'playlist[0][type]': typ,
  67. 'playlist[0][id]': episode_id,
  68. 'requestUrl': compat_urllib_parse_urlparse(url).path,
  69. 'requestSource': 'iVysilani',
  70. }
  71. req = compat_urllib_request.Request('http://www.ceskatelevize.cz/ivysilani/ajax/get-playlist-url',
  72. data=compat_urllib_parse.urlencode(data))
  73. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  74. req.add_header('x-addr', '127.0.0.1')
  75. req.add_header('X-Requested-With', 'XMLHttpRequest')
  76. req.add_header('Referer', url)
  77. playlistpage = self._download_json(req, video_id)
  78. req = compat_urllib_request.Request(compat_urllib_parse.unquote(playlistpage['url']))
  79. req.add_header('Referer', url)
  80. playlist = self._download_xml(req, video_id)
  81. formats = []
  82. for i in playlist.find('smilRoot/body'):
  83. if 'AD' not in i.attrib['id']:
  84. base_url = i.attrib['base']
  85. parsedurl = compat_urllib_parse_urlparse(base_url)
  86. duration = i.attrib['duration']
  87. for video in i.findall('video'):
  88. if video.attrib['label'] != 'AD':
  89. format_id = video.attrib['label']
  90. play_path = video.attrib['src']
  91. vbr = int(video.attrib['system-bitrate'])
  92. formats.append({
  93. 'format_id': format_id,
  94. 'url': base_url,
  95. 'vbr': vbr,
  96. 'play_path': play_path,
  97. 'app': parsedurl.path[1:] + '?' + parsedurl.query,
  98. 'rtmp_live': True,
  99. 'ext': 'flv',
  100. })
  101. self._sort_formats(formats)
  102. return {
  103. 'id': episode_id,
  104. 'title': self._html_search_regex(r'<title>(.+?) — iVysílání — Česká televize</title>', webpage, 'title'),
  105. 'duration': float(duration),
  106. 'formats': formats,
  107. }