2020
2121import com .google .gson .Gson ;
2222import com .google .gson .GsonBuilder ;
23- // import java.io.BufferedReader ;
23+ import com . google . gson . JsonSyntaxException ;
2424import java .io .IOException ;
2525import java .net .URI ;
26- //import java.io.InputStreamReader;
27- //import java.io.OutputStreamWriter;
2826import java .util .Arrays ;
2927import java .net .URL ;
3028import java .net .URLEncoder ;
3129import java .net .http .HttpClient ;
32- //import java.net.HttpRequest;
3330import java .net .http .HttpResponse ;
3431import java .net .http .HttpResponse .BodyHandlers ;
3532import java .nio .charset .StandardCharsets ;
36- //import org.apache.http.HttpRequest;
3733import java .net .http .HttpRequest ;
3834import java .util .logging .Level ;
3935import java .util .logging .Logger ;
@@ -59,7 +55,7 @@ public class Leet {
5955 private static final String BASE_URL = "http://expectusafterlun.ch:5000/1337x" ;
6056 private String fullUrl ;
6157 private String json ;
62- private final int MAX_RESULTS = 5 ; //@TODO Use me
58+ private final int MAX_RESULTS = 3 ;
6359 private String query ;
6460 private final String API_KEY ;
6561 private final Config CONFIG ;
@@ -145,7 +141,7 @@ public Leet(final Config CONFIG, final String SEARCH) throws NullPointerExceptio
145141 // There is no CATEGORY. Search ALL.
146142 category = "" ;
147143 query = SEARCH ;
148- ex . printStackTrace ( );
144+ Logger . getLogger ( Leet . class . getName ()). log ( Level . SEVERE , null , ex );
149145 }
150146
151147 /**
@@ -242,20 +238,30 @@ public String getFormattedResult(final boolean HAS_COLORS) {
242238 gson = new GsonBuilder ().setPrettyPrinting ().create ();
243239 RESULTS = gson .fromJson (this .getJson (), LeetJsonItem [].class );
244240
245- } catch (IllegalStateException | NullPointerException ex ) {
246- ex .printStackTrace ();
247- return "" ;
241+ } catch (IllegalStateException | NullPointerException | JsonSyntaxException ex ) {
242+ Logger .getLogger (Leet .class .getName ()).log (Level .SEVERE , null , ex );
243+ json = "{ \" data\" : \" Unable to retrieve Torrent json data\" }" ;
244+ return json ;
248245 }
249246
250247 String output = "" ;
248+ int count = 0 ;
251249
252250 if (HAS_COLORS ) {
253251 for (LeetJsonItem result : RESULTS ) {
254252 output += result .getColorString ();
253+ count ++;
254+ if (MAX_RESULTS <= count ) {
255+ break ;
256+ }
255257 }
256258 } else {
257259 for (LeetJsonItem result : RESULTS ) {
258260 output += result .toString ();
261+ count ++;
262+ if (MAX_RESULTS <= count ) {
263+ break ;
264+ }
259265 }
260266 }
261267 return output ;
@@ -291,9 +297,9 @@ public class LeetJsonItem {
291297
292298 public String date ;
293299 public String href ;
294- public String leeches ;
300+ public int leeches ;
295301 public String name ;
296- public String seeds ;
302+ public int seeds ;
297303 public String size ;
298304 public String user ;
299305// public String tinyurl = "https://not.implemented.yet";
0 commit comments