]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/abc.py
[abc] Support YouTube embeds (fixes #6595)
[yt-dlp.git] / youtube_dl / extractor / abc.py
CommitLineData
64ce58db
JMF
1from __future__ import unicode_literals
2
3import re
64ce58db
JMF
4
5from .common import InfoExtractor
17a64763
YCH
6from ..utils import (
7 ExtractorError,
8 js_to_json,
9)
64ce58db
JMF
10
11
12class ABCIE(InfoExtractor):
13 IE_NAME = 'abc.net.au'
14 _VALID_URL = r'http://www\.abc\.net\.au/news/[^/]+/[^/]+/(?P<id>\d+)'
15
17a64763 16 _TESTS = [{
732c848c
MK
17 'url': 'http://www.abc.net.au/news/2014-11-05/australia-to-staff-ebola-treatment-centre-in-sierra-leone/5868334',
18 'md5': 'cb3dd03b18455a661071ee1e28344d9f',
64ce58db 19 'info_dict': {
732c848c 20 'id': '5868334',
64ce58db 21 'ext': 'mp4',
732c848c
MK
22 'title': 'Australia to help staff Ebola treatment centre in Sierra Leone',
23 'description': 'md5:809ad29c67a05f54eb41f2a105693a67',
64ce58db 24 },
17a64763
YCH
25 }, {
26 'url': 'http://www.abc.net.au/news/2015-08-17/warren-entsch-introduces-same-sex-marriage-bill/6702326',
27 'md5': 'db2a5369238b51f9811ad815b69dc086',
28 'info_dict': {
29 'id': 'NvqvPeNZsHU',
30 'ext': 'mp4',
31 'upload_date': '20150816',
32 'uploader': 'ABC News (Australia)',
33 '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',
34 'uploader_id': 'NewsOnABC',
35 'title': 'Marriage Equality: Warren Entsch introduces same sex marriage bill',
36 },
37 'add_ie': ['Youtube'],
38 }]
64ce58db
JMF
39
40 def _real_extract(self, url):
ed9266db 41 video_id = self._match_id(url)
64ce58db
JMF
42 webpage = self._download_webpage(url, video_id)
43
17a64763
YCH
44 mobj = re.search(
45 r'inline(?P<type>Video|YouTube)Data\.push\((?P<json_data>[^)]+)\);',
46 webpage)
47 if mobj is None:
48 raise ExtractorError('Unable to extract video urls')
49
50 urls_info = self._parse_json(
51 mobj.group('json_data'), video_id, transform_source=js_to_json)
52
53 if not isinstance(urls_info, list):
54 urls_info = [urls_info]
55
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
64ce58db
JMF
60 formats = [{
61 'url': url_info['url'],
62 'width': int(url_info['width']),
63 'height': int(url_info['height']),
64 'tbr': int(url_info['bitrate']),
65 'filesize': int(url_info['filesize']),
66 } for url_info in urls_info]
67 self._sort_formats(formats)
68
69 return {
70 'id': video_id,
71 'title': self._og_search_title(webpage),
72 'formats': formats,
73 'description': self._og_search_description(webpage),
74 'thumbnail': self._og_search_thumbnail(webpage),
75 }