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.

95 lines
3.7 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. )
  9. class ABCIE(InfoExtractor):
  10. IE_NAME = 'abc.net.au'
  11. _VALID_URL = r'https?://www\.abc\.net\.au/news/(?:[^/]+/){1,2}(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334',
  14. 'md5': 'cb3dd03b18455a661071ee1e28344d9f',
  15. 'info_dict': {
  16. 'id': '5868334',
  17. 'ext': 'mp4',
  18. 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone',
  19. 'description': 'md5:809ad29c67a05f54eb41f2a105693a67',
  20. },
  21. 'skip': 'this video has expired',
  22. }, {
  23. 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
  24. 'md5': 'db2a5369238b51f9811ad815b69dc086',
  25. 'info_dict': {
  26. 'id': 'NvqvPeNZsHU',
  27. 'ext': 'mp4',
  28. 'upload_date': '20150816',
  29. 'uploader': 'ABC News (Australia)',
  30. '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',
  31. 'uploader_id': 'NewsOnABC',
  32. 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
  33. },
  34. 'add_ie': ['Youtube'],
  35. 'skip': 'Not accessible from Travis CI server',
  36. }, {
  37. 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080',
  38. 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f',
  39. 'info_dict': {
  40. 'id': '6880080',
  41. 'ext': 'mp3',
  42. 'title': 'NAB lifts interest rates, following Westpac and CBA',
  43. 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728',
  44. },
  45. }, {
  46. 'url': 'http://www.abc.net.au/news/2015-10-19/6866214',
  47. 'only_matching': True,
  48. }]
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. webpage = self._download_webpage(url, video_id)
  52. mobj = re.search(
  53. r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  54. webpage)
  55. if mobj is None:
  56. expired = self._html_search_regex(r'(?s)class="expired-(?:video|audio)".+?<span>(.+?)</span>', webpage, 'expired', None)
  57. if expired:
  58. raise ExtractorError('%s said: %s' % (self.IE_NAME, expired), expected=True)
  59. raise ExtractorError('Unable to extract video urls')
  60. urls_info = self._parse_json(
  61. mobj.group('json_data'), video_id, transform_source=js_to_json)
  62. if not isinstance(urls_info, list):
  63. urls_info = [urls_info]
  64. if mobj.group('type') == 'YouTube':
  65. return self.playlist_result([
  66. self.url_result(url_info['url']) for url_info in urls_info])
  67. formats = [{
  68. 'url': url_info['url'],
  69. 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none',
  70. 'width': int_or_none(url_info.get('width')),
  71. 'height': int_or_none(url_info.get('height')),
  72. 'tbr': int_or_none(url_info.get('bitrate')),
  73. 'filesize': int_or_none(url_info.get('filesize')),
  74. } for url_info in urls_info]
  75. self._sort_formats(formats)
  76. return {
  77. 'id': video_id,
  78. 'title': self._og_search_title(webpage),
  79. 'formats': formats,
  80. 'description': self._og_search_description(webpage),
  81. 'thumbnail': self._og_search_thumbnail(webpage),
  82. }