abc.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/[^/]+/[^/]+/(?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. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. webpage = self._download_webpage(url, video_id)
  47. mobj = re.search(
  48. r'inline(?P<type>Video|Audio|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  49. webpage)
  50. if mobj is None:
  51. raise ExtractorError('Unable to extract video urls')
  52. urls_info = self._parse_json(
  53. mobj.group('json_data'), video_id, transform_source=js_to_json)
  54. if not isinstance(urls_info, list):
  55. urls_info = [urls_info]
  56. if mobj.group('type') == 'YouTube':
  57. return self.playlist_result([
  58. self.url_result(url_info['url']) for url_info in urls_info])
  59. formats = [{
  60. 'url': url_info['url'],
  61. 'vcodec': url_info.get('codec') if mobj.group('type') == 'Video' else 'none',
  62. 'width': int_or_none(url_info.get('width')),
  63. 'height': int_or_none(url_info.get('height')),
  64. 'tbr': int_or_none(url_info.get('bitrate')),
  65. 'filesize': int_or_none(url_info.get('filesize')),
  66. } for url_info in urls_info]
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'title': self._og_search_title(webpage),
  71. 'formats': formats,
  72. 'description': self._og_search_description(webpage),
  73. 'thumbnail': self._og_search_thumbnail(webpage),
  74. }