ninenews.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from .brightcove import BrightcoveNewIE
  2. from .common import InfoExtractor
  3. from ..utils import ExtractorError
  4. from ..utils.traversal import traverse_obj
  5. class NineNewsIE(InfoExtractor):
  6. IE_NAME = '9News'
  7. _VALID_URL = r'https?://(?:www\.)?9news\.com\.au/(?:[\w-]+/){2,3}(?P<id>[\w-]+)/?(?:$|[?#])'
  8. _TESTS = [{
  9. 'url': 'https://www.9news.com.au/videos/national/fair-trading-pulls-dozens-of-toys-from-shelves/clqgc7dvj000y0jnvfism0w5m',
  10. 'md5': 'd1a65b2e9d126e5feb9bc5cb96e62c80',
  11. 'info_dict': {
  12. 'id': '6343717246112',
  13. 'ext': 'mp4',
  14. 'title': 'Fair Trading pulls dozens of toys from shelves',
  15. 'description': 'Fair Trading Australia have been forced to pull dozens of toys from shelves over hazard fears.',
  16. 'thumbnail': 'md5:bdbe44294e2323b762d97acf8843f66c',
  17. 'duration': 93.44,
  18. 'timestamp': 1703231748,
  19. 'upload_date': '20231222',
  20. 'uploader_id': '664969388001',
  21. 'tags': ['networkclip', 'aunews_aunationalninenews', 'christmas presents', 'toys', 'fair trading', 'au_news'],
  22. },
  23. }, {
  24. 'url': 'https://www.9news.com.au/world/tape-reveals-donald-trump-pressured-michigan-officials-not-to-certify-2020-vote-a-new-report-says/0b8b880e-7d3c-41b9-b2bd-55bc7e492259',
  25. 'md5': 'a885c44d20898c3e70e9a53e8188cea1',
  26. 'info_dict': {
  27. 'id': '6343587450112',
  28. 'ext': 'mp4',
  29. 'title': 'Trump found ineligible to run for president by state court',
  30. 'description': 'md5:40e6e7db7a4ac6be0e960569a5af6066',
  31. 'thumbnail': 'md5:3e132c48c186039fd06c10787de9bff2',
  32. 'duration': 104.64,
  33. 'timestamp': 1703058034,
  34. 'upload_date': '20231220',
  35. 'uploader_id': '664969388001',
  36. 'tags': ['networkclip', 'aunews_aunationalninenews', 'ineligible', 'presidential candidate', 'donald trump', 'au_news'],
  37. },
  38. }, {
  39. 'url': 'https://www.9news.com.au/national/outrage-as-parents-banned-from-giving-gifts-to-kindergarten-teachers/e19b49d4-a1a4-4533-9089-6e10e2d9386a',
  40. 'info_dict': {
  41. 'id': '6343716797112',
  42. 'ext': 'mp4',
  43. 'title': 'Outrage as parents banned from giving gifts to kindergarten teachers',
  44. 'description': 'md5:7a8b0ed2f9e08875fd9a3e86e462bc46',
  45. 'thumbnail': 'md5:5ee4d66717bdd0dee9fc9a705ef041b8',
  46. 'duration': 91.307,
  47. 'timestamp': 1703229584,
  48. 'upload_date': '20231222',
  49. 'uploader_id': '664969388001',
  50. 'tags': ['networkclip', 'aunews_aunationalninenews', 'presents', 'teachers', 'kindergarten', 'au_news'],
  51. },
  52. }]
  53. def _real_extract(self, url):
  54. article_id = self._match_id(url)
  55. webpage = self._download_webpage(url, article_id)
  56. initial_state = self._search_json(
  57. r'var\s+__INITIAL_STATE__\s*=', webpage, 'initial state', article_id)
  58. video_id = traverse_obj(
  59. initial_state, ('videoIndex', 'currentVideo', 'brightcoveId', {str}),
  60. ('article', ..., 'media', lambda _, v: v['type'] == 'video', 'urn', {str}), get_all=False)
  61. account = traverse_obj(initial_state, (
  62. 'videoIndex', 'config', (None, 'video'), 'account', {str}), get_all=False)
  63. if not video_id or not account:
  64. raise ExtractorError('Unable to get the required video data')
  65. return self.url_result(
  66. f'https://players.brightcove.net/{account}/default_default/index.html?videoId={video_id}',
  67. BrightcoveNewIE, video_id)