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.

128 lines
4.6 KiB

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