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

Code before:
import re
from .common import InfoExtractor
from ..utils import (
    determine_ext,
    extract_attributes,
    int_or_none,
    url_or_none,
)


class DLFBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?deutschlandfunk\.de/'
    _BUTTON_REGEX = r'(<button[^>]+alt="Anhören"[^>]+data-audio-diraid[^>]*>)'

    def _parse_button_attrs(self, button, id=None):
        attrs = extract_attributes(button)
        id = id or attrs['data-audio-diraid']

        # Note: DLF's mp3 recordings are in two distinct locations on the web:
        # A direct download location, https://download.deutschlandfunk.de/ ... .mp3
        # A stream with playback controls, https://ondemand-mp3.dradio.de/ ... .mp3
        url = url_or_none(
            attrs.get('data-audio-download-src')
            or attrs.get('data-audio')
            or attrs.get('data-audioreference')
            or attrs['data-audio-src'])

        return {
            'id': id,
            'title': (
                attrs.get('data-audiotitle')
                or attrs.get('data-audio-title')
                or attrs.get('data-audio-download-tracking-title')),
            'url': url,
            'formats': (
                self._extract_m3u8_formats(url, id) if determine_ext(url) == 'm3u8'
                else None),
            'duration': int_or_none(
                attrs.get('data-audioduration')
                or attrs.get('data-audio-duration')),
            'thumbnail': attrs.get('data-audioimage'),
            'uploader': attrs.get('data-audio-producer'),
            'series': attrs.get('data-audio-series'),
            'channel': attrs.get('data-audio-origin-site-name'),
        }


class DLFIE(DLFBaseIE):
    _VALID_URL = DLFBaseIE._VALID_URL_BASE + r'(?:\w+-)+(?P<id>[^-]*\d[^-]*)-100\.html'


Review comment (suggestion):
imo we can use an `ext` var to make things easier below
```suggestion
        ext = determine_ext(url)

```

Code after:
import re

from .common import InfoExtractor
from ..utils import (
    determine_ext,
    extract_attributes,
    int_or_none,
    traverse_obj,
    url_or_none,
)


class DLFBaseIE(InfoExtractor):
    _VALID_URL_BASE = r'https?://(?:www\.)?deutschlandfunk\.de/'
    _BUTTON_REGEX = r'(<button[^>]+alt="Anhören"[^>]+data-audio-diraid[^>]*>)'

    def _parse_button_attrs(self, button, audio_id=None):
        attrs = extract_attributes(button)
        audio_id = audio_id or attrs['data-audio-diraid']

        url = traverse_obj(
            attrs, 'data-audio-download-src', 'data-audio', 'data-audioreference',
            'data-audio-src', expected_type=url_or_none)
        ext = determine_ext(url)

        return {
            'id': audio_id,
            'extractor_key': DLFIE.ie_key(),
            'extractor': DLFIE.IE_NAME,
            **traverse_obj(attrs, {
                'title': (('data-audiotitle', 'data-audio-title', 'data-audio-download-tracking-title'), {str}),
                'duration': (('data-audioduration', 'data-audio-duration'), {int_or_none}),
                'thumbnail': ('data-audioimage', {url_or_none}),
                'uploader': 'data-audio-producer',
                'series': 'data-audio-series',
                'channel': 'data-audio-origin-site-name',
                'webpage_url': ('data-audio-download-tracking-path', {url_or_none}),
            }, get_all=False),
            'formats': (self._extract_m3u8_formats(url, audio_id, fatal=False)
                        if ext == 'm3u8' else [{'url': url, 'ext': ext, 'vcodec': 'none'}])
        }


class DLFIE(DLFBaseIE):
    IE_NAME = 'dlf'
    _VALID_URL = DLFBaseIE._VALID_URL_BASE + r'[\w-]+-dlf-(?P<id>[\da-f]{8})-100\.html'
    _TESTS = [
        # Audio as an HLS stream
        {
            'url': 'https://www.deutschlandfunk.de/tanz-der-saiteninstrumente-das-wild-strings-trio-aus-slowenien-dlf-03a3eb19-100.html',