3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.concurrent.CompletableFuture;
6 import java.util.concurrent.ExecutionException;
7 import java.util.concurrent.ExecutorService;
8 import java.util.concurrent.Executors;
10 import org.jsoup.Jsoup;
11 import org.jsoup.nodes.Document;
12 import org.jsoup.select.Elements;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 import com.ranfa.lib.concurrent.CountedThreadFactory;
18 public class AlbumTypeEstimate {
20 public final static String ALBUM_DATA_URI = "https://imascg-slstage-wiki.gamerch.com/%E6%A5%BD%E6%9B%B2%E8%A9%B3%E7%B4%B0%E4%B8%80%E8%A6%A7%EF%BC%88%E9%9B%A3%E6%98%93%E5%BA%A6%E5%88%A5%EF%BC%89";
21 private static ExecutorService executor = Executors.newCachedThreadPool(new CountedThreadFactory(() -> "DRS", "AlbumEstimateThread"));
22 private static Logger logger = LoggerFactory.getLogger(AlbumTypeEstimate.class);
25 public enum ALBUM_TYPE {
34 public enum MASTERPLUS_TYPE {
41 public static ArrayList<ArrayList<Album>> getAlbumType() {
42 long time = System.currentTimeMillis();
43 ArrayList<ArrayList<Album>> res = new ArrayList<>();
45 Document document = Jsoup.connect(ALBUM_DATA_URI)
46 .userAgent("Java/DelesteRandomSelector More Information is available at https://github.com/hizumiaoba/DeresteRandomSelector/")
50 Elements elements = document.getElementsByTag("tbody");
51 Elements newMasterPlus = elements.get(4).select("tr");
52 Elements legacyMasterPlus = elements.get(5).select("tr");
53 CompletableFuture<ArrayList<Album>> fetchNew = CompletableFuture.supplyAsync(() -> fetch(newMasterPlus), executor);
54 CompletableFuture<ArrayList<Album>> fetchLegacy = CompletableFuture.supplyAsync(() -> fetch(legacyMasterPlus), executor);
55 res.add(fetchNew.get());
56 res.add(fetchLegacy.get());
57 } catch (IOException | InterruptedException | ExecutionException e) {
58 logger.warn("Exception was thrown while fetching Album type.", e);
60 logger.info("Album type fetched in {} ms", (System.currentTimeMillis() - time));
64 private static ArrayList<Album> fetch(Elements elements) {
65 ArrayList<Album> res = new ArrayList<>();
68 String type = element.select("td").get(0).text().isEmpty() ? "Not-implemented" : element.select("td").get(0).text();
69 String songName = element.select("td").get(2).text();
70 Album tmp = new Album();
71 tmp.setSongName(songName);
72 tmp.setAlbumType(type);