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.

90 lines
3.4 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'http://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. }, {
  22. 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
  23. 'md5': 'db2a5369238b51f9811ad815b69dc086',
  24. 'info_dict': {
  25. 'id': 'NvqvPeNZsHU',
  26. 'ext': 'mp4',
  27. 'upload_date': '20150816',
  28. 'uploader': 'ABC News (Australia)',
  29. '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',
  30. 'uploader_id': 'NewsOnABC',
  31. 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
  32. },
  33. 'add_ie': ['Youtube'],
  34. }, {
  35. 'url': 'http://www.abc.net.au/news/2015-10-23/nab-lifts-interest-rates-following-westpac-and-cba/6880080',
  36. 'md5': 'b96eee7c9edf4fc5a358a0252881cc1f',
  37. 'info_dict': {
  38. 'id': '6880080',
  39. 'ext': 'mp3',
  40. 'title': 'NAB lifts interest rates, following Westpac and CBA',
  41. 'description': 'md5:f13d8edc81e462fce4a0437c7dc04728',
  42. },
  43. }, {
  44. 'url': 'http://www.abc.net.au/news/2015-10-19/6866214',
  45. 'only_matching': True,
  46. }]
  47. def _real_extract(self, url):
  48. video_id = self._match_id(url)
  49. webpage = self._download_webpage(url, video_id)
  50. mobj = re.search(
  51. r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  52. webpage)
  53. if mobj is None:
  54. raise ExtractorError('Unable to extract video urls')
  55. urls_info = self._parse_json(
  56. mobj.group('json_data'), video_id, transform_source=js_to_json)
  57. if not isinstance(urls_info, list):
  58. urls_info = [urls_info]
  59. if mobj.group('type') == 'YouTube':
  60. return self.playlist_result([
  61. self.url_result(url_info['url']) for url_info in urls_info])
  62. formats = [{
  63. 'url': url_info['url'],
  64. 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none',
  65. 'width': int_or_none(url_info.get('width')),
  66. 'height': int_or_none(url_info.get('height')),
  67. 'tbr': int_or_none(url_info.get('bitrate')),
  68. 'filesize': int_or_none(url_info.get('filesize')),
  69. } for url_info in urls_info]
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'title': self._og_search_title(webpage),
  74. 'formats': formats,
  75. 'description': self._og_search_description(webpage),
  76. 'thumbnail': self._og_search_thumbnail(webpage),
  77. }