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.

158 lines
6.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. js_to_json,
  7. int_or_none,
  8. update_url_query,
  9. parse_iso8601,
  10. )
  11. class ABCIE(InfoExtractor):
  12. IE_NAME = 'abc.net.au'
  13. _VALID_URL = r'https?://www\.abc\.net\.au/news/(?:[^/]+/){1,2}(?P<id>\d+)'
  14. _TESTS = [{
  15. 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334',
  16. 'md5': 'cb3dd03b18455a661071ee1e28344d9f',
  17. 'info_dict': {
  18. 'id': '5868334',
  19. 'ext': 'mp4',
  20. 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone',
  21. 'description': 'md5:809ad29c67a05f54eb41f2a105693a67',
  22. },
  23. 'skip': 'this video has expired',
  24. }, {
  25. 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
  26. 'md5': 'db2a5369238b51f9811ad815b69dc086',
  27. 'info_dict': {
  28. 'id': 'NvqvPeNZsHU',
  29. 'ext': 'mp4',
  30. 'upload_date': '20150816',
  31. 'uploader': 'ABC News (Australia)',
  32. 'description': 'Government backbencher Warren Entsch introduces a cross-party sponsored bill to legalise same-sex marriage, saying the bill is designed to promote "an inclusive Australia, not a divided one.". Read more here: http://ab.co/1Mwc6ef',
  33. 'uploader_id': 'NewsOnABC',
  34. 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
  35. },
  36. 'add_ie': ['Youtube'],
  37. 'skip': 'Not accessible from Travis CI server',
  38. }, {
  39. 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080',
  40. 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f',
  41. 'info_dict': {
  42. 'id': '6880080',
  43. 'ext': 'mp3',
  44. 'title': 'NAB lifts interest rates, following Westpac and CBA',
  45. 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728',
  46. },
  47. }, {
  48. 'url': 'http://www.abc.net.au/news/2015-10-19/6866214',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage(url, video_id)
  54. mobj = re.search(
  55. r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  56. webpage)
  57. if mobj is None:
  58. expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None)
  59. if expired:
  60. raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True)
  61. raise ExtractorError('Unable to extract video urls')
  62. urls_info = self._parse_json(
  63. mobj.group('json_data'), video_id, transform_source=js_to_json)
  64. if not isinstance(urls_info, list):
  65. urls_info = [urls_info]
  66. if mobj.group('type') == 'YouTube':
  67. return self.playlist_result([
  68. self.url_result(url_info['url']) for url_info in urls_info])
  69. formats = [{
  70. 'url': url_info['url'],
  71. 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none',
  72. 'width': int_or_none(url_info.get('width')),
  73. 'height': int_or_none(url_info.get('height')),
  74. 'tbr': int_or_none(url_info.get('bitrate')),
  75. 'filesize': int_or_none(url_info.get('filesize')),
  76. } for url_info in urls_info]
  77. self._sort_formats(formats)
  78. return {
  79. 'id': video_id,
  80. 'title': self._og_search_title(webpage),
  81. 'formats': formats,
  82. 'description': self._og_search_description(webpage),
  83. 'thumbnail': self._og_search_thumbnail(webpage),
  84. }
  85. class ABCIViewIE(InfoExtractor):
  86. IE_NAME = 'abc.net.au:iview'
  87. _VALID_URL = r'https?://iview\.abc\.net\.au/programs/[^/]+/(?P<id>[^/?#]+)'
  88. _TESTS = [{
  89. 'url': 'http://iview.abc.net.au/programs/gardening-australia/FA1505V024S00',
  90. 'md5': '979d10b2939101f0d27a06b79edad536',
  91. 'info_dict': {
  92. 'id': 'FA1505V024S00',
  93. 'ext': 'mp4',
  94. 'title': 'Series 27 Ep 24',
  95. 'description': 'md5:b28baeae7504d1148e1d2f0e3ed3c15d',
  96. 'upload_date': '20160820',
  97. 'uploader_id': 'abc1',
  98. 'timestamp': 1471719600,
  99. },
  100. }]
  101. def _real_extract(self, url):
  102. video_id = self._match_id(url)
  103. webpage = self._download_webpage(url, video_id)
  104. video_params = self._parse_json(self._search_regex(
  105. r'videoParams\s*=\s*({.+?});', webpage, 'video params'), video_id)
  106. title = video_params['title']
  107. stream = next(s for s in video_params['playlist'] if s.get('type') == 'program')
  108. formats = []
  109. f4m_url = stream.get('hds-unmetered') or stream['hds-metered']
  110. formats.extend(self._extract_f4m_formats(
  111. update_url_query(f4m_url, {'hdcore': '3.7.0'}),
  112. video_id, f4m_id='hds', fatal=False))
  113. formats.extend(self._extract_m3u8_formats(f4m_url.replace(
  114. 'akamaihd.net/z/', 'akamaihd.net/i/').replace('/manifest.f4m', '/master.m3u8'),
  115. video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  116. self._sort_formats(formats)
  117. subtitles = {}
  118. src_vtt = stream.get('captions', {}).get('src-vtt')
  119. if src_vtt:
  120. subtitles['en'] = [{
  121. 'url': src_vtt,
  122. 'ext': 'vtt',
  123. }]
  124. return {
  125. 'id': video_id,
  126. 'title': title,
  127. 'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
  128. 'thumbnail': self._html_search_meta(['og:image', 'twitter:image:src'], webpage),
  129. 'duration': int_or_none(video_params.get('eventDuration')),
  130. 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '),
  131. 'series': video_params.get('seriesTitle'),
  132. 'series_id': video_params.get('seriesHouseNumber') or video_id[:7],
  133. 'episode_number': int_or_none(self._html_search_meta('episodeNumber', webpage)),
  134. 'episode': self._html_search_meta('episode_title', webpage),
  135. 'uploader_id': video_params.get('channel'),
  136. 'formats': formats,
  137. 'subtitles': subtitles,
  138. }