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.

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