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

Code before:
    }
    streamInfo {
      dashUrl
      hlsUrl
      url
    }
    tags {
      tag {
        name
      }
    }
    restrictedReason
    id''', track_id, username, slug)

        if not cloudcast:
            raise ExtractorError('Track not found', expected=True)

        if cloudcast['restrictedReason']:
            reason = cloudcast['restrictedReason']
            if reason == "tracklist":
                raise ExtractorError('Track unavailable in your country due to licensing restrictions', expected=True)
            elif reason == "repeat_play":
                # https://help.mixcloud.com/hc/en-us/articles/360010592220-Why-can-I-only-replay-a-show-three-times-
                raise ExtractorError('You have reached your play limit for this track', expected=True)
            else:
                raise ExtractorError('Track is restricted', expected=True)

        title = cloudcast['name']

        stream_info = cloudcast['streamInfo']
        formats = []

        for url_key in ('url', 'hlsUrl', 'dashUrl'):
            format_url = stream_info.get(url_key)
            if not format_url:
                continue
            decrypted = self._decrypt_xor_cipher(
                self._DECRYPTION_KEY, compat_b64decode(format_url))
            if url_key == 'hlsUrl':
                formats.extend(self._extract_m3u8_formats(
                    decrypted, track_id, 'mp4', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False))
            elif url_key == 'dashUrl':
                formats.extend(self._extract_mpd_formats(
                    decrypted, track_id, mpd_id='dash', fatal=False))
            else:
                formats.append({
                    'format_id': 'http',
                    'url': decrypted,
                    'downloader_options': {
                        # Mixcloud starts throttling at >~5M

Review comment (refactor):
```suggestion
        reason = cloudcast.get('restrictedReason')
        if reason == 'tracklist':
            raise ExtractorError('Track unavailable in your country due to licensing restrictions', expected=True)
        elif reason == 'repeat_play':
            raise ExtractorError('You have reached your play limit for this track', expected=True)
        elif reason:
            raise ExtractorError('Track is restricted', expected=True)
```

Code after:
    }
    streamInfo {
      dashUrl
      hlsUrl
      url
    }
    tags {
      tag {
        name
      }
    }
    restrictedReason
    id''', track_id, username, slug)

        if not cloudcast:
            raise ExtractorError('Track not found', expected=True)

        reason = cloudcast.get('restrictedReason')
        if reason == 'tracklist':
            raise ExtractorError('Track unavailable in your country due to licensing restrictions', expected=True)
        elif reason == 'repeat_play':
            raise ExtractorError('You have reached your play limit for this track', expected=True)
        elif reason:
            raise ExtractorError('Track is restricted', expected=True)

        title = cloudcast['name']

        stream_info = cloudcast['streamInfo']
        formats = []

        for url_key in ('url', 'hlsUrl', 'dashUrl'):
            format_url = stream_info.get(url_key)
            if not format_url:
                continue
            decrypted = self._decrypt_xor_cipher(
                self._DECRYPTION_KEY, compat_b64decode(format_url))
            if url_key == 'hlsUrl':
                formats.extend(self._extract_m3u8_formats(
                    decrypted, track_id, 'mp4', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False))
            elif url_key == 'dashUrl':
                formats.extend(self._extract_mpd_formats(
                    decrypted, track_id, mpd_id='dash', fatal=False))
            else:
                formats.append({
                    'format_id': 'http',
                    'url': decrypted,
                    'downloader_options': {
                        # Mixcloud starts throttling at >~5M
                        'http_chunk_size': 5242880,
                    },