]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/byutv.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / byutv.py
CommitLineData
6949d810 1from .common import InfoExtractor
df63cafe
S
2from ..utils import (
3 determine_ext,
4 merge_dicts,
5 parse_duration,
6 url_or_none,
7)
6949d810
PH
8
9
10class BYUtvIE(InfoExtractor):
c8be7d5f 11 _VALID_URL = r'https?://(?:www\.)?byutv\.org/(?:watch|player)/(?!event/)(?P<id>[0-9a-f-]+)(?:/(?P<display_id>[^/?#&]+))?'
6d2549fb 12 _TESTS = [{
0db2b275 13 # ooyalaVOD
7009a904 14 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d/studio-c-season-5-episode-5',
6949d810 15 'info_dict': {
c8be7d5f 16 'id': 'ZvanRocTpW-G5_yZFeltTAMv6jxOU9KH',
6d2549fb 17 'display_id': 'studio-c-season-5-episode-5',
6949d810 18 'ext': 'mp4',
7009a904 19 'title': 'Season 5 Episode 5',
c8be7d5f
S
20 'description': 'md5:1d31dc18ef4f075b28f6a65937d22c65',
21 'thumbnail': r're:^https?://.*',
53e06b25 22 'duration': 1486.486,
6949d810 23 },
688c634b 24 'params': {
25 'skip_download': True,
26 },
277c7465 27 'add_ie': ['Ooyala'],
ab116745 28 }, {
0db2b275
S
29 # dvr
30 'url': 'https://www.byutv.org/player/8f1dab9b-b243-47c8-b525-3e2d021a3451/byu-softball-pacific-vs-byu-41219---game-2',
ab116745 31 'info_dict': {
0db2b275
S
32 'id': '8f1dab9b-b243-47c8-b525-3e2d021a3451',
33 'display_id': 'byu-softball-pacific-vs-byu-41219---game-2',
ab116745 34 'ext': 'mp4',
0db2b275
S
35 'title': 'Pacific vs. BYU (4/12/19)',
36 'description': 'md5:1ac7b57cb9a78015910a4834790ce1f3',
37 'duration': 11645,
ab116745
MT
38 },
39 'params': {
40 'skip_download': True
41 },
6d2549fb
S
42 }, {
43 'url': 'http://www.byutv.org/watch/6587b9a3-89d2-42a6-a7f7-fd2f81840a7d',
44 'only_matching': True,
c8be7d5f
S
45 }, {
46 'url': 'https://www.byutv.org/player/27741493-dc83-40b0-8420-e7ae38a2ae98/byu-football-toledo-vs-byu-93016?listid=4fe0fee5-0d3c-4a29-b725-e4948627f472&listindex=0&q=toledo',
47 'only_matching': True,
6d2549fb 48 }]
6949d810
PH
49
50 def _real_extract(self, url):
5ad28e7f 51 mobj = self._match_valid_url(url)
6d2549fb 52 video_id = mobj.group('id')
0db2b275 53 display_id = mobj.group('display_id') or video_id
6949d810 54
df63cafe 55 video = self._download_json(
0db2b275
S
56 'https://api.byutv.org/api3/catalog/getvideosforcontent',
57 display_id, query={
c8be7d5f 58 'contentid': video_id,
6bf9c28b
RA
59 'channel': 'byutv',
60 'x-byutv-context': 'web$US',
c8be7d5f 61 }, headers={
6bf9c28b 62 'x-byutv-context': 'web$US',
c8be7d5f 63 'x-byutv-platformkey': 'xsaaw9c7y5',
ab116745 64 })
6d2549fb 65
df63cafe 66 ep = video.get('ooyalaVOD')
ab116745
MT
67 if ep:
68 return {
69 '_type': 'url_transparent',
70 'ie_key': 'Ooyala',
71 'url': 'ooyala:%s' % ep['providerId'],
72 'id': video_id,
0db2b275 73 'display_id': display_id,
ab116745
MT
74 'title': ep.get('title'),
75 'description': ep.get('description'),
76 'thumbnail': ep.get('imageThumbnail'),
77 }
0db2b275 78
df63cafe
S
79 info = {}
80 formats = []
64a5cf79 81 subtitles = {}
df63cafe
S
82 for format_id, ep in video.items():
83 if not isinstance(ep, dict):
84 continue
85 video_url = url_or_none(ep.get('videoUrl'))
86 if not video_url:
87 continue
88 ext = determine_ext(video_url)
89 if ext == 'm3u8':
64a5cf79 90 m3u8_fmts, m3u8_subs = self._extract_m3u8_formats_and_subtitles(
df63cafe 91 video_url, video_id, 'mp4', entry_protocol='m3u8_native',
64a5cf79
F
92 m3u8_id='hls', fatal=False)
93 formats.extend(m3u8_fmts)
94 subtitles = self._merge_subtitles(subtitles, m3u8_subs)
df63cafe 95 elif ext == 'mpd':
64a5cf79
F
96 mpd_fmts, mpd_subs = self._extract_mpd_formats_and_subtitles(
97 video_url, video_id, mpd_id='dash', fatal=False)
98 formats.extend(mpd_fmts)
99 subtitles = self._merge_subtitles(subtitles, mpd_subs)
df63cafe
S
100 else:
101 formats.append({
102 'url': video_url,
103 'format_id': format_id,
104 })
105 merge_dicts(info, {
106 'title': ep.get('title'),
107 'description': ep.get('description'),
108 'thumbnail': ep.get('imageThumbnail'),
109 'duration': parse_duration(ep.get('length')),
110 })
df63cafe
S
111
112 return merge_dicts(info, {
0db2b275
S
113 'id': video_id,
114 'display_id': display_id,
df63cafe 115 'title': display_id,
0db2b275 116 'formats': formats,
64a5cf79 117 'subtitles': subtitles,
df63cafe 118 })