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

Code before:
import re

from .common import InfoExtractor
from ..utils import (
    clean_html,
    remove_end,
    str_or_none,
    traverse_obj,
    urljoin,
)


class MediaStreamBaseIE(InfoExtractor):
    _EMBED_BASE_URL = 'https://mdstrm.com/embed'
    _BASE_URL_RE = r'https?://mdstrm\.com/(?:embed|live-stream)'

    def _extract_mediastream_urls(self, webpage):
        yield from traverse_obj(list(self._yield_json_ld(webpage, None)), (
            lambda _, v: v['@type'] == 'VideoObject', 'embedUrl',
            {lambda x: x if re.match(rf'{self._BASE_URL_RE}/\w+', x) else None}))

        for mobj in re.finditer(r'<script[^>]+>[^>]*playerMdStream\.mdstreamVideo\(\s*[\'"](?P<video_id>\w+)', webpage):
            yield f'{self._EMBED_BASE_URL}/{mobj.group("video_id")}'

        yield from re.findall(
            rf'<iframe[^>]+\bsrc="({self._BASE_URL_RE}/\w+)', webpage)

        for mobj in re.finditer(
            r'''(?x)
                <(?:div|ps-mediastream)[^>]+
                class\s*=\s*"[^"]*MediaStreamVideoPlayer[^"]*"[^>]+
                data-video-id\s*=\s*"(?P<video_id>\w+)\s*"
                (?:\s*data-video-type\s*=\s*"(?P<video_type>[^"]+))?
                ''', webpage):

            video_type = 'live-stream' if mobj.group('video_type') == 'live' else 'embed'
            yield f'https://mdstrm.com/{video_type}/{mobj.group("video_id")}'


class MediaStreamIE(MediaStreamBaseIE):
    _VALID_URL = MediaStreamBaseIE._BASE_URL_RE + r'/(?P<id>\w+)'

Review comment (refactor):
If you can make this a `classmethod`, then it can be defined as `MediaStreamIE_extract_embed_urls`. Base-class and _extract_from_webpage aren't needed then.

Code after:
import re

from .common import InfoExtractor
from ..utils import (
    clean_html,
    remove_end,
    traverse_obj,
    urljoin,
)


class MediaStreamBaseIE(InfoExtractor):
    _EMBED_BASE_URL = 'https://mdstrm.com/embed'
    _BASE_URL_RE = r'https?://mdstrm\.com/(?:embed|live-stream)'

    def _extract_mediastream_urls(self, webpage):
        yield from traverse_obj(list(self._yield_json_ld(webpage, None)), (
            lambda _, v: v['@type'] == 'VideoObject', ('embedUrl', 'contentUrl'),
            {lambda x: x if re.match(rf'{self._BASE_URL_RE}/\w+', x) else None}))

        for mobj in re.finditer(r'<script[^>]+>[^>]*playerMdStream\.mdstreamVideo\(\s*[\'"](?P<video_id>\w+)', webpage):
            yield f'{self._EMBED_BASE_URL}/{mobj.group("video_id")}'

        yield from re.findall(
            rf'<iframe[^>]+\bsrc="({self._BASE_URL_RE}/\w+)', webpage)

        for mobj in re.finditer(
            r'''(?x)
                <(?:div|ps-mediastream)[^>]+
                (class="[^"]*MediaStreamVideoPlayer)[^"]*"[^>]+
                data-video-id="(?P<video_id>\w+)"
                (?:\s*data-video-type="(?P<video_type>[^"]+))?
                (?:[^>]*>\s*<div[^>]+\1[^"]*"[^>]+data-mediastream=["\'][^>]+
                    https://mdstrm\.com/(?P<live>live-stream))?
                ''', webpage):

            video_type = 'live-stream' if mobj.group('video_type') == 'live' or mobj.group('live') else 'embed'
            yield f'https://mdstrm.com/{video_type}/{mobj.group("video_id")}'


class MediaStreamIE(MediaStreamBaseIE):