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

Code before:
import re

from .common import InfoExtractor
from ..utils import (
    float_or_none,
    int_or_none,
    orderedSet,
    parse_iso8601,
    parse_qs,
    parse_resolution,
    str_or_none,
    traverse_obj,
    url_or_none,
)


class EpidemicSoundIE(InfoExtractor):
    # set an attribute to indicate if it's a sound effect or a track based on this regex (r'https?://(?:www\.)?epidemicsound\.com/sound-effects/tracks/(?P<id>[0-9a-zA-Z-]+)')
    _IS_SFX = False
    _SFX_REGEX = re.compile(r'https?://(?:www\.)?epidemicsound\.com/sound-effects/tracks/(?P<id>[0-9a-zA-Z-]+)')
    _VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/(?:sound-effects/tracks|track)/(?P<id>[0-9a-zA-Z-]+)'
    _TESTS = [{
        'url': 'https://www.epidemicsound.com/track/yFfQVRpSPz/',
        'md5': 'd98ff2ddb49e8acab9716541cbc9dfac',
        'info_dict': {
            'id': '45014',
            'display_id': 'yFfQVRpSPz',
            'ext': 'mp3',
            'title': 'Door Knock Door 1',
            'alt_title': 'Door Knock Door 1',
            'tags': ['foley', 'door', 'knock', 'glass', 'window', 'glass door knock'],
            'categories': ['Misc. Door'],
            'duration': 1,
            'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/default-sfx/3000x3000.jpg',
            'timestamp': 1415320353,
            'upload_date': '20141107',
        },
    }, {
        'url': 'https://www.epidemicsound.com/track/mj8GTTwsZd/',
        'md5': 'c82b745890f9baf18dc2f8d568ee3830',
        'info_dict': {
            'id': '148700',
            'display_id': 'mj8GTTwsZd',
            'ext': 'mp3',
            'title': 'Noplace',
            'tags': ['liquid drum n bass', 'energetic'],

Review comment (suggestion):
we can handle this all in the `_VALID_URL` by adding an `sfx` capture group
```suggestion
    _VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/(?:(?P<sfx>sound-effects/tracks)|track)/(?P<id>[0-9a-zA-Z-]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    float_or_none,
    int_or_none,
    join_nonempty,
    orderedSet,
    parse_iso8601,
    parse_qs,
    parse_resolution,
    str_or_none,
    traverse_obj,
    url_or_none,
)


class EpidemicSoundIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/(?:(?P<sfx>sound-effects/tracks)|track)/(?P<id>[0-9a-zA-Z-]+)'
    _TESTS = [{
        'url': 'https://www.epidemicsound.com/track/yFfQVRpSPz/',
        'md5': 'd98ff2ddb49e8acab9716541cbc9dfac',
        'info_dict': {
            'id': '45014',
            'display_id': 'yFfQVRpSPz',
            'ext': 'mp3',
            'title': 'Door Knock Door 1',
            'alt_title': 'Door Knock Door 1',
            'tags': ['foley', 'door', 'knock', 'glass', 'window', 'glass door knock'],
            'categories': ['Misc. Door'],
            'duration': 1,
            'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/default-sfx/3000x3000.jpg',
            'timestamp': 1415320353,
            'upload_date': '20141107',
        },
    }, {
        'url': 'https://www.epidemicsound.com/track/mj8GTTwsZd/',
        'md5': 'c82b745890f9baf18dc2f8d568ee3830',
        'info_dict': {
            'id': '148700',
            'display_id': 'mj8GTTwsZd',
            'ext': 'mp3',
            'title': 'Noplace',
            'tags': ['liquid drum n bass', 'energetic'],
            'categories': ['drum and bass'],
            'duration': 237,
            'timestamp': 1694426482,
            'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/11138/3000x3000.jpg',