1010import org .schabi .newpipe .extractor .StreamingService ;
1111import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
1212import org .schabi .newpipe .extractor .linkhandler .ListLinkHandler ;
13+ import org .schabi .newpipe .extractor .stream .StreamInfoItem ;
1314import org .schabi .newpipe .extractor .utils .ExtractorHelper ;
1415
1516public class CommentsInfo extends ListInfo <CommentsInfoItem >{
@@ -23,78 +24,45 @@ public static CommentsInfo getInfo(String url) throws IOException, ExtractionExc
2324 return getInfo (NewPipe .getServiceByUrl (url ), url );
2425 }
2526
26- private static CommentsInfo getInfo (StreamingService serviceByUrl , String url ) throws ExtractionException , IOException {
27+ public static CommentsInfo getInfo (StreamingService serviceByUrl , String url ) throws ExtractionException , IOException {
2728 return getInfo (serviceByUrl .getCommentsExtractor (url ));
2829 }
2930
3031 private static CommentsInfo getInfo (CommentsExtractor commentsExtractor ) throws IOException , ExtractionException {
31- //for services which do not have a comments extractor
32- if (null == commentsExtractor ) {
32+ // for services which do not have a comments extractor
33+ if (null == commentsExtractor ) {
3334 return null ;
3435 }
35-
36+
3637 commentsExtractor .fetchPage ();
3738 String name = commentsExtractor .getName ();
3839 int serviceId = commentsExtractor .getServiceId ();
3940 ListLinkHandler listUrlIdHandler = commentsExtractor .getUIHandler ();
4041 CommentsInfo commentsInfo = new CommentsInfo (serviceId , listUrlIdHandler , name );
4142 commentsInfo .setCommentsExtractor (commentsExtractor );
42- InfoItemsPage <CommentsInfoItem > initialCommentsPage = ExtractorHelper .getItemsPageOrLogError (commentsInfo ,
43- commentsExtractor );
44- commentsInfo .setComments (new ArrayList <>());
45- commentsInfo .getComments ().addAll (initialCommentsPage .getItems ());
46- //tmp
43+ InfoItemsPage <CommentsInfoItem > initialCommentsPage = ExtractorHelper .getItemsPageOrLogError (commentsInfo ,
44+ commentsExtractor );
4745 commentsInfo .setRelatedItems (initialCommentsPage .getItems ());
4846 commentsInfo .setNextPageUrl (initialCommentsPage .getNextPageUrl ());
49-
50- commentsInfo .setHasMoreComments (initialCommentsPage .hasNextPage ());
51- commentsInfo .setNextCommentsPageUrl (initialCommentsPage .getNextPageUrl ());
47+
5248 return commentsInfo ;
5349 }
5450
55- public static void loadMoreComments (CommentsInfo commentsInfo ) {
56- if (commentsInfo .hasMoreComments ()) {
57- if (null == commentsInfo .getCommentsExtractor ()) {
58- try {
59- commentsInfo .setCommentsExtractor (NewPipe .getService (commentsInfo .getServiceId ()).getCommentsExtractor (commentsInfo .getUrl ()));
60- commentsInfo .getCommentsExtractor ().fetchPage ();
61- } catch (ExtractionException | IOException e ) {
62- commentsInfo .addError (e );
63- return ;
64- }
65- }
66- try {
67- InfoItemsPage <CommentsInfoItem > commentsPage = commentsInfo .getCommentsExtractor ()
68- .getPage (commentsInfo .getNextCommentsPageUrl ());
69- commentsInfo .getComments ().addAll (commentsPage .getItems ());
70- commentsInfo .setHasMoreComments (commentsPage .hasNextPage ());
71- commentsInfo .setNextCommentsPageUrl (commentsPage .getNextPageUrl ());
72- } catch (IOException | ExtractionException e ) {
73- commentsInfo .addError (e );
74- }
51+ public static InfoItemsPage <CommentsInfoItem > getMoreItems (CommentsInfo commentsInfo , String pageUrl )
52+ throws ExtractionException , IOException {
53+ return getMoreItems (NewPipe .getService (commentsInfo .getServiceId ()), commentsInfo , pageUrl );
54+ }
55+
56+ public static InfoItemsPage <CommentsInfoItem > getMoreItems (StreamingService service , CommentsInfo commentsInfo ,
57+ String pageUrl ) throws IOException , ExtractionException {
58+ if (null == commentsInfo .getCommentsExtractor ()) {
59+ commentsInfo .setCommentsExtractor (service .getCommentsExtractor (commentsInfo .getUrl ()));
60+ commentsInfo .getCommentsExtractor ().fetchPage ();
7561 }
62+ return commentsInfo .getCommentsExtractor ().getPage (pageUrl );
7663 }
7764
7865 private transient CommentsExtractor commentsExtractor ;
79- private List <CommentsInfoItem > comments ;
80- private boolean hasMoreComments ;
81- private String nextCommentsPageUrl ;
82-
83- public List <CommentsInfoItem > getComments () {
84- return comments ;
85- }
86-
87- public void setComments (List <CommentsInfoItem > comments ) {
88- this .comments = comments ;
89- }
90-
91- public boolean hasMoreComments () {
92- return hasMoreComments ;
93- }
94-
95- public void setHasMoreComments (boolean hasMoreComments ) {
96- this .hasMoreComments = hasMoreComments ;
97- }
9866
9967 public CommentsExtractor getCommentsExtractor () {
10068 return commentsExtractor ;
@@ -104,12 +72,4 @@ public void setCommentsExtractor(CommentsExtractor commentsExtractor) {
10472 this .commentsExtractor = commentsExtractor ;
10573 }
10674
107- public String getNextCommentsPageUrl () {
108- return nextCommentsPageUrl ;
109- }
110-
111- public void setNextCommentsPageUrl (String nextCommentsPageUrl ) {
112- this .nextCommentsPageUrl = nextCommentsPageUrl ;
113- }
114-
11575}
0 commit comments