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'),

Review comment (refactor):
Avoid using names of built-ins (`id`)
You can rename the var to whatever you want, but for the sake of this review I will be using `id_` throughout
```suggestion
    def _parse_button_attrs(self, button, id_=None):
        attrs = extract_attributes(button)
        id_ = id_ or attrs['data-audio-diraid']
```

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'}])
        }