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.

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