abc.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. )
  8. class ABCIE(InfoExtractor):
  9. IE_NAME = 'abc.net.au'
  10. _VALID_URL = r'http://www\.abc\.net\.au/news/[^/]+/[^/]+/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334',
  13. 'md5': 'cb3dd03b18455a661071ee1e28344d9f',
  14. 'info_dict': {
  15. 'id': '5868334',
  16. 'ext': 'mp4',
  17. 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone',
  18. 'description': 'md5:809ad29c67a05f54eb41f2a105693a67',
  19. },
  20. }, {
  21. 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
  22. 'md5': 'db2a5369238b51f9811ad815b69dc086',
  23. 'info_dict': {
  24. 'id': 'NvqvPeNZsHU',
  25. 'ext': 'mp4',
  26. 'upload_date': '20150816',
  27. 'uploader': 'ABC News (Australia)',
  28. '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',
  29. 'uploader_id': 'NewsOnABC',
  30. 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
  31. },
  32. 'add_ie': ['Youtube'],
  33. }]
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(url, video_id)
  37. mobj = re.search(
  38. r'inline(?P<type>Video|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
  39. webpage)
  40. if mobj is None:
  41. raise ExtractorError('Unable to extract video urls')
  42. urls_info = self._parse_json(
  43. mobj.group('json_data'), video_id, transform_source=js_to_json)
  44. if not isinstance(urls_info, list):
  45. urls_info = [urls_info]
  46. if mobj.group('type') == 'YouTube':
  47. return self.playlist_result([
  48. self.url_result(url_info['url']) for url_info in urls_info])
  49. formats = [{
  50. 'url': url_info['url'],
  51. 'width': int(url_info['width']),
  52. 'height': int(url_info['height']),
  53. 'tbr': int(url_info['bitrate']),
  54. 'filesize': int(url_info['filesize']),
  55. } for url_info in urls_info]
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'title': self._og_search_title(webpage),
  60. 'formats': formats,
  61. 'description': self._og_search_description(webpage),
  62. 'thumbnail': self._og_search_thumbnail(webpage),
  63. }