@@ -720,32 +720,27 @@ public static Optional<String> getUrlFromNavigationEndpoint(
720720
721721 return null ;
722722 })
723- .or (() -> {
724- final var browseEndpoint = navigationEndpoint . getObject ( " browseEndpoint" );
725- final var baseUrl = browseEndpoint . getString ( "canonicalBaseUrl" );
726- final var browseId = browseEndpoint .getString ("browseId " );
727-
728- return Optional . ofNullable ( browseId )
729- . map ( id -> {
730- if (id .startsWith ("UC" )) {
723+ .or (() -> Optional . ofNullable ( navigationEndpoint . getObject ( "browseEndpoint" , null ))
724+ . map ( browseEndpoint -> {
725+ final var canonicalBaseUrl =
726+ browseEndpoint .getString ("canonicalBaseUrl " );
727+ final var browseId = browseEndpoint . getString ( "browseId" );
728+
729+ if ( browseId != null ) {
730+ if (browseId .startsWith ("UC" )) {
731731 // All channel IDs are prefixed with UC
732- return "https://www.youtube.com/channel/" + id ;
733- } else if (id .startsWith ("VL" )) {
732+ return "https://www.youtube.com/channel/" + browseId ;
733+ } else if (browseId .startsWith ("VL" )) {
734734 // All playlist IDs are prefixed with VL, which needs to be
735735 // removed from the playlist ID
736736 return "https://www.youtube.com/playlist?list="
737- + id .substring (2 );
738- }
739- return null ;
740- })
741- .or (() -> {
742- if (!isNullOrEmpty (baseUrl )) {
743- return Optional .of ("https://www.youtube.com" + baseUrl );
744- } else {
745- return Optional .empty ();
737+ + browseId .substring (2 );
746738 }
747- });
748- })
739+ } else if (!isNullOrEmpty (canonicalBaseUrl )) {
740+ return "https://www.youtube.com" + canonicalBaseUrl ;
741+ }
742+ return null ;
743+ }))
749744 .or (() -> Optional .ofNullable (navigationEndpoint .getObject ("watchEndpoint" , null ))
750745 .map (watchEndpoint -> {
751746 final var videoId = watchEndpoint .getString (VIDEO_ID );
0 commit comments