@@ -267,51 +267,29 @@ public boolean isUploaderVerified() throws ParsingException {
267267 @ Override
268268 public long getStreamCount () throws ParsingException {
269269 if (isNewPlaylistInterface ) {
270- final String numVideosText =
271- getTextFromObject (getPlaylistHeader ().getObject ("numVideosText" ))
272- .orElse (null );
273- if (numVideosText != null ) {
274- try {
275- return Long .parseLong (Utils .removeNonDigitCharacters (numVideosText ));
276- } catch (final NumberFormatException ignored ) {
277- }
278- }
279-
280- final String firstByLineRendererText = getTextFromObject (
281- getPlaylistHeader ().getArray ("byline" )
270+ final var count = getTextFromObject (getPlaylistHeader ().getObject ("numVideosText" ))
271+ .or (() -> getTextFromObject (getPlaylistHeader ().getArray ("byline" )
282272 .getObject (0 )
283- .getObject ("text" ))
273+ .getObject ("text" )))
274+ .map (numText -> {
275+ try {
276+ return Long .parseLong (Utils .removeNonDigitCharacters (numText ));
277+ } catch (final NumberFormatException e ) {
278+ return null ;
279+ }
280+ })
284281 .orElse (null );
285-
286- if (firstByLineRendererText != null ) {
287- try {
288- return Long .parseLong (Utils .removeNonDigitCharacters (firstByLineRendererText ));
289- } catch (final NumberFormatException ignored ) {
290- }
282+ if (count != null ) {
283+ return count ;
291284 }
292285 }
293286
294287 // These data structures are returned in both layouts
295- final JsonArray briefStats =
296- (isNewPlaylistInterface ? getPlaylistHeader () : getPlaylistInfo ())
297- .getArray ("briefStats" );
298- if (!briefStats .isEmpty ()) {
299- final var briefsStatsText = getTextFromObject (briefStats .getObject (0 )).orElse (null );
300- if (briefsStatsText != null ) {
301- return Long .parseLong (Utils .removeNonDigitCharacters (briefsStatsText ));
302- }
303- }
304-
305- final JsonArray stats = (isNewPlaylistInterface ? getPlaylistHeader () : getPlaylistInfo ())
306- .getArray ("stats" );
307- if (!stats .isEmpty ()) {
308- final var statsText = getTextFromObject (stats .getObject (0 )).orElse (null );
309- if (statsText != null ) {
310- return Long .parseLong (Utils .removeNonDigitCharacters (statsText ));
311- }
312- }
313-
314- return ITEM_COUNT_UNKNOWN ;
288+ final var playlist = isNewPlaylistInterface ? getPlaylistHeader () : getPlaylistInfo ();
289+ return getTextFromObject (playlist .getArray ("briefStats" ).getObject (0 ))
290+ .or (() -> getTextFromObject (playlist .getArray ("stats" ).getObject (0 )))
291+ .map (text -> Long .parseLong (Utils .removeNonDigitCharacters (text )))
292+ .orElse (ITEM_COUNT_UNKNOWN );
315293 }
316294
317295 @ Nonnull
0 commit comments