]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nfhsnetwork.py
[crunchyroll:playlist] Force http
[yt-dlp.git] / yt_dlp / extractor / nfhsnetwork.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 from ..utils import (
8 try_get,
9 unified_strdate,
10 unified_timestamp
11 )
12
13
14 class NFHSNetworkIE(InfoExtractor):
15 IE_NAME = 'NFHSNetwork'
16 _VALID_URL = r'https?://(?:www\.)?nfhsnetwork\.com/events/[\w-]+/(?P<id>(?:gam|evt|dd|)?[\w\d]{0,10})'
17 _TESTS = [{
18 # Auto-generated two-team sport (pixellot)
19 'url': 'https://www.nfhsnetwork.com/events/rockford-high-school-rockford-mi/gamcf7e54cfbc',
20 'info_dict': {
21 'id': 'gamcf7e54cfbc',
22 'ext': 'mp4',
23 'title': 'Rockford vs Spring Lake - Girls Varsity Lacrosse 03/27/2021',
24 'uploader': 'MHSAA - Michigan: Rockford High School, Rockford, MI',
25 'uploader_id': 'cd2622cf76',
26 'uploader_url': 'https://www.nfhsnetwork.com/schools/rockford-high-school-rockford-mi',
27 'location': 'Rockford, Michigan',
28 'timestamp': 1616859000,
29 'upload_date': '20210327'
30 },
31 'params': {
32 # m3u8 download
33 'skip_download': True,
34 }
35 }, {
36 # Non-sport activity with description
37 'url': 'https://www.nfhsnetwork.com/events/limon-high-school-limon-co/evt4a30e3726c',
38 'info_dict': {
39 'id': 'evt4a30e3726c',
40 'ext': 'mp4',
41 'title': 'Drama Performance Limon High School vs. Limon High School - 12/13/2020',
42 'description': 'Join the broadcast of the Limon High School Musical Performance at 2 PM.',
43 'uploader': 'CHSAA: Limon High School, Limon, CO',
44 'uploader_id': '7d2d121332',
45 'uploader_url': 'https://www.nfhsnetwork.com/schools/limon-high-school-limon-co',
46 'location': 'Limon, Colorado',
47 'timestamp': 1607893200,
48 'upload_date': '20201213'
49 },
50 'params': {
51 # m3u8 download
52 'skip_download': True,
53 }
54 }, {
55 # Postseason game
56 'url': 'https://www.nfhsnetwork.com/events/nfhs-network-special-events/dd8de71d45',
57 'info_dict': {
58 'id': 'dd8de71d45',
59 'ext': 'mp4',
60 'title': '2015 UA Holiday Classic Tournament: National Division - 12/26/2015',
61 'uploader': 'SoCal Sports Productions',
62 'uploader_id': '063dba0150',
63 'uploader_url': 'https://www.nfhsnetwork.com/affiliates/socal-sports-productions',
64 'location': 'San Diego, California',
65 'timestamp': 1451187000,
66 'upload_date': '20151226'
67 },
68 'params': {
69 # m3u8 download
70 'skip_download': True,
71 }
72 }, {
73 # Video with no broadcasts object
74 'url': 'https://www.nfhsnetwork.com/events/wiaa-wi/9aa2f92f82',
75 'info_dict': {
76 'id': '9aa2f92f82',
77 'ext': 'mp4',
78 'title': 'Competitive Equity - 01/21/2015',
79 'description': 'Committee members discuss points of their research regarding a competitive equity plan',
80 'uploader': 'WIAA - Wisconsin: Wisconsin Interscholastic Athletic Association',
81 'uploader_id': 'a49f7d1002',
82 'uploader_url': 'https://www.nfhsnetwork.com/associations/wiaa-wi',
83 'location': 'Stevens Point, Wisconsin',
84 'timestamp': 1421856000,
85 'upload_date': '20150121'
86 },
87 'params': {
88 # m3u8 download
89 'skip_download': True,
90 }
91 }
92 ]
93
94 def _real_extract(self, url):
95 video_id = self._match_id(url)
96 webpage = self._download_webpage(url, video_id)
97 data = self._download_json(
98 'https://cfunity.nfhsnetwork.com/v2/game_or_event/' + video_id,
99 video_id)
100 publisher = data.get('publishers')[0] # always exists
101 broadcast = (publisher.get('broadcasts') or publisher.get('vods'))[0] # some (older) videos don't have a broadcasts object
102 uploader = publisher.get('formatted_name') or publisher.get('name')
103 uploaderID = publisher.get('publisher_key')
104 pubType = publisher.get('type')
105 uploaderPrefix = (
106 "schools" if pubType == "school"
107 else "associations" if "association" in pubType
108 else "affiliates" if (pubType == "publisher" or pubType == "affiliate")
109 else "schools")
110 uploaderPage = 'https://www.nfhsnetwork.com/%s/%s' % (uploaderPrefix, publisher.get('slug'))
111 location = '%s, %s' % (data.get('city'), data.get('state_name'))
112 description = broadcast.get('description')
113 isLive = broadcast.get('on_air') or broadcast.get('status') == 'on_air' or False
114
115 timestamp = unified_timestamp(data.get('local_start_time'))
116 upload_date = unified_strdate(data.get('local_start_time'))
117
118 title = (
119 self._og_search_title(webpage)
120 or self._html_search_regex(r'<h1 class="sr-hidden">(.*?)</h1>', webpage, 'title'))
121 title = title.split('|')[0].strip()
122
123 video_type = 'broadcasts' if isLive else 'vods'
124 key = broadcast.get('key') if isLive else try_get(publisher, lambda x: x['vods'][0]['key'])
125 m3u8_url = self._download_json(
126 'https://cfunity.nfhsnetwork.com/v2/%s/%s/url' % (video_type, key),
127 video_id).get('video_url')
128
129 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', live=isLive)
130 self._sort_formats(formats, ['res', 'tbr'])
131
132 return {
133 'id': video_id,
134 'title': title,
135 'formats': formats,
136 'description': description,
137 'timestamp': timestamp,
138 'uploader': uploader,
139 'uploader_id': uploaderID,
140 'uploader_url': uploaderPage,
141 'location': location,
142 'upload_date': upload_date,
143 'is_live': isLive
144 }