rte.py 6.1 KB

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