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.

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