]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/abcotvs.py
Reject entire playlists faster with `--match-filter`
[yt-dlp.git] / yt_dlp / extractor / abcotvs.py
CommitLineData
fdb2ed74 1from .common import InfoExtractor
88a7a908 2from ..compat import compat_str
0b36a962 3from ..utils import (
88a7a908 4 dict_get,
0b36a962 5 int_or_none,
88a7a908 6 try_get,
0b36a962 7)
fdb2ed74
S
8
9
0b36a962
RA
10class ABCOTVSIE(InfoExtractor):
11 IE_NAME = 'abcotvs'
ad0e2b33 12 IE_DESC = 'ABC Owned Television Stations'
88a7a908 13 _VALID_URL = r'https?://(?P<site>abc(?:7(?:news|ny|chicago)?|11|13|30)|6abc)\.com(?:(?:/[^/]+)*/(?P<display_id>[^/]+))?/(?P<id>\d+)'
fdb2ed74
S
14 _TESTS = [
15 {
16 'url': 'http://abc7news.com/entertainment/east-bay-museum-celebrates-vintage-synthesizers/472581/',
17 'info_dict': {
88a7a908 18 'id': '472548',
fdb2ed74
S
19 'display_id': 'east-bay-museum-celebrates-vintage-synthesizers',
20 'ext': 'mp4',
88a7a908 21 'title': 'East Bay museum celebrates synthesized music',
6ce79d7a 22 'description': 'md5:24ed2bd527096ec2a5c67b9d5a9005f3',
ec85ded8 23 'thumbnail': r're:^https?://.*\.jpg$',
88a7a908 24 'timestamp': 1421118520,
fdb2ed74 25 'upload_date': '20150113',
fdb2ed74
S
26 },
27 'params': {
28 # m3u8 download
29 'skip_download': True,
30 },
31 },
32 {
33 'url': 'http://abc7news.com/472581',
34 'only_matching': True,
35 },
88a7a908
RA
36 {
37 'url': 'https://6abc.com/man-75-killed-after-being-struck-by-vehicle-in-chester/5725182/',
38 'only_matching': True,
39 },
fdb2ed74 40 ]
88a7a908
RA
41 _SITE_MAP = {
42 '6abc': 'wpvi',
43 'abc11': 'wtvd',
44 'abc13': 'ktrk',
45 'abc30': 'kfsn',
46 'abc7': 'kabc',
47 'abc7chicago': 'wls',
48 'abc7news': 'kgo',
49 'abc7ny': 'wabc',
50 }
fdb2ed74
S
51
52 def _real_extract(self, url):
5ad28e7f 53 site, display_id, video_id = self._match_valid_url(url).groups()
88a7a908
RA
54 display_id = display_id or video_id
55 station = self._SITE_MAP[site]
fdb2ed74 56
88a7a908
RA
57 data = self._download_json(
58 'https://api.abcotvs.com/v2/content', display_id, query={
59 'id': video_id,
60 'key': 'otv.web.%s.story' % station,
61 'station': station,
62 })['data']
63 video = try_get(data, lambda x: x['featuredMedia']['video'], dict) or data
64 video_id = compat_str(dict_get(video, ('id', 'publishedKey'), video_id))
65 title = video.get('title') or video['linkText']
fdb2ed74 66
88a7a908
RA
67 formats = []
68 m3u8_url = video.get('m3u8')
69 if m3u8_url:
70 formats = self._extract_m3u8_formats(
71 video['m3u8'].split('?')[0], display_id, 'mp4', m3u8_id='hls', fatal=False)
72 mp4_url = video.get('mp4')
73 if mp4_url:
74 formats.append({
75 'abr': 128,
76 'format_id': 'https',
77 'height': 360,
78 'url': mp4_url,
79 'width': 640,
80 })
19dbaeec 81 self._sort_formats(formats)
fdb2ed74 82
88a7a908 83 image = video.get('image') or {}
fdb2ed74
S
84
85 return {
86 'id': video_id,
87 'display_id': display_id,
88 'title': title,
88a7a908
RA
89 'description': dict_get(video, ('description', 'caption'), try_get(video, lambda x: x['meta']['description'])),
90 'thumbnail': dict_get(image, ('source', 'dynamicSource')),
91 'timestamp': int_or_none(video.get('date')),
92 'duration': int_or_none(video.get('length')),
fdb2ed74
S
93 'formats': formats,
94 }
0b36a962
RA
95
96
97class ABCOTVSClipsIE(InfoExtractor):
98 IE_NAME = 'abcotvs:clips'
99 _VALID_URL = r'https?://clips\.abcotvs\.com/(?:[^/]+/)*video/(?P<id>\d+)'
100 _TEST = {
101 'url': 'https://clips.abcotvs.com/kabc/video/214814',
102 'info_dict': {
103 'id': '214814',
104 'ext': 'mp4',
105 'title': 'SpaceX launch pad explosion destroys rocket, satellite',
106 'description': 'md5:9f186e5ad8f490f65409965ee9c7be1b',
107 'upload_date': '20160901',
108 'timestamp': 1472756695,
109 },
110 'params': {
111 # m3u8 download
112 'skip_download': True,
113 },
114 }
115
116 def _real_extract(self, url):
117 video_id = self._match_id(url)
118 video_data = self._download_json('https://clips.abcotvs.com/vogo/video/getByIds?ids=' + video_id, video_id)['results'][0]
119 title = video_data['title']
120 formats = self._extract_m3u8_formats(
121 video_data['videoURL'].split('?')[0], video_id, 'mp4')
122 self._sort_formats(formats)
123
124 return {
125 'id': video_id,
126 'title': title,
127 'description': video_data.get('description'),
128 'thumbnail': video_data.get('thumbnailURL'),
129 'duration': int_or_none(video_data.get('duration')),
130 'timestamp': int_or_none(video_data.get('pubDate')),
131 'formats': formats,
132 }