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

Code before:
                # If there is neither video or playlist ids, youtube redirects to home page, which is undesirable
                raise ExtractorError('Unable to recognize tab page')
            # Common mistake: https://www.youtube.com/watch?list=playlist_id
            self.report_warning(f'A video URL was given without video ID. Trying to download playlist {playlist_id}')
            url = f'https://www.youtube.com/playlist?list={playlist_id}'
            mobj = get_mobj(url)

        if video_id and playlist_id:
            if self.get_param('noplaylist'):
                self.to_screen(f'Downloading just video {video_id} because of --no-playlist')
                return self.url_result(f'https://www.youtube.com/watch?v={video_id}',
                                       ie=YoutubeIE.ie_key(), video_id=video_id)
            self.to_screen(f'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}')

        data, ytcfg = self._extract_data(url, item_id)

        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()
            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 is_channel and 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 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.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

Review comment (suggestion):
Can you explain this? Especially the `!= 'featured'`
I think `requested_tab_name not in ('', selected_tab_name)` is sufficient here

Code after:
            if not playlist_id:
                # If there is neither video or playlist ids, youtube redirects to home page, which is undesirable
                raise ExtractorError('Unable to recognize tab page')
            # Common mistake: https://www.youtube.com/watch?list=playlist_id
            self.report_warning(f'A video URL was given without video ID. Trying to download playlist {playlist_id}')
            url = f'https://www.youtube.com/playlist?list={playlist_id}'
            mobj = get_mobj(url)

        if video_id and playlist_id:
            if self.get_param('noplaylist'):
                self.to_screen(f'Downloading just video {video_id} because of --no-playlist')
                return self.url_result(f'https://www.youtube.com/watch?v={video_id}',
                                       ie=YoutubeIE.ie_key(), video_id=video_id)
            self.to_screen(f'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}')

        data, ytcfg = self._extract_data(url, item_id)

        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}')