2020
2121import java .io .IOException ;
2222
23- import static org .schabi .newpipe .extractor .services .peertube .PeertubeParsingHelper .*;
23+ import static org .schabi .newpipe .extractor .services .peertube .PeertubeParsingHelper .COUNT_KEY ;
24+ import static org .schabi .newpipe .extractor .services .peertube .PeertubeParsingHelper .ITEMS_PER_PAGE ;
25+ import static org .schabi .newpipe .extractor .services .peertube .PeertubeParsingHelper .START_KEY ;
2426
2527public class PeertubeAccountExtractor extends ChannelExtractor {
26-
27- private InfoItemsPage <StreamInfoItem > initPage ;
28- private long total ;
29-
3028 private JsonObject json ;
3129 private final String baseUrl ;
3230
33- public PeertubeAccountExtractor (StreamingService service , ListLinkHandler linkHandler ) throws ParsingException {
31+ public PeertubeAccountExtractor (final StreamingService service , final ListLinkHandler linkHandler ) throws ParsingException {
3432 super (service , linkHandler );
3533 this .baseUrl = getBaseUrl ();
3634 }
3735
3836 @ Override
39- public String getAvatarUrl () throws ParsingException {
37+ public String getAvatarUrl () {
4038 String value ;
4139 try {
4240 value = JsonUtils .getString (json , "avatar.path" );
@@ -47,7 +45,7 @@ public String getAvatarUrl() throws ParsingException {
4745 }
4846
4947 @ Override
50- public String getBannerUrl () throws ParsingException {
48+ public String getBannerUrl () {
5149 return null ;
5250 }
5351
@@ -58,12 +56,12 @@ public String getFeedUrl() throws ParsingException {
5856
5957 @ Override
6058 public long getSubscriberCount () throws ParsingException {
61- Number number = JsonUtils .getNumber (json , "followersCount" );
59+ final Number number = JsonUtils .getNumber (json , "followersCount" );
6260 return number .longValue ();
6361 }
6462
6563 @ Override
66- public String getDescription () throws ParsingException {
64+ public String getDescription () {
6765 try {
6866 return JsonUtils .getString (json , "description" );
6967 } catch (ParsingException e ) {
@@ -72,53 +70,46 @@ public String getDescription() throws ParsingException {
7270 }
7371
7472 @ Override
75- public String getParentChannelName () throws ParsingException {
73+ public String getParentChannelName () {
7674 return "" ;
7775 }
7876
7977 @ Override
80- public String getParentChannelUrl () throws ParsingException {
78+ public String getParentChannelUrl () {
8179 return "" ;
8280 }
8381
8482 @ Override
85- public String getParentChannelAvatarUrl () throws ParsingException {
83+ public String getParentChannelAvatarUrl () {
8684 return "" ;
8785 }
8886
8987 @ Override
9088 public InfoItemsPage <StreamInfoItem > getInitialPage () throws IOException , ExtractionException {
91- super . fetchPage () ;
92- return initPage ;
89+ final String pageUrl = getUrl () + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE ;
90+ return getPage ( pageUrl ) ;
9391 }
9492
95- private void collectStreamsFrom (StreamInfoItemsCollector collector , JsonObject json , String pageUrl ) throws ParsingException {
96- JsonArray contents ;
93+ private void collectStreamsFrom (StreamInfoItemsCollector collector , JsonObject json ) throws ParsingException {
94+ final JsonArray contents ;
9795 try {
9896 contents = (JsonArray ) JsonUtils .getValue (json , "data" );
9997 } catch (Exception e ) {
10098 throw new ParsingException ("unable to extract channel streams" , e );
10199 }
102100
103- for (Object c : contents ) {
101+ for (final Object c : contents ) {
104102 if (c instanceof JsonObject ) {
105103 final JsonObject item = (JsonObject ) c ;
106- PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor (item , baseUrl );
104+ final PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor (item , baseUrl );
107105 collector .commit (extractor );
108106 }
109107 }
110-
111- }
112-
113- @ Override
114- public String getNextPageUrl () throws IOException , ExtractionException {
115- super .fetchPage ();
116- return initPage .getNextPageUrl ();
117108 }
118109
119110 @ Override
120- public InfoItemsPage <StreamInfoItem > getPage (String pageUrl ) throws IOException , ExtractionException {
121- Response response = getDownloader ().get (pageUrl );
111+ public InfoItemsPage <StreamInfoItem > getPage (final String pageUrl ) throws IOException , ExtractionException {
112+ final Response response = getDownloader ().get (pageUrl );
122113 JsonObject json = null ;
123114 if (response != null && !Utils .isBlank (response .responseBody ())) {
124115 try {
@@ -128,31 +119,29 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException,
128119 }
129120 }
130121
131- StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
122+ final StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
123+ final long total ;
132124 if (json != null ) {
133125 PeertubeParsingHelper .validate (json );
134126 total = JsonUtils .getNumber (json , "total" ).longValue ();
135- collectStreamsFrom (collector , json , pageUrl );
127+ collectStreamsFrom (collector , json );
136128 } else {
137129 throw new ExtractionException ("Unable to get PeerTube kiosk info" );
138130 }
139131 return new InfoItemsPage <>(collector , PeertubeParsingHelper .getNextPageUrl (pageUrl , total ));
140132 }
141133
142134 @ Override
143- public void onFetchPage (Downloader downloader ) throws IOException , ExtractionException {
144- Response response = downloader .get (getUrl ());
145- if (null != response && null != response .responseBody ()) {
135+ public void onFetchPage (final Downloader downloader ) throws IOException , ExtractionException {
136+ final Response response = downloader .get (getUrl ());
137+ if (response != null && response .responseBody () != null ) {
146138 setInitialData (response .responseBody ());
147139 } else {
148140 throw new ExtractionException ("Unable to extract PeerTube channel data" );
149141 }
150-
151- String pageUrl = getUrl () + "/videos?" + START_KEY + "=0&" + COUNT_KEY + "=" + ITEMS_PER_PAGE ;
152- this .initPage = getPage (pageUrl );
153142 }
154143
155- private void setInitialData (String responseBody ) throws ExtractionException {
144+ private void setInitialData (final String responseBody ) throws ExtractionException {
156145 try {
157146 json = JsonParser .object ().from (responseBody );
158147 } catch (JsonParserException e ) {
@@ -170,5 +159,4 @@ public String getName() throws ParsingException {
170159 public String getOriginalUrl () throws ParsingException {
171160 return baseUrl + "/" + getId ();
172161 }
173-
174162}
0 commit comments