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.

167 lines
6.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. ExtractorError,
  7. js_to_json,
  8. int_or_none,
  9. parse_iso8601,
  10. try_get,
  11. )
  12. class ABCIE(InfoExtractor):
  13. IE_NAME = 'abc.net.au'
  14. _VALID_URL = r'https?://(?:www\.)?abc\.net\.au/news/(?:[^/]+/){1,2}(?P<id>\d+)'
  15. _TESTS = [{
  16. 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334',
  17. 'md5': 'cb3dd03b18455a661071ee1e28344d9f',
  18. 'info_dict': {
  19. 'id': '5868334',
  20. 'ext': 'mp4',
  21. 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone',
  22. 'description': 'md5:809ad29c67a05f54eb41f2a105693a67',
  23. },
  24. 'skip': 'this video has expired',
  25. }, {
  26. 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
  27. 'md5': 'db2a5369238b51f9811ad815b69dc086',
  28. 'info_dict': {
  29. 'id': 'NvqvPeNZsHU',
  30. 'ext': 'mp4',
  31. 'upload_date': '20150816',
  32. 'uploader': 'ABC News (Australia)',
  33. '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',
  34. 'uploader_id': 'NewsOnABC',
  35. 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
  36. },
  37. 'add_ie': ['Youtube'],
  38. 'skip': 'Not accessible from Travis CI server',
  39. }, {
  40. 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080',
  41. 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f',
  42. 'info_dict': {
  43. 'id': '6880080',
  44. 'ext': 'mp3',
  45. 'title': 'NAB lifts interest rates, following Westpac and CBA',
  46. 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728',
  47. },
  48. }, {
  49. 'url': 'http://www.abc.net.au/news/2015-10-19/6866214',
  50. 'only_matching': True,
  51. }]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  55. mobj = re.search(
  56. r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  57. webpage)
  58. if mobj is None:
  59. expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None)
  60. if expired:
  61. raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True)
  62. raise ExtractorError('Unable to extract video urls')
  63. urls_info = self._parse_json(
  64. mobj.group('json_data'), video_id, transform_source=js_to_json)
  65. if not isinstance(urls_info, list):
  66. urls_info = [urls_info]
  67. if mobj.group('type') == 'YouTube':
  68. return self.playlist_result([
  69. self.url_result(url_info['url']) for url_info in urls_info])
  70. formats = [{
  71. 'url': url_info['url'],
  72. 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none',
  73. 'width': int_or_none(url_info.get('width')),
  74. 'height': int_or_none(url_info.get('height')),
  75. 'tbr': int_or_none(url_info.get('bitrate')),
  76. 'filesize': int_or_none(url_info.get('filesize')),
  77. } for url_info in urls_info]
  78. self._sort_formats(formats)
  79. return {
  80. 'id': video_id,
  81. 'title': self._og_search_title(webpage),
  82. 'formats': formats,
  83. 'description': self._og_search_description(webpage),
  84. 'thumbnail': self._og_search_thumbnail(webpage),
  85. }
  86. class ABCIViewIE(InfoExtractor):
  87. IE_NAME = 'abc.net.au:iview'
  88. _VALID_URL = r'https?://iview\.abc\.net\.au/programs/[^/]+/(?P<id>[^/?#]+)'
  89. # ABC iview programs are normally available for 14 days only.
  90. _TESTS = [{
  91. 'url': 'http://iview.abc.net.au/programs/diaries-of-a-broken-mind/ZX9735A001S00',
  92. 'md5': 'cde42d728b3b7c2b32b1b94b4a548afc',
  93. 'info_dict': {
  94. 'id': 'ZX9735A001S00',
  95. 'ext': 'mp4',
  96. 'title': 'Diaries Of A Broken Mind',
  97. 'description': 'md5:7de3903874b7a1be279fe6b68718fc9e',
  98. 'upload_date': '20161010',
  99. 'uploader_id': 'abc2',
  100. 'timestamp': 1476064920,
  101. },
  102. 'skip': 'Video gone',
  103. }]
  104. def _real_extract(self, url):
  105. video_id = self._match_id(url)
  106. webpage = self._download_webpage(url, video_id)
  107. video_params = self._parse_json(self._search_regex(
  108. r'videoParams\s*=\s*({.+?});', webpage, 'video params'), video_id)
  109. title = video_params.get('title') or video_params['seriesTitle']
  110. stream = next(s for s in video_params['playlist'] if s.get('type') == 'program')
  111. format_urls = [
  112. try_get(stream, lambda x: x['hds-unmetered'], compat_str)]
  113. # May have higher quality video
  114. sd_url = try_get(
  115. stream, lambda x: x['streams']['hds']['sd'], compat_str)
  116. if sd_url:
  117. format_urls.append(sd_url.replace('metered', 'um'))
  118. formats = []
  119. for format_url in format_urls:
  120. if format_url:
  121. formats.extend(
  122. self._extract_akamai_formats(format_url, video_id))
  123. self._sort_formats(formats)
  124. subtitles = {}
  125. src_vtt = stream.get('captions', {}).get('src-vtt')
  126. if src_vtt:
  127. subtitles['en'] = [{
  128. 'url': src_vtt,
  129. 'ext': 'vtt',
  130. }]
  131. return {
  132. 'id': video_id,
  133. 'title': title,
  134. 'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
  135. 'thumbnail': self._html_search_meta(['og:image', 'twitter:image:src'], webpage),
  136. 'duration': int_or_none(video_params.get('eventDuration')),
  137. 'timestamp': parse_iso8601(video_params.get('pubDate'), ' '),
  138. 'series': video_params.get('seriesTitle'),
  139. 'series_id': video_params.get('seriesHouseNumber') or video_id[:7],
  140. 'episode_number': int_or_none(self._html_search_meta('episodeNumber', webpage, default=None)),
  141. 'episode': self._html_search_meta('episode_title', webpage, default=None),
  142. 'uploader_id': video_params.get('channel'),
  143. 'formats': formats,
  144. 'subtitles': subtitles,
  145. }