21
21
import java .util .stream .StreamSupport ;
22
22
23
23
import static java .lang .String .format ;
24
+ import static java .nio .file .Files .createSymbolicLink ;
24
25
import static org .hydev .mcpm .Constants .JACKSON ;
25
26
import static org .hydev .mcpm .utils .GeneralUtils .makeUrl ;
26
27
33
34
public class SpigetCrawler
34
35
{
35
36
private final String spiget = "https://api.spiget.org/v2" ;
36
- private final String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" ;
37
+ private final String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
38
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" ;
37
39
private final long mtDelay = 1000 ;
38
40
private final File dataDir ;
39
41
private final StoredHashMap <Long , String > blacklist ;
@@ -56,15 +58,17 @@ private List<JsonNode> crawlResourcesPage(long i)
56
58
{
57
59
// Send request
58
60
var resp = Request .get (makeUrl (spiget + "/resources" , "size" , 500 , "sort" , "+id" , "page" , i ,
59
- "fields" , "id,name,tag,external,likes,testedVersions,links,contributors,premium,price,currency,version,releaseDate,updateDate,downloads,existenceStatus" ))
61
+ "fields" , "id,name,tag,external,likes,testedVersions,links,contributors,premium," +
62
+ "price,currency,version,releaseDate,updateDate,downloads,existenceStatus" ))
60
63
.addHeader ("User-Agent" , userAgent ).execute ().returnContent ().asString ();
61
64
62
65
// Parse JSON
63
66
ArrayNode page = (ArrayNode ) JACKSON .readTree (resp );
64
67
65
68
// Print debug info
66
69
if (!page .isEmpty ())
67
- System .out .printf ("Page %s done, page len: %s, last id: %s\n " , i , page .size (), page .get (page .size () - 1 ).get ("id" ).asLong ());
70
+ System .out .printf ("Page %s done, page len: %s, last id: %s\n " ,
71
+ i , page .size (), page .get (page .size () - 1 ).get ("id" ).asLong ());
68
72
else
69
73
System .out .printf ("Page %s is empty\n " , i );
70
74
@@ -268,7 +272,7 @@ public void links()
268
272
269
273
// Create new link
270
274
linkPath .getParentFile ().mkdirs ();
271
- Files . createSymbolicLink (linkPath .toPath (), linkPath .getParentFile ().toPath ().relativize (ver .toPath ()));
275
+ createSymbolicLink (linkPath .toPath (), linkPath .getParentFile ().toPath ().relativize (ver .toPath ()));
272
276
}
273
277
catch (IOException e )
274
278
{
@@ -280,6 +284,11 @@ public void links()
280
284
});
281
285
}
282
286
287
+ /**
288
+ * Execute server crawler
289
+ *
290
+ * @param args Arguments (Unused)
291
+ */
283
292
public static void main (String [] args )
284
293
{
285
294
var crawler = new SpigetCrawler (new File (".mcpm" ));
0 commit comments