]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/abcnews.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / abcnews.py
CommitLineData
055f0d3d
YCH
1from .amp import AMPIE
2from .common import InfoExtractor
2181983a 3from ..utils import (
4 parse_duration,
5 parse_iso8601,
6 try_get,
7)
055f0d3d
YCH
8
9
10class AbcNewsVideoIE(AMPIE):
11 IE_NAME = 'abcnews:video'
bc22df29 12 _VALID_URL = r'''(?x)
164fcbfe 13 https?://
164fcbfe 14 (?:
16d3672a
RA
15 abcnews\.go\.com/
16 (?:
2181983a 17 (?:[^/]+/)*video/(?P<display_id>[0-9a-z-]+)-|
18 video/(?:embed|itemfeed)\?.*?\bid=
16d3672a
RA
19 )|
20 fivethirtyeight\.abcnews\.go\.com/video/embed/\d+/
164fcbfe
S
21 )
22 (?P<id>\d+)
23 '''
055f0d3d
YCH
24
25 _TESTS = [{
26 'url': 'http://abcnews.go.com/ThisWeek/video/week-exclusive-irans-foreign-minister-zarif-20411932',
27 'info_dict': {
28 'id': '20411932',
29 'ext': 'mp4',
30 'display_id': 'week-exclusive-irans-foreign-minister-zarif',
31 'title': '\'This Week\' Exclusive: Iran\'s Foreign Minister Zarif',
32 'description': 'George Stephanopoulos goes one-on-one with Iranian Foreign Minister Dr. Javad Zarif.',
33 'duration': 180,
ec85ded8 34 'thumbnail': r're:^https?://.*\.jpg$',
2181983a 35 'timestamp': 1380454200,
36 'upload_date': '20130929',
055f0d3d
YCH
37 },
38 'params': {
39 # m3u8 download
40 'skip_download': True,
41 },
bc22df29
TF
42 }, {
43 'url': 'http://abcnews.go.com/video/embed?id=46979033',
164fcbfe 44 'only_matching': True,
055f0d3d
YCH
45 }, {
46 'url': 'http://abcnews.go.com/2020/video/2020-husband-stands-teacher-jail-student-affairs-26119478',
47 'only_matching': True,
2181983a 48 }, {
49 'url': 'http://abcnews.go.com/video/itemfeed?id=46979033',
50 'only_matching': True,
51 }, {
52 'url': 'https://abcnews.go.com/GMA/News/video/history-christmas-story-67894761',
53 'only_matching': True,
055f0d3d
YCH
54 }]
55
56 def _real_extract(self, url):
5ad28e7f 57 mobj = self._match_valid_url(url)
055f0d3d
YCH
58 display_id = mobj.group('display_id')
59 video_id = mobj.group('id')
60 info_dict = self._extract_feed_info(
add96eb9 61 f'http://abcnews.go.com/video/itemfeed?id={video_id}')
055f0d3d
YCH
62 info_dict.update({
63 'id': video_id,
64 'display_id': display_id,
65 })
66 return info_dict
67
68
69class AbcNewsIE(InfoExtractor):
70 IE_NAME = 'abcnews'
25042f73 71 _VALID_URL = r'https?://abcnews\.go\.com/(?:[^/]+/)+(?P<display_id>[0-9a-z-]+)/story\?id=(?P<id>\d+)'
055f0d3d
YCH
72
73 _TESTS = [{
2181983a 74 # Youtube Embeds
75 'url': 'https://abcnews.go.com/Entertainment/peter-billingsley-child-actor-christmas-story-hollywood-power/story?id=51286501',
055f0d3d 76 'info_dict': {
2181983a 77 'id': '51286501',
78 'title': "Peter Billingsley: From child actor in 'A Christmas Story' to Hollywood power player",
79 'description': 'Billingsley went from a child actor to Hollywood power player.',
055f0d3d 80 },
2181983a 81 'playlist_count': 5,
055f0d3d
YCH
82 }, {
83 'url': 'http://abcnews.go.com/Entertainment/justin-timberlake-performs-stop-feeling-eurovision-2016/story?id=39125818',
84 'info_dict': {
2d17c631 85 'id': '38897857',
055f0d3d 86 'ext': 'mp4',
055f0d3d
YCH
87 'title': 'Justin Timberlake Drops Hints For Secret Single',
88 'description': 'Lara Spencer reports the buzziest stories of the day in "GMA" Pop News.',
2181983a 89 'upload_date': '20160505',
90 'timestamp': 1462442280,
055f0d3d
YCH
91 },
92 'params': {
93 # m3u8 download
94 'skip_download': True,
95 # The embedded YouTube video is blocked due to copyright issues
96 'playlist_items': '1',
97 },
98 'add_ie': ['AbcNewsVideo'],
99 }, {
100 'url': 'http://abcnews.go.com/Technology/exclusive-apple-ceo-tim-cook-iphone-cracking-software/story?id=37173343',
101 'only_matching': True,
2181983a 102 }, {
103 # inline.type == 'video'
104 'url': 'http://abcnews.go.com/Technology/exclusive-apple-ceo-tim-cook-iphone-cracking-software/story?id=37173343',
105 'only_matching': True,
055f0d3d
YCH
106 }]
107
108 def _real_extract(self, url):
2181983a 109 story_id = self._match_id(url)
110 webpage = self._download_webpage(url, story_id)
111 story = self._parse_json(self._search_regex(
112 r"window\['__abcnews__'\]\s*=\s*({.+?});",
113 webpage, 'data'), story_id)['page']['content']['story']['everscroll'][0]
114 article_contents = story.get('articleContents') or {}
115
116 def entries():
117 featured_video = story.get('featuredVideo') or {}
118 feed = try_get(featured_video, lambda x: x['video']['feed'])
119 if feed:
120 yield {
121 '_type': 'url',
122 'id': featured_video.get('id'),
123 'title': featured_video.get('name'),
124 'url': feed,
125 'thumbnail': featured_video.get('images'),
126 'description': featured_video.get('description'),
127 'timestamp': parse_iso8601(featured_video.get('uploadDate')),
128 'duration': parse_duration(featured_video.get('duration')),
129 'ie_key': AbcNewsVideoIE.ie_key(),
130 }
131
132 for inline in (article_contents.get('inlines') or []):
133 inline_type = inline.get('type')
134 if inline_type == 'iframe':
135 iframe_url = try_get(inline, lambda x: x['attrs']['src'])
136 if iframe_url:
137 yield self.url_result(iframe_url)
138 elif inline_type == 'video':
139 video_id = inline.get('id')
140 if video_id:
141 yield {
142 '_type': 'url',
143 'id': video_id,
144 'url': 'http://abcnews.go.com/video/embed?id=' + video_id,
145 'thumbnail': inline.get('imgSrc') or inline.get('imgDefault'),
146 'description': inline.get('description'),
147 'duration': parse_duration(inline.get('duration')),
148 'ie_key': AbcNewsVideoIE.ie_key(),
149 }
150
151 return self.playlist_result(
152 entries(), story_id, article_contents.get('headline'),
153 article_contents.get('subHead'))