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.

76 lines
2.8 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/[^/]+/[^/]+/(?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. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(url, video_id)
  38. mobj = re.search(
  39. r'inline(?P<type>Video|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  40. webpage)
  41. if mobj is None:
  42. raise ExtractorError('Unable to extract video urls')
  43. urls_info = self._parse_json(
  44. mobj.group('json_data'), video_id, transform_source=js_to_json)
  45. if not isinstance(urls_info, list):
  46. urls_info = [urls_info]
  47. if mobj.group('type') == 'YouTube':
  48. return self.playlist_result([
  49. self.url_result(url_info['url']) for url_info in urls_info])
  50. formats = [{
  51. 'url': url_info['url'],
  52. 'width': int_or_none(url_info.get('width')),
  53. 'height': int_or_none(url_info.get('height')),
  54. 'tbr': int_or_none(url_info.get('bitrate')),
  55. 'filesize': int_or_none(url_info.get('filesize')),
  56. } for url_info in urls_info]
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'title': self._og_search_title(webpage),
  61. 'formats': formats,
  62. 'description': self._og_search_description(webpage),
  63. 'thumbnail': self._og_search_thumbnail(webpage),
  64. }