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