Skip to content

[YouTube] Fix duration and live stream display in related videos#1478

Merged
TobiGr merged 3 commits intoTeamNewPipe:devfrom
Ecomont:fix/youtube-lockup-duration-live-stream
Apr 23, 2026
Merged

[YouTube] Fix duration and live stream display in related videos#1478
TobiGr merged 3 commits intoTeamNewPipe:devfrom
Ecomont:fix/youtube-lockup-duration-live-stream

Conversation

@Ecomont
Copy link
Copy Markdown
Contributor

@Ecomont Ecomont commented Apr 19, 2026

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

Two bugs in YoutubeStreamInfoItemLockupExtractor caused related/suggested videos to show wrong duration badges:

  1. "00:00" on Shorts and videos without a duration badge
    getDuration() threw ParsingException when no thumbnailBottomOverlayViewModel overlay was found. StreamInfoItemsCollector catches that exception and leaves duration at the Java default of 0, which the app renders as "00:00". Fixed by returning -1 (the established contract for unknown duration) instad of throwing also added a null guard before .matches() to prevent NPE on badges with no text field.

  2. Live streams showing 00:00 on duration
    determineStreamType() only checked thumbnailOverlayBadgeViewModel.thumbnailBadges for the live badge style. In the lockup format, YouTube places the live badge inside thumbnailBottomOverlayViewModel.badges — the same overlay used for duration text. So live streams were returned as VIDEO_STREAM, isLive() was false, and the app never reached the isLiveStream() branch that renders "LIVE". Fixed by adding a second check for thumbnailBottomOverlayViewModel.badges[].thumbnailBadgeViewModel.badgeStyle == THUMBNAIL_OVERLAY_BADGE_STYLE_LIVE

Ecomont added 3 commits April 19, 2026 17:10
- getDuration() returns -1 instead of throwing when no duration badge
  is present (e.g. Shorts in related section)
- Add null guard before String.matches() to avoid NPE on missing badge text
- determineStreamType() now also checks thumbnailBottomOverlayViewModel
  badges for the live style, so live streams in related videos are
  correctly identified as LIVE_STREAM instead of VIDEO_STREAM
- Update Javadoc to reflect Shorts behaviour
Tests cover: normal video with duration badge, video without duration
badge (Shorts), and live stream. Mocks added for all three cases.
Update disabled testMoreRelatedItems comment to reflect the fix.
@sonarqubecloud
Copy link
Copy Markdown

@ShareASmile ShareASmile added bug Issue or PR is related to a bug YouTube Service, https://www.youtube.com/ labels Apr 19, 2026
Copy link
Copy Markdown
Contributor

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

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

Thank you! Just a small question.

Comment on lines +238 to +241
if (!input.matches(".*\\d.*") && !input.equalsIgnoreCase("SHORTS")) {
throw new ParsingException("Error duration string contains no digits: " + input);
}

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.

I do not understand this change. Why exclude shorts here? If SHORTS is passed, it will fail in convertDurationToInt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

YouTube does something special with shorts in certain places, instead of showing the numeric duration in the corner of the thumbnail, it simply shows the word SHORTS

SHORTS does not actually fail in convertDurationToInt, and that is precisely why the check exists.

Without the !input.equalsIgnoreCase("SHORTS") guard: parseDurationString("SHORTS") would hit this line first

if (!input.matches(".*\\d.*")) {
    throw new ParsingException("Error duration string contains no digits: " + input);
}

It would throw immediately, never reaching convertDurationToInt at all.

The check is not there to exclude shorts, but to allow them thrugh so that the downstream fallback (returning 0) can handle the case where YouTube sends SHORTS instead of an actual timestamp

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.

Ah yeah, I see. Thank you.

@Ecomont Ecomont requested a review from TobiGr April 23, 2026 13:38
@TobiGr TobiGr merged commit 827d206 into TeamNewPipe:dev Apr 23, 2026
3 checks passed
@TobiGr TobiGr changed the title Fix duration and live stream display in related videos [YouTube] Fix duration and live stream display in related videos Apr 23, 2026
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants