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.

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