File tree Expand file tree Collapse file tree
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -571,6 +571,16 @@ public static String getTextFromObject(JsonObject textObject) throws ParsingExce
571571 return getTextFromObject (textObject , false );
572572 }
573573
574+ @ Nullable
575+ public static String getTextAtKey (final JsonObject jsonObject , final String key )
576+ throws ParsingException {
577+ if (jsonObject .isString (key )) {
578+ return jsonObject .getString (key );
579+ } else {
580+ return getTextFromObject (jsonObject .getObject (key ));
581+ }
582+ }
583+
574584 public static String fixThumbnailUrl (String thumbnailUrl ) {
575585 if (thumbnailUrl .startsWith ("//" )) {
576586 thumbnailUrl = thumbnailUrl .substring (2 );
Original file line number Diff line number Diff line change 3939import javax .annotation .Nonnull ;
4040
4141import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getJsonResponse ;
42+ import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getTextAtKey ;
4243import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getTextFromObject ;
4344import static org .schabi .newpipe .extractor .utils .Utils .isNullOrEmpty ;
4445
@@ -70,18 +71,17 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) {
7071 @ Override
7172 public String getName () throws ParsingException {
7273 final JsonObject header = initialData .getObject ("header" );
73- JsonObject title = null ;
74+ String name = null ;
7475 if (header .has ("feedTabbedHeaderRenderer" )) {
75- title = header .getObject ("feedTabbedHeaderRenderer" ). getObject ( "title" );
76+ name = getTextAtKey ( header .getObject ("feedTabbedHeaderRenderer" ), "title" );
7677 } else if (header .has ("c4TabbedHeaderRenderer" )) {
77- title = header .getObject ("c4TabbedHeaderRenderer" ). getObject ( "title" );
78+ name = getTextAtKey ( header .getObject ("c4TabbedHeaderRenderer" ), "title" );
7879 }
7980
80- String name = getTextFromObject (title );
81- if (!isNullOrEmpty (name )) {
82- return name ;
81+ if (isNullOrEmpty (name )) {
82+ throw new ParsingException ("Could not get Trending name" );
8383 }
84- throw new ParsingException ( "Could not get Trending name" ) ;
84+ return name ;
8585 }
8686
8787 @ Nonnull
You can’t perform that action at this time.
0 commit comments