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.

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