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

Code before:
        'url': 'https://steviasphere.bandcamp.com/music',
        'playlist_mincount': 47,
        'info_dict': {
            'id': 'steviasphere',
            'title': 'Discography of steviasphere',
        },
    }, {
        'url': 'https://coldworldofficial.bandcamp.com/music',
        'playlist_mincount': 10,
        'info_dict': {
            'id': 'coldworldofficial',
            'title': 'Discography of coldworldofficial',
        },
    }, {
        'url': 'https://nuclearwarnowproductions.bandcamp.com/music',
        'playlist_mincount': 399,
        'info_dict': {
            'id': 'nuclearwarnowproductions',
            'title': 'Discography of nuclearwarnowproductions',
        },
    }]

    def _extract_data_attr(self, webpage, video_id, attr, fatal=True):
        return self._parse_json(self._html_search_regex(
            fr'data-{attr}=(["\'])(\[.+?\])\1', webpage,
            attr + ' data', group=2), video_id, fatal=fatal)

    def _real_extract(self, url):
        uploader = self._match_id(url)
        webpage = self._download_webpage(url, uploader)

        matches = []
        if discography_data := (re.findall(r'<li data-item-id=["\'][^>]+>\s*<a href=["\'](?![^"\'/]*?/merch)([^"\']+)', webpage)
                                or re.findall(r'<div[^>]+trackTitle["\'][^"\']+["\']([^"\']+)', webpage)):
            matches += (urljoin(url, path) for path in discography_data)
        if music_grid := self._extract_data_attr(webpage, uploader, 'client-items', fatal=False):
            matches += (urljoin(url, album.get('page_url')) for album in music_grid)

        return self.playlist_from_matches(matches, uploader, f'Discography of {uploader}')


Review comment (refactor):
I would instead use a generator method to yield all the url paths
```suggestion
    def _yield_items(self, webpage):
        yield from (
            re.findall(r'<li data-item-id=["\'][^>]+>\s*<a href=["\'](?![^"\'/]*?/merch)([^"\']+)', webpage)
            or re.findall(r'<div[^>]+trackTitle["\'][^"\']+["\']([^"\']+)', webpage))

        yield from traverse_obj(webpage, (
            {functools.partial(get_element_html_by_id, 'music-grid')}, {extract_attributes},
            'data-client-items', {json.loads}, ..., 'page_url', {str}))
```

Code after:
            'id': 'nightcallofficial',
            'title': 'Discography of nightcallofficial',
        },
        'playlist_count': 4,
    }, {
        'url': 'https://steviasphere.bandcamp.com/music',
        'playlist_mincount': 47,
        'info_dict': {
            'id': 'steviasphere',
            'title': 'Discography of steviasphere',
        },
    }, {
        'url': 'https://coldworldofficial.bandcamp.com/music',
        'playlist_mincount': 7,
        'info_dict': {
            'id': 'coldworldofficial',
            'title': 'Discography of coldworldofficial',
        },
    }, {
        'url': 'https://nuclearwarnowproductions.bandcamp.com/music',
        'playlist_mincount': 399,
        'info_dict': {
            'id': 'nuclearwarnowproductions',
            'title': 'Discography of nuclearwarnowproductions',
        },
    }]

    def _yield_items(self, webpage):
        yield from (
            re.findall(r'<li data-item-id=["\'][^>]+>\s*<a href=["\'](?![^"\'/]*?/merch)([^"\']+)', webpage)
            or re.findall(r'<div[^>]+trackTitle["\'][^"\']+["\']([^"\']+)', webpage))

        yield from traverse_obj(webpage, (
            {functools.partial(get_element_html_by_id, 'music-grid')}, {extract_attributes},
            'data-client-items', {json.loads}, ..., 'page_url', {str}))

    def _real_extract(self, url):
        uploader = self._match_id(url)
        webpage = self._download_webpage(url, uploader)

        return self.playlist_from_matches(
            self._yield_items(webpage), uploader, f'Discography of {uploader}',
            getter=functools.partial(urljoin, url))