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.

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