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

Code before:
        if tabs:
            selected_tab = self._extract_selected_tab(tabs)
            selected_tab_name = selected_tab.get('title', '').lower()
            requested_tab_name = mobj['tab'][1:]
            if 'no-youtube-channel-redirect' not in compat_opts:
                if mobj['tab'] == '/live':
                    # Live tab should have redirected to the video
                    raise ExtractorError('The channel is not currently live', expected=True)
                if selected_tab_name != requested_tab_name and requested_tab_name != 'featured':
                    redirect_warning = f'The URL does not have a {requested_tab_name} tab'
                    if requested_tab_name == 'videos':
                        if not mobj['not_channel'] and item_id[:2] == 'UC':
                            # Topic channels don't have /videos. Use the equivalent playlist instead
                            pl_id = f'UU{item_id[2:]}'
                            pl_url = f'https://www.youtube.com/playlist?list={pl_id}'
                            try:
                                data, ytcfg = self._extract_data(pl_url, pl_id, ytcfg=ytcfg, fatal=True)
                            except ExtractorError:
                                redirect_warning += ' and the playlist redirect gave error'
                            else:
                                item_id, url, selected_tab_name = pl_id, pl_url, requested_tab_name
                                redirect_warning += f'. Redirecting to playlist {pl_id} instead'
                        if selected_tab_name != requested_tab_name:
                            redirect_warning += f'. {selected_tab_name} tab is being downloaded instead'
                    elif not mobj['not_channel']:
                        raise ExtractorError(f'The channel did not present a {requested_tab_name} tab', expected=True)

        if redirect_warning:
            self.report_warning(redirect_warning)
        self.write_debug(f'Final URL: {url}')

        # YouTube sometimes provides a button to reload playlist with unavailable videos.
        if 'no-youtube-unavailable-videos' not in compat_opts:
            data = self._reload_with_unavailable_videos(item_id, data, ytcfg) or data
        self._extract_and_report_alerts(data, only_once=True)
        tabs = traverse_obj(data, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type=list)
        if tabs:
            return self._extract_from_tabs(item_id, ytcfg, data, tabs)

        playlist = traverse_obj(
            data, ('contents', 'twoColumnWatchNextResults', 'playlist', 'playlist'), expected_type=dict)
        if playlist:
            return self._extract_from_playlist(item_id, url, data, playlist, ytcfg)

        video_id = traverse_obj(
            data, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'), expected_type=str) or video_id
        if video_id:
            if mobj['tab'] != '/live':  # live tab is expected to redirect to video
                self.report_warning(f'Unable to recognize playlist. Downloading just video {video_id}')
            return self.url_result(f'https://www.youtube.com/watch?v={video_id}',
                                   ie=YoutubeIE.ie_key(), video_id=video_id)

Review comment (refactor):
```suggestion
                    elif not mobj['not_channel']:
                        raise ExtractorError(redirect_warning, expected=True)
```
Not sure if we need the channel check

Code after:
        tabs = traverse_obj(data, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type=list)
        if tabs:
            selected_tab = self._extract_selected_tab(tabs)
            selected_tab_name = selected_tab.get('title', '').lower()
            if selected_tab_name == 'home':
                selected_tab_name = 'featured'
            requested_tab_name = mobj['tab'][1:]
            if 'no-youtube-channel-redirect' not in compat_opts:
                if requested_tab_name == 'live':
                    # Live tab should have redirected to the video
                    raise ExtractorError('The channel is not currently live', expected=True)
                if requested_tab_name not in ('', selected_tab_name):
                    redirect_warning = f'The channel does not have a {requested_tab_name} tab'
                    if not original_tab_name:
                        if item_id[:2] == 'UC':
                            # Topic channels don't have /videos. Use the equivalent playlist instead
                            pl_id = f'UU{item_id[2:]}'
                            pl_url = f'https://www.youtube.com/playlist?list={pl_id}'
                            try:
                                data, ytcfg = self._extract_data(pl_url, pl_id, ytcfg=ytcfg, fatal=True, webpage_fatal=True)
                            except ExtractorError:
                                redirect_warning += ' and the playlist redirect gave error'
                            else:
                                item_id, url, selected_tab_name = pl_id, pl_url, requested_tab_name
                                redirect_warning += f'. Redirecting to playlist {pl_id} instead'
                        if selected_tab_name and selected_tab_name != requested_tab_name:
                            redirect_warning += f'. {selected_tab_name} tab is being downloaded instead'
                    else:
                        raise ExtractorError(redirect_warning, expected=True)

        if redirect_warning:
            self.to_screen(redirect_warning)
        self.write_debug(f'Final URL: {url}')

        # YouTube sometimes provides a button to reload playlist with unavailable videos.
        if 'no-youtube-unavailable-videos' not in compat_opts:
            data = self._reload_with_unavailable_videos(item_id, data, ytcfg) or data
        self._extract_and_report_alerts(data, only_once=True)
        tabs = traverse_obj(data, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type=list)
        if tabs:
            return self._extract_from_tabs(item_id, ytcfg, data, tabs)

        playlist = traverse_obj(
            data, ('contents', 'twoColumnWatchNextResults', 'playlist', 'playlist'), expected_type=dict)
        if playlist:
            return self._extract_from_playlist(item_id, url, data, playlist, ytcfg)

        video_id = traverse_obj(
            data, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'), expected_type=str) or video_id
        if video_id:
            if mobj['tab'] != '/live':  # live tab is expected to redirect to video