Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/nfhsnetwork.py (Python)

Code before:
            'https://cfunity.nfhsnetwork.com/v2/game_or_event/' + video_id,
            video_id)
        publisher = data.get('publishers')[0]  # always exists
        broadcast = (publisher.get('broadcasts') or publisher.get('vods'))[0]  # some (older) videos don't have a broadcasts object
        uploader = publisher.get('formatted_name') or publisher.get('name') or ''
        location = data.get('city') + ', ' + data.get('state_name')
        description = broadcast.get('description') or ''
        isLive = broadcast.get('on_air') or broadcast.get('status') == 'on_air' or False

        timestamp = unified_timestamp(data.get('local_start_time'))
        upload_date = unified_strdate(data.get('local_start_time'))

        title = self._og_search_title(webpage) or self._html_search_regex(r'<h1 class="sr-hidden">(.*?)</h1>', webpage, 'title')
        title = title[:title.find('|') - 1]

        if broadcast.get('status') == 'complete':
            m3u8_url = self._download_json('https://cfunity.nfhsnetwork.com/v2/vods/' + broadcast.get('key') + '/url', video_id)
        else:
            m3u8_url = self._download_json('https://cfunity.nfhsnetwork.com/v2/broadcasts/' + broadcast.get('key') + '/url', video_id)

        m3u8_url = m3u8_url.get('video_url')

        formats = []
        formats.extend(self._extract_m3u8_formats(
            m3u8_url, video_id, 'mp4',
            m3u8_id='hls', fatal=False))

        return {
            'id': video_id,
            'title': title,
            'formats': formats,
            'description': description,
            'timestamp': timestamp,
            'uploader': uploader,
            'location': location,
            'upload_date': upload_date,
            'is_live': isLive
        }


Review comment (bug):
```suggestion
        formats =self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', live=isLive)
        self._sort_formats(formats)
```

1. Since there are no other formats than the ones extracted from the m3u8, failures should be fatal
2. For same reason, no need to create an array and then extend
3. live videos must have `live=True` for the parsing to be done correctly
4. You can modify the sorting method like `self._sort_formats(formats, ['res','tbr'])` for example if you know that certain fields are more reliable. Try to adhere to the default order except for the unreliable fields. See "sorting formats" in readme

> the default order used is: quality,res,fps,codec:vp9.2,size,br,asr,proto,ext,hasaud,source,id. Note that the extractors may override this default order, but they cannot override the user-provided order.

Code after:
            video_id)
        publisher = data.get('publishers')[0]  # always exists
        broadcast = (publisher.get('broadcasts') or publisher.get('vods'))[0]  # some (older) videos don't have a broadcasts object
        uploader = publisher.get('formatted_name') or publisher.get('name')
        uploaderID = publisher.get('publisher_key')
        pubType = publisher.get('type')
        uploaderPrefix = (
            "schools" if pubType == "school"
            else "associations" if "association" in pubType
            else "affiliates" if (pubType == "publisher" or pubType == "affiliate")
            else "schools")
        uploaderPage = 'https://www.nfhsnetwork.com/%s/%s' % (uploaderPrefix, publisher.get('slug'))
        location = '%s, %s' % (data.get('city'), data.get('state_name'))
        description = broadcast.get('description')
        isLive = broadcast.get('on_air') or broadcast.get('status') == 'on_air' or False

        timestamp = unified_timestamp(data.get('local_start_time'))
        upload_date = unified_strdate(data.get('local_start_time'))

        title = (
            self._og_search_title(webpage)
            or self._html_search_regex(r'<h1 class="sr-hidden">(.*?)</h1>', webpage, 'title'))
        title = title.split('|')[0].strip()

        video_type = 'broadcasts' if isLive else 'vods'
        key = broadcast.get('key') if isLive else try_get(publisher, lambda x: x['vods'][0]['key'])
        m3u8_url = self._download_json(
            'https://cfunity.nfhsnetwork.com/v2/%s/%s/url' % (video_type, key),
            video_id).get('video_url')

        formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', live=isLive)
        self._sort_formats(formats, ['res', 'tbr'])

        return {
            'id': video_id,
            'title': title,
            'formats': formats,
            'description': description,
            'timestamp': timestamp,
            'uploader': uploader,
            'uploader_id': uploaderID,
            'uploader_url': uploaderPage,
            'location': location,
            'upload_date': upload_date,
            'is_live': isLive
        }