Skip to content

[YouTube] Make channelId resolution follow redirects and fix YoutubeStreamInfoItemLockupExtractor building incorrect handles#1347

Merged
Stypox merged 5 commits intoTeamNewPipe:devfrom
litetex:fix-yt-channel-id-resolution
Jul 31, 2025
Merged

[YouTube] Make channelId resolution follow redirects and fix YoutubeStreamInfoItemLockupExtractor building incorrect handles#1347
Stypox merged 5 commits intoTeamNewPipe:devfrom
litetex:fix-yt-channel-id-resolution

Conversation

@litetex
Copy link
Copy Markdown
Member

@litetex litetex commented Jul 26, 2025

Followup of #1344 (comment)

Fixes #1345

This fixes the following problems:

  1. Fix YT handle resolution. It works now like this:
    When resolving a YT handle like @TheDailyShow, YT first returns a response with WEB_PAGE_TYPE_UNKNOWN and a redirect to thedailyshow. The redirect must then be resolved again to get the actual channel id which is UCwWhs_6x42TyRM4Wstoq8HA. However this is not always the case.
  2. I built the handle url in YoutubeStreamInfoItemLockupExtractor incorrectly, however it was (sometimes?) resolved correctly due to the previous problem.

@AudricV
Copy link
Copy Markdown
Member

AudricV commented Jul 26, 2025

When resolving a YT handle like @TheDailyShow, YT first returns a response with WEB_PAGE_TYPE_UNKNOWN and a redirect to thedailyshow. The redirect must then be resolved again to get the actual channel id with is UCwWhs_6x42TyRM4Wstoq8HA.

This is not always the case, this is the first time I see this. You can try for instance with @google or @Gronkh, you get directly the channel ID in a browseEndpoint.

Please update your comment in the code and your PR description :)

@AudricV AudricV added bug Issue or PR is related to a bug YouTube Service, https://www.youtube.com/ labels Jul 26, 2025
litetex added a commit to litetex/NewPipeExtractor that referenced this pull request Jul 26, 2025
Ref: TeamNewPipe#1347 (comment)
Co-Authored-By: Audric V. <74829229+AudricV@users.noreply.github.com>
@litetex
Copy link
Copy Markdown
Member Author

litetex commented Jul 26, 2025

Please update your comment in the code and your PR description :)

Done :)

@Stypox Stypox added this to v0.28.x Jul 28, 2025
@github-project-automation github-project-automation Bot moved this to Todo in v0.28.x Jul 28, 2025
@Stypox Stypox moved this from Todo to In Progress in v0.28.x Jul 28, 2025
Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in this PR looks good to me, and this function is only called to resolve URLs upon fetching stuff so it's not like we're going to get many more requests (it'd be bad if it was one request per info item). Thanks!

Comment on lines 109 to 110
if (webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_BROWSE")
|| webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_CHANNEL")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw this (|| &&) combination might be wrong, since clarifying parenthesis are missing. What is the intended condition here @AudricV?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the equalsIgnoreCase should also likely be inverted for better null safety (we can also then remove the "" initialization above)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended condition here

The intended condition is if it is a valid webpage type and a valid browse ID so:

(webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_BROWSE")
        || webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_CHANNEL"))
        && !browseId.isEmpty()

Thanks for catching this 4 year-old-bug I introduced!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6397b2e. It wasn't the only place where the parenthesis was missing. getChannelResponse and resolveChannelId are quite similar and might qualify for deduplication at a later point...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's any checkstyle rule for this, but I could only find one which does the opposite 😅 https://checkstyle.org/checks/coding/unnecessaryparentheses.html

Comment on lines +75 to +80
// It works like that:
// @TheDailyShow
// -> resolves to thedailyshow
// -> resolves to the id: UCwWhs_6x42TyRM4Wstoq8HA
// Please note that this is not always the case, some handles
// e.g. @google or @Gronkh directly resolve the id
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really important, but I wonder whether the contrary is more common instead. If so, this comment should updated.

Comment on lines 109 to 110
if (webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_BROWSE")
|| webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_CHANNEL")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended condition here

The intended condition is if it is a valid webpage type and a valid browse ID so:

(webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_BROWSE")
        || webPageType.equalsIgnoreCase("WEB_PAGE_TYPE_CHANNEL"))
        && !browseId.isEmpty()

Thanks for catching this 4 year-old-bug I introduced!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add tests for channels without this handle -> c/ -> browseId redirection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in aa70b5a. I amended the initial commit which creates the YouTubeChannelHelperTest because the other mocks were touched while recording the new ones for the class.

@TobiGr TobiGr force-pushed the fix-yt-channel-id-resolution branch from 3deef52 to 6397b2e Compare July 31, 2025 09:20
@Stypox Stypox merged commit 426a227 into TeamNewPipe:dev Jul 31, 2025
4 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in v0.28.x Jul 31, 2025
@litetex litetex deleted the fix-yt-channel-id-resolution branch August 1, 2025 19:08
whistlingwoods pushed a commit to whistlingwoods/TubularExtractor that referenced this pull request Aug 25, 2025
Ref: TeamNewPipe/NewPipeExtractor#1347 (comment)
Co-Authored-By: Audric V. <74829229+AudricV@users.noreply.github.com>
whistlingwoods pushed a commit to whistlingwoods/NewPipeExtractor that referenced this pull request Sep 2, 2025
whistlingwoods pushed a commit to whistlingwoods/NewPipeExtractor that referenced this pull request Jan 10, 2026
Ref: TeamNewPipe#1347 (comment)
Co-Authored-By: Audric V. <74829229+AudricV@users.noreply.github.com>
whistlingwoods pushed a commit to whistlingwoods/NewPipeExtractor that referenced this pull request Jan 10, 2026
Ref: TeamNewPipe#1347 (comment)
Co-Authored-By: Audric V. <74829229+AudricV@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue or PR is related to a bug YouTube Service, https://www.youtube.com/

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

YoutubeStreamInfoItemLockupExtractor: getUploaderUrl not resolving correct url

4 participants