]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/abcotvs.py
[fragments] Pad fragments before decrypting (#1298)
[yt-dlp.git] / yt_dlp / extractor / abcotvs.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import (
8 dict_get,
9 int_or_none,
10 try_get,
11 )
12
13
14 class ABCOTVSIE(InfoExtractor):
15 IE_NAME = 'abcotvs'
16 IE_DESC = 'ABC Owned Television Stations'
17 _VALID_URL = r'https?://(?P<site>abc(?:7(?:news|ny|chicago)?|11|13|30)|6abc)\.com(?:(?:/[^/]+)*/(?P<display_id>[^/]+))?/(?P<id>\d+)'
18 _TESTS = [
19 {
20 'url': 'http://abc7news.com/entertainment/east-bay-museum-celebrates-vintage-synthesizers/472581/',
21 'info_dict': {
22 'id': '472548',
23 'display_id': 'east-bay-museum-celebrates-vintage-synthesizers',
24 'ext': 'mp4',
25 'title': 'East Bay museum celebrates synthesized music',
26 'description': 'md5:24ed2bd527096ec2a5c67b9d5a9005f3',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'timestamp': 1421118520,
29 'upload_date': '20150113',
30 },
31 'params': {
32 # m3u8 download
33 'skip_download': True,
34 },
35 },
36 {
37 'url': 'http://abc7news.com/472581',
38 'only_matching': True,
39 },
40 {
41 'url': 'https://6abc.com/man-75-killed-after-being-struck-by-vehicle-in-chester/5725182/',
42 'only_matching': True,
43 },
44 ]
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 }
55
56 def _real_extract(self, url):
57 site, display_id, video_id = self._match_valid_url(url).groups()
58 display_id = display_id or video_id
59 station = self._SITE_MAP[site]
60
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']
70
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 })
85 self._sort_formats(formats)
86
87 image = video.get('image') or {}
88
89 return {
90 'id': video_id,
91 'display_id': display_id,
92 'title': title,
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')),
97 'formats': formats,
98 }
99
100
101 class 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 }