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