3939
4040public class PeertubeStreamExtractor extends StreamExtractor {
4141
42-
42+
43+ private final String baseUrl ;
4344 private JsonObject json ;
4445 private List <SubtitlesStream > subtitles = new ArrayList <>();
45- private final String baseUrl ;
46-
46+
4747 public PeertubeStreamExtractor (StreamingService service , LinkHandler linkHandler ) throws ParsingException {
4848 super (service , linkHandler );
4949 this .baseUrl = getBaseUrl ();
5050 }
51-
51+
5252 @ Override
5353 public String getTextualUploadDate () throws ParsingException {
5454 return JsonUtils .getString (json , "publishedAt" );
@@ -64,7 +64,7 @@ public DateWrapper getUploadDate() throws ParsingException {
6464
6565 return new DateWrapper (PeertubeParsingHelper .parseDateFrom (textualUploadDate ));
6666 }
67-
67+
6868 @ Override
6969 public String getThumbnailUrl () throws ParsingException {
7070 return baseUrl + JsonUtils .getString (json , "previewPath" );
@@ -149,7 +149,7 @@ public String getUploaderAvatarUrl() throws ParsingException {
149149 String value ;
150150 try {
151151 value = JsonUtils .getString (json , "account.avatar.path" );
152- }catch (Exception e ) {
152+ } catch (Exception e ) {
153153 value = "/client/assets/images/default-avatar.png" ;
154154 }
155155 return baseUrl + value ;
@@ -176,8 +176,8 @@ public List<VideoStream> getVideoStreams() throws IOException, ExtractionExcepti
176176 List <VideoStream > videoStreams = new ArrayList <>();
177177 try {
178178 JsonArray streams = json .getArray ("files" , new JsonArray ());
179- for (Object s : streams ) {
180- if (!(s instanceof JsonObject )) continue ;
179+ for (Object s : streams ) {
180+ if (!(s instanceof JsonObject )) continue ;
181181 JsonObject stream = (JsonObject ) s ;
182182 String url = JsonUtils .getString (stream , "fileUrl" );
183183 String torrentUrl = JsonUtils .getString (stream , "torrentUrl" );
@@ -211,8 +211,8 @@ public List<SubtitlesStream> getSubtitlesDefault() throws IOException, Extractio
211211 @ Override
212212 public List <SubtitlesStream > getSubtitles (final MediaFormat format ) throws IOException , ExtractionException {
213213 List <SubtitlesStream > filteredSubs = new ArrayList <>();
214- for (SubtitlesStream sub : subtitles ) {
215- if (sub .getFormat () == format ) {
214+ for (SubtitlesStream sub : subtitles ) {
215+ if (sub .getFormat () == format ) {
216216 filteredSubs .add (sub );
217217 }
218218 }
@@ -234,18 +234,18 @@ public StreamInfoItemsCollector getRelatedStreams() throws IOException, Extracti
234234 StreamInfoItemsCollector collector = new StreamInfoItemsCollector (getServiceId ());
235235 List <String > tags = getTags ();
236236 String apiUrl = null ;
237- if (!tags .isEmpty ()) {
237+ if (!tags .isEmpty ()) {
238238 apiUrl = getRelatedStreamsUrl (tags );
239-
240- }else {
239+
240+ } else {
241241 apiUrl = getUploaderUrl () + "/videos?start=0&count=8" ;
242242 }
243- if (!StringUtil .isBlank (apiUrl )) getStreamsFromApi (collector , apiUrl );
243+ if (!StringUtil .isBlank (apiUrl )) getStreamsFromApi (collector , apiUrl );
244244 return collector ;
245245 }
246246
247247 @ Override
248- public List <String > getTags (){
248+ public List <String > getTags () {
249249 try {
250250 return (List ) JsonUtils .getArray (json , "tags" );
251251 } catch (Exception e ) {
@@ -267,7 +267,7 @@ private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodin
267267 String url = baseUrl + PeertubeSearchQueryHandlerFactory .SEARCH_ENDPOINT ;
268268 StringBuilder params = new StringBuilder ();
269269 params .append ("start=0&count=8&sort=-createdAt" );
270- for (String tag : tags ) {
270+ for (String tag : tags ) {
271271 params .append ("&tagsOneOf=" );
272272 params .append (URLEncoder .encode (tag , "UTF-8" ));
273273 }
@@ -277,38 +277,38 @@ private String getRelatedStreamsUrl(List<String> tags) throws UnsupportedEncodin
277277 private void getStreamsFromApi (StreamInfoItemsCollector collector , String apiUrl ) throws ReCaptchaException , IOException , ParsingException {
278278 Response response = getDownloader ().get (apiUrl );
279279 JsonObject relatedVideosJson = null ;
280- if (null != response && !StringUtil .isBlank (response .responseBody ())) {
280+ if (null != response && !StringUtil .isBlank (response .responseBody ())) {
281281 try {
282282 relatedVideosJson = JsonParser .object ().from (response .responseBody ());
283283 } catch (JsonParserException e ) {
284284 throw new ParsingException ("Could not parse json data for related videos" , e );
285285 }
286286 }
287-
288- if (relatedVideosJson != null ) {
287+
288+ if (relatedVideosJson != null ) {
289289 collectStreamsFrom (collector , relatedVideosJson );
290290 }
291291 }
292-
292+
293293 private void collectStreamsFrom (StreamInfoItemsCollector collector , JsonObject json ) throws ParsingException {
294294 JsonArray contents ;
295295 try {
296296 contents = (JsonArray ) JsonUtils .getValue (json , "data" );
297- }catch (Exception e ) {
297+ } catch (Exception e ) {
298298 throw new ParsingException ("unable to extract related videos" , e );
299299 }
300-
301- for (Object c : contents ) {
302- if (c instanceof JsonObject ) {
300+
301+ for (Object c : contents ) {
302+ if (c instanceof JsonObject ) {
303303 final JsonObject item = (JsonObject ) c ;
304304 PeertubeStreamInfoItemExtractor extractor = new PeertubeStreamInfoItemExtractor (item , baseUrl );
305305 //do not add the same stream in related streams
306- if (!extractor .getUrl ().equals (getUrl ())) collector .commit (extractor );
306+ if (!extractor .getUrl ().equals (getUrl ())) collector .commit (extractor );
307307 }
308308 }
309-
309+
310310 }
311-
311+
312312
313313 @ Override
314314 public String getErrorMessage () {
@@ -318,12 +318,12 @@ public String getErrorMessage() {
318318 @ Override
319319 public void onFetchPage (Downloader downloader ) throws IOException , ExtractionException {
320320 Response response = downloader .get (getUrl ());
321- if (null != response && null != response .responseBody ()) {
321+ if (null != response && null != response .responseBody ()) {
322322 setInitialData (response .responseBody ());
323- }else {
323+ } else {
324324 throw new ExtractionException ("Unable to extract peertube channel data" );
325325 }
326-
326+
327327 loadSubtitles ();
328328 }
329329
@@ -333,24 +333,25 @@ private void setInitialData(String responseBody) throws ExtractionException {
333333 } catch (JsonParserException e ) {
334334 throw new ExtractionException ("Unable to extract peertube stream data" , e );
335335 }
336- if (null == json ) throw new ExtractionException ("Unable to extract peertube stream data" );
336+ if (null == json ) throw new ExtractionException ("Unable to extract peertube stream data" );
337337 PeertubeParsingHelper .validate (json );
338338 }
339-
339+
340340 private void loadSubtitles () {
341341 if (subtitles .isEmpty ()) {
342342 try {
343- Response response = getDownloader ().get (getUrl () + "/captions" );
343+ Response response = getDownloader ().get (getUrl () + "/captions" );
344344 JsonObject captionsJson = JsonParser .object ().from (response .responseBody ());
345345 JsonArray captions = JsonUtils .getArray (captionsJson , "data" );
346- for (Object c : captions ) {
347- if (c instanceof JsonObject ) {
348- JsonObject caption = (JsonObject )c ;
346+ for (Object c : captions ) {
347+ if (c instanceof JsonObject ) {
348+ JsonObject caption = (JsonObject ) c ;
349349 String url = baseUrl + JsonUtils .getString (caption , "captionPath" );
350350 String languageCode = JsonUtils .getString (caption , "language.id" );
351351 String ext = url .substring (url .lastIndexOf ("." ) + 1 );
352352 MediaFormat fmt = MediaFormat .getFromSuffix (ext );
353- if (fmt != null && languageCode != null ) subtitles .add (new SubtitlesStream (fmt , languageCode , url , false ));
353+ if (fmt != null && languageCode != null )
354+ subtitles .add (new SubtitlesStream (fmt , languageCode , url , false ));
354355 }
355356 }
356357 } catch (Exception e ) {
0 commit comments