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

Code before:
        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,
            'location': location,
            'upload_date': upload_date,
            'is_live': isLive
        }


Review comment (refactor):
Since the extraction cannot proceed anyway without a `key`, you can use `broadcast['key'] if isLive else publisher['vods'][0]['key']`

`.get` and `try_get` are mandatory only when the the obtained values are not essential for downloading the video. Ofc, there is no harm in using `try_get` anyway. So I am not asking to change this, just letting you know for the future.

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
        }