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

Code before:
            is_live = status == 2  # Not currently live is 4, other numbers have not been encountered for the time being

            base_dict = {
                'title': title,
                'uploader_id': uploader_id,
                'is_live': is_live,
            }

            if is_live:
                liveUrl = traverse_obj(video_js_data, ('LiveRoomInfo', 'liveUrl'), expected_type=str)
                if self.suitable(liveUrl):  # Prevent infinite loop in case redirect fails
                    raise UnsupportedError(liveUrl)
                formats = self._extract_m3u8_formats(
                    liveUrl, room_id, 'mp4')
                infodict = {
                    'formats': formats,
                }
                return {
                    'id': room_id,
                    **base_dict,
                    **infodict,
                }
            else:
                raise ExtractorError('The user is not currently live')
                # https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/twitcasting.py#L253
        raise ExtractorError('The user is not currently live')


Review comment (refactor):
again, instead of indenting most of the code in a `if room_id:` block, this `raise` could be moved up like this:

```py
        room_id = self._html_search_regex(r'snssdk\d*://live\?room_id=(\d+)', webpage, 'room ID', default=None)
        if not room_id:
            raise ExtractorError('The user is not currently live', expected=True)
```
also add `expected=True`

Code after:
            'ext': 'mp4',
            'title': 'md5:c64f6152330c2efe98093ccc8597871c',
            'uploader_id': '6687535061741700102',
            'upload_date': '20221127',
            'view_count': int,
            'like_count': int,
            'comment_count': int,
            'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAObqu3WCTXxmw2xwZ3iLEHnEecEIw7ks6rxWqOqOhaPja9BI7gqUQnjw8_5FSoDXX',
            'album': 'Wave of Mutilation: Best of Pixies',
            'thumbnail': r're:https://.+\.webp.*',
            'duration': 5,
            'timestamp': 1669516858,
            'repost_count': int,
            'artist': 'Pixies',
            'track': 'Where Is My Mind?',
            'description': 'md5:c64f6152330c2efe98093ccc8597871c',
            'uploader': 'sigmachaddeus',
            'creator': 'SigmaChad',
        },
    }, {
        'url': 'https://vm.tiktok.com/ZTR45GpSF/',
        'info_dict': {
            'id': '7106798200794926362',
            'ext': 'mp4',
            'title': 'md5:edc3e7ea587847f8537468f2fe51d074',
            'uploader_id': '6997695878846268418',
            'upload_date': '20220608',
            'view_count': int,
            'like_count': int,
            'comment_count': int,
            'thumbnail': r're:https://.+\.webp.*',
            'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAdZ_NcPPgMneaGrW0hN8O_J_bwLshwNNERRF5DxOw2HKIzk0kdlLrR8RkVl1ksrMO',
            'duration': 29,
            'timestamp': 1654680400,
            'repost_count': int,
            'artist': 'Akihitoko',
            'track': 'original sound',
            'description': 'md5:edc3e7ea587847f8537468f2fe51d074',
            'uploader': 'akihitoko1',
            'creator': 'Akihitoko',
        },
    }, {
        'url': 'https://vt.tiktok.com/ZSe4FqkKd',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        new_url = self._request_webpage(
            HEADRequest(url), self._match_id(url), headers={'User-Agent': 'facebookexternalhit/1.1'}).geturl()
        if self.suitable(new_url):  # Prevent infinite loop in case redirect fails
            raise UnsupportedError(new_url)