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

Code before:
            '%s (%s)' % (user['username'], resource.capitalize()))


class SoundcloudUserPermalinkIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://(?:api\.soundcloud\.com/users/(?P<user_id>\d+)$)'
    IE_NAME = 'soundcloud:user_permalink'
    _TESTS = [{
        'url': 'https://api.soundcloud.com/users/30909869',
        'info_dict': {
            'id': '30909869',
            'title': 'neilcic (permalink)',
        },
        'playlist_mincount': 23,
    }]

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        user_id = mobj.group('user_id')

        user = self._download_json(
            self._resolv_url(url), 'user:' + user_id,
            'Downloading user info', headers=self._HEADERS)

        return self._extract_playlist(
            self._API_V2_BASE + 'stream/users/%s' % user['id'],
            str_or_none(user.get('id')), '%s (permalink)' % user['username'])


class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)'
    IE_NAME = 'soundcloud:trackstation'
    _TESTS = [{
        'url': 'https://soundcloud.com/stations/track/officialsundial/your-text',
        'info_dict': {
            'id': '286017854',
            'title': 'Track station: your text',
        },
        'playlist_mincount': 47,
    }]

    def _real_extract(self, url):
        track_name = self._match_id(url)

        track = self._download_json(self._resolv_url(url), track_name, headers=self._HEADERS)
        track_id = self._search_regex(
            r'soundcloud:track-stations:(\d+)', track['id'], 'track id')

        return self._extract_playlist(
            self._API_V2_BASE + 'stations/%s/tracks' % track['id'],
            track_id, 'Track station: %s' % track['title'])


Review comment (refactor):
```suggestion
class SoundcloudUserPermalinkIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://api\.soundcloud\.com/users/(?P<id>\d+)'
    IE_NAME = 'soundcloud:user:permalink'
    _TESTS = [{
        'url': 'https://api.soundcloud.com/users/30909869',
        'info_dict': {
            'id': '30909869',
            'title': 'neilcic',
        },
        'playlist_mincount': 23,
    }]

    def _real_extract(self, url):
        user_id = self._match_id(url)
        user = self._download_json(
            self._resolv_url(url), user_id, 'Downloading user info', headers=self._HEADERS)

        return self._extract_playlist(
            f'{self._API_V2_BASE}stream/users/{user["id"]}',
            str_or_none(user.get('id')), user.get('username'))
```

Code after:
            '%s (%s)' % (user['username'], resource.capitalize()))


class SoundcloudUserPermalinkIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://api\.soundcloud\.com/users/(?P<id>\d+)'
    IE_NAME = 'soundcloud:user:permalink'
    _TESTS = [{
        'url': 'https://api.soundcloud.com/users/30909869',
        'info_dict': {
            'id': '30909869',
            'title': 'neilcic',
        },
        'playlist_mincount': 23,
    }]

    def _real_extract(self, url):
        user_id = self._match_id(url)
        user = self._download_json(
            self._resolv_url(url), user_id, 'Downloading user info', headers=self._HEADERS)

        return self._extract_playlist(
            f'{self._API_V2_BASE}stream/users/{user["id"]}', str(user['id']), user.get('username'))


class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)'
    IE_NAME = 'soundcloud:trackstation'
    _TESTS = [{
        'url': 'https://soundcloud.com/stations/track/officialsundial/your-text',
        'info_dict': {
            'id': '286017854',
            'title': 'Track station: your text',
        },
        'playlist_mincount': 47,
    }]

    def _real_extract(self, url):
        track_name = self._match_id(url)

        track = self._download_json(self._resolv_url(url), track_name, headers=self._HEADERS)
        track_id = self._search_regex(
            r'soundcloud:track-stations:(\d+)', track['id'], 'track id')

        return self._extract_playlist(
            self._API_V2_BASE + 'stations/%s/tracks' % track['id'],
            track_id, 'Track station: %s' % track['title'])


class SoundcloudRelatedIE(SoundcloudPagedPlaylistBaseIE):
    _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<slug>[\w\d-]+/[\w\d-]+)/(?P<relation>albums|sets|recommended)'
    IE_NAME = 'soundcloud:related'