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.

142 lines
5.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_HTTPError
  6. from ..utils import (
  7. float_or_none,
  8. parse_iso8601,
  9. unescapeHTML,
  10. ExtractorError,
  11. )
  12. class RteBaseIE(InfoExtractor):
  13. def _real_extract(self, url):
  14. item_id = self._match_id(url)
  15. try:
  16. json_string = self._download_json(
  17. 'http://www.rte.ie/rteavgen/getplaylist/?type=web&format=json&id=' + item_id,
  18. item_id)
  19. except ExtractorError as ee:
  20. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404:
  21. error_info = self._parse_json(ee.cause.read().decode(), item_id, fatal=False)
  22. if error_info:
  23. raise ExtractorError(
  24. '%s said: %s' % (self.IE_NAME, error_info['message']),
  25. expected=True)
  26. raise
  27. # NB the string values in the JSON are stored using XML escaping(!)
  28. show = json_string['shows'][0]
  29. title = unescapeHTML(show['title'])
  30. description = unescapeHTML(show.get('description'))
  31. thumbnail = show.get('thumbnail')
  32. duration = float_or_none(show.get('duration'), 1000)
  33. timestamp = parse_iso8601(show.get('published'))
  34. mg = show['media:group'][0]
  35. formats = []
  36. if mg.get('url'):
  37. m = re.match(r'(?P<url>rtmpe?://[^/]+)/(?P<app>.+)/(?P<playpath>mp4:.*)', mg['url'])
  38. if m:
  39. m = m.groupdict()
  40. formats.append({
  41. 'url': m['url'] + '/' + m['app'],
  42. 'app': m['app'],
  43. 'play_path': m['playpath'],
  44. 'player_url': url,
  45. 'ext': 'flv',
  46. 'format_id': 'rtmp',
  47. })
  48. if mg.get('hls_server') and mg.get('hls_url'):
  49. formats.extend(self._extract_m3u8_formats(
  50. mg['hls_server'] + mg['hls_url'], item_id, 'mp4',
  51. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  52. if mg.get('hds_server') and mg.get('hds_url'):
  53. formats.extend(self._extract_f4m_formats(
  54. mg['hds_server'] + mg['hds_url'], item_id,
  55. f4m_id='hds', fatal=False))
  56. self._sort_formats(formats)
  57. return {
  58. 'id': item_id,
  59. 'title': title,
  60. 'description': description,
  61. 'thumbnail': thumbnail,
  62. 'timestamp': timestamp,
  63. 'duration': duration,
  64. 'formats': formats,
  65. }
  66. class RteIE(RteBaseIE):
  67. IE_NAME = 'rte'
  68. IE_DESC = 'Raidió Teilifís Éireann TV'
  69. _VALID_URL = r'https?://(?:www\.)?rte\.ie/player/[^/]{2,3}/show/[^/]+/(?P<id>[0-9]+)'
  70. _TEST = {
  71. 'url': 'http://www.rte.ie/player/ie/show/iwitness-862/10478715/',
  72. 'md5': '4a76eb3396d98f697e6e8110563d2604',
  73. 'info_dict': {
  74. 'id': '10478715',
  75. 'ext': 'mp4',
  76. 'title': 'iWitness',
  77. 'thumbnail': 're:^https?://.*\.jpg$',
  78. 'description': 'The spirit of Ireland, one voice and one minute at a time.',
  79. 'duration': 60.046,
  80. 'upload_date': '20151012',
  81. 'timestamp': 1444694160,
  82. },
  83. }
  84. class RteRadioIE(RteBaseIE):
  85. IE_NAME = 'rte:radio'
  86. IE_DESC = 'Raidió Teilifís Éireann radio'
  87. # Radioplayer URLs have two distinct specifier formats,
  88. # the old format #!rii=<channel_id>:<id>:<playable_item_id>:<date>:
  89. # the new format #!rii=b<channel_id>_<id>_<playable_item_id>_<date>_
  90. # where the IDs are int/empty, the date is DD-MM-YYYY, and the specifier may be truncated.
  91. # An <id> uniquely defines an individual recording, and is the only part we require.
  92. _VALID_URL = r'https?://(?:www\.)?rte\.ie/radio/utils/radioplayer/rteradioweb\.html#!rii=(?:b?[0-9]*)(?:%3A|:|%5F|_)(?P<id>[0-9]+)'
  93. _TESTS = [{
  94. # Old-style player URL; HLS and RTMPE formats
  95. 'url': 'http://www.rte.ie/radio/utils/radioplayer/rteradioweb.html#!rii=16:10507902:2414:27-12-2015:',
  96. 'md5': 'c79ccb2c195998440065456b69760411',
  97. 'info_dict': {
  98. 'id': '10507902',
  99. 'ext': 'mp4',
  100. 'title': 'Gloria',
  101. 'thumbnail': 're:^https?://.*\.jpg$',
  102. 'description': 'md5:9ce124a7fb41559ec68f06387cabddf0',
  103. 'timestamp': 1451203200,
  104. 'upload_date': '20151227',
  105. 'duration': 7230.0,
  106. },
  107. }, {
  108. # New-style player URL; RTMPE formats only
  109. 'url': 'http://rte.ie/radio/utils/radioplayer/rteradioweb.html#!rii=b16_3250678_8861_06-04-2012_',
  110. 'info_dict': {
  111. 'id': '3250678',
  112. 'ext': 'flv',
  113. 'title': 'The Lyric Concert with Paul Herriott',
  114. 'thumbnail': 're:^https?://.*\.jpg$',
  115. 'description': '',
  116. 'timestamp': 1333742400,
  117. 'upload_date': '20120406',
  118. 'duration': 7199.016,
  119. },
  120. 'params': {
  121. # rtmp download
  122. 'skip_download': True,
  123. },
  124. }]