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.

122 lines
4.6 KiB

10 years ago
9 years ago
9 years ago
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. unescapeHTML,
  7. )
  8. class RteIE(InfoExtractor):
  9. IE_NAME = 'rte'
  10. IE_DESC = 'Raidió Teilifís Éireann TV'
  11. _VALID_URL = r'https?://(?:www\.)?rte\.ie/player/[^/]{2,3}/show/[^/]+/(?P<id>[0-9]+)'
  12. _TEST = {
  13. 'url': 'http://www.rte.ie/player/ie/show/iwitness-862/10478715/',
  14. 'info_dict': {
  15. 'id': '10478715',
  16. 'ext': 'flv',
  17. 'title': 'Watch iWitness online',
  18. 'thumbnail': 're:^https?://.*\.jpg$',
  19. 'description': 'iWitness : The spirit of Ireland, one voice and one minute at a time.',
  20. 'duration': 60.046,
  21. },
  22. 'params': {
  23. 'skip_download': 'f4m fails with --test atm'
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. title = self._og_search_title(webpage)
  30. description = self._html_search_meta('description', webpage, 'description')
  31. duration = float_or_none(self._html_search_meta(
  32. 'duration', webpage, 'duration', fatal=False), 1000)
  33. thumbnail_id = self._search_regex(
  34. r'<meta name="thumbnail" content="uri:irus:(.*?)" />', webpage, 'thumbnail')
  35. thumbnail = 'http://img.rasset.ie/' + thumbnail_id + '.jpg'
  36. feeds_url = self._html_search_meta("feeds-prefix", webpage, 'feeds url') + video_id
  37. json_string = self._download_json(feeds_url, video_id)
  38. # f4m_url = server + relative_url
  39. f4m_url = json_string['shows'][0]['media:group'][0]['rte:server'] + json_string['shows'][0]['media:group'][0]['url']
  40. f4m_formats = self._extract_f4m_formats(f4m_url, video_id)
  41. return {
  42. 'id': video_id,
  43. 'title': title,
  44. 'formats': f4m_formats,
  45. 'description': description,
  46. 'thumbnail': thumbnail,
  47. 'duration': duration,
  48. }
  49. class RteRadioIE(InfoExtractor):
  50. IE_NAME = 'rte:radio'
  51. IE_DESC = 'Raidió Teilifís Éireann radio'
  52. # Radioplayer URLs have the specifier #!rii=<channel_id>:<id>:<playable_item_id>:<date>:
  53. # where the IDs are int/empty, the date is DD-MM-YYYY, and the specifier may be truncated.
  54. # An <id> uniquely defines an individual recording, and is the only part we require.
  55. _VALID_URL = r'https?://(?:www\.)?rte\.ie/radio/utils/radioplayer/rteradioweb\.html#!rii=(?:[0-9]*)(?:%3A|:)(?P<id>[0-9]+)'
  56. _TEST = {
  57. 'url': 'http://www.rte.ie/radio/utils/radioplayer/rteradioweb.html#!rii=16:10507902:2414:27-12-2015:',
  58. 'info_dict': {
  59. 'id': '10507902',
  60. 'ext': 'flv',
  61. 'title': 'Gloria',
  62. 'thumbnail': 're:^https?://.*\.jpg$',
  63. 'description': 'Tim Thurston guides you through a millennium of sacred music featuring Gregorian chant, pure solo voices and choral masterpieces, framed around the glorious music of J.S. Bach.',
  64. 'duration': 7230.0,
  65. },
  66. 'params': {
  67. 'skip_download': 'f4m fails with --test atm'
  68. }
  69. }
  70. def _real_extract(self, url):
  71. item_id = self._match_id(url)
  72. feeds_url = 'http://www.rte.ie/rteavgen/getplaylist/?type=web&format=json&id=' + item_id
  73. json_string = self._download_json(feeds_url, item_id)
  74. # NB the string values in the JSON are stored using XML escaping(!)
  75. show = json_string['shows'][0]
  76. title = unescapeHTML(show['title'])
  77. description = unescapeHTML(show.get('description'))
  78. thumbnail = show.get('thumbnail')
  79. duration = float_or_none(show.get('duration'), 1000)
  80. mg = show['media:group'][0]
  81. formats = []
  82. if mg.get('url') and not mg['url'].startswith('rtmpe:'):
  83. formats.append({'url': mg.get('url')})
  84. if mg.get('hls_server') and mg.get('hls_url'):
  85. hls_url = mg['hls_server'] + mg['hls_url']
  86. hls_formats = self._extract_m3u8_formats(
  87. hls_url, item_id, 'mp4', m3u8_id='hls', fatal=False)
  88. formats.extend(hls_formats)
  89. if mg.get('hds_server') and mg.get('hds_url'):
  90. f4m_url = mg['hds_server'] + mg['hds_url']
  91. f4m_formats = self._extract_f4m_formats(
  92. f4m_url, item_id, f4m_id='hds', fatal=False)
  93. formats.extend(f4m_formats)
  94. return {
  95. 'id': item_id,
  96. 'title': title,
  97. 'formats': formats,
  98. 'description': description,
  99. 'thumbnail': thumbnail,
  100. 'duration': duration,
  101. }