77import com .grack .nanojson .JsonArray ;
88import com .grack .nanojson .JsonObject ;
99
10-
1110public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
1211
1312 private final JsonObject json ;
@@ -26,8 +25,8 @@ public String getUrl() throws ParsingException {
2625 @ Override
2726 public String getThumbnailUrl () throws ParsingException {
2827 try {
29- JsonArray arr = ( JsonArray ) JsonUtils .getValue (json , "authorThumbnail.thumbnails" );
30- return ( String ) JsonUtils .getValue (arr .getObject (2 ), "url" );
28+ JsonArray arr = JsonUtils .getArray (json , "authorThumbnail.thumbnails" );
29+ return JsonUtils .getString (arr .getObject (2 ), "url" );
3130 } catch (Exception e ) {
3231 throw new ParsingException ("Could not get thumbnail url" , e );
3332 }
@@ -36,7 +35,7 @@ public String getThumbnailUrl() throws ParsingException {
3635 @ Override
3736 public String getName () throws ParsingException {
3837 try {
39- return YoutubeCommentsExtractor .getYoutubeText (( JsonObject ) JsonUtils .getValue (json , "authorText" ));
38+ return YoutubeCommentsExtractor .getYoutubeText (JsonUtils .getObject (json , "authorText" ));
4039 } catch (Exception e ) {
4140 throw new ParsingException ("Could not get author name" , e );
4241 }
@@ -45,7 +44,7 @@ public String getName() throws ParsingException {
4544 @ Override
4645 public String getPublishedTime () throws ParsingException {
4746 try {
48- return YoutubeCommentsExtractor .getYoutubeText (( JsonObject ) JsonUtils .getValue (json , "publishedTimeText" ));
47+ return YoutubeCommentsExtractor .getYoutubeText (JsonUtils .getObject (json , "publishedTimeText" ));
4948 } catch (Exception e ) {
5049 throw new ParsingException ("Could not get publishedTimeText" , e );
5150 }
@@ -54,7 +53,7 @@ public String getPublishedTime() throws ParsingException {
5453 @ Override
5554 public Integer getLikeCount () throws ParsingException {
5655 try {
57- return ( Integer ) JsonUtils .getValue (json , "likeCount" );
56+ return JsonUtils .getNumber (json , "likeCount" ). intValue ( );
5857 } catch (Exception e ) {
5958 throw new ParsingException ("Could not get like count" , e );
6059 }
@@ -63,7 +62,7 @@ public Integer getLikeCount() throws ParsingException {
6362 @ Override
6463 public String getCommentText () throws ParsingException {
6564 try {
66- return YoutubeCommentsExtractor .getYoutubeText (( JsonObject ) JsonUtils .getValue (json , "contentText" ));
65+ return YoutubeCommentsExtractor .getYoutubeText (JsonUtils .getObject (json , "contentText" ));
6766 } catch (Exception e ) {
6867 throw new ParsingException ("Could not get comment text" , e );
6968 }
@@ -72,7 +71,7 @@ public String getCommentText() throws ParsingException {
7271 @ Override
7372 public String getCommentId () throws ParsingException {
7473 try {
75- return ( String ) JsonUtils .getValue (json , "commentId" );
74+ return JsonUtils .getString (json , "commentId" );
7675 } catch (Exception e ) {
7776 throw new ParsingException ("Could not get comment id" , e );
7877 }
@@ -81,8 +80,8 @@ public String getCommentId() throws ParsingException {
8180 @ Override
8281 public String getAuthorThumbnail () throws ParsingException {
8382 try {
84- JsonArray arr = ( JsonArray ) JsonUtils .getValue (json , "authorThumbnail.thumbnails" );
85- return ( String ) JsonUtils .getValue (arr .getObject (2 ), "url" );
83+ JsonArray arr = JsonUtils .getArray (json , "authorThumbnail.thumbnails" );
84+ return JsonUtils .getString (arr .getObject (2 ), "url" );
8685 } catch (Exception e ) {
8786 throw new ParsingException ("Could not get author thumbnail" , e );
8887 }
@@ -91,7 +90,7 @@ public String getAuthorThumbnail() throws ParsingException {
9190 @ Override
9291 public String getAuthorName () throws ParsingException {
9392 try {
94- return YoutubeCommentsExtractor .getYoutubeText (( JsonObject ) JsonUtils .getValue (json , "authorText" ));
93+ return YoutubeCommentsExtractor .getYoutubeText (JsonUtils .getObject (json , "authorText" ));
9594 } catch (Exception e ) {
9695 throw new ParsingException ("Could not get author name" , e );
9796 }
@@ -100,8 +99,7 @@ public String getAuthorName() throws ParsingException {
10099 @ Override
101100 public String getAuthorEndpoint () throws ParsingException {
102101 try {
103- return "https://youtube.com"
104- + (String ) JsonUtils .getValue (json , "authorEndpoint.browseEndpoint.canonicalBaseUrl" );
102+ return "https://youtube.com" + JsonUtils .getString (json , "authorEndpoint.browseEndpoint.canonicalBaseUrl" );
105103 } catch (Exception e ) {
106104 throw new ParsingException ("Could not get author endpoint" , e );
107105 }
0 commit comments