From ca198a2e5d733155339bc25bd08695c3402329cd Mon Sep 17 00:00:00 2001 From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Sun, 31 Oct 2021 12:30:27 +0900 Subject: [PATCH] feat: added Album type fetch class --- src/com/ranfa/lib/Album.java | 21 +++++++++++++++++ src/com/ranfa/lib/AlbumTypeEstimate.java | 40 ++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/com/ranfa/lib/Album.java diff --git a/src/com/ranfa/lib/Album.java b/src/com/ranfa/lib/Album.java new file mode 100644 index 0000000..637c308 --- /dev/null +++ b/src/com/ranfa/lib/Album.java @@ -0,0 +1,21 @@ +package com.ranfa.lib; + +public class Album { + + private String songName; + private String albumType; + + public String getSongName() { + return songName; + } + public void setSongName(String songName) { + this.songName = songName; + } + public String getAlbumType() { + return albumType; + } + public void setAlbumType(String albumType) { + this.albumType = albumType; + } + +} diff --git a/src/com/ranfa/lib/AlbumTypeEstimate.java b/src/com/ranfa/lib/AlbumTypeEstimate.java index d9fb834..4df9aac 100644 --- a/src/com/ranfa/lib/AlbumTypeEstimate.java +++ b/src/com/ranfa/lib/AlbumTypeEstimate.java @@ -1,7 +1,9 @@ package com.ranfa.lib; import java.io.IOException; -import java.util.Map; +import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -21,19 +23,47 @@ public class AlbumTypeEstimate { ALBUM_C }; - public static Map getLastModified() { + public enum MASTERPLUS_TYPE { + //新MASTER+ + NEWMASTERPLUS, + //旧MASTER+ + LEGACYMASTERPLUS + } + + public static ArrayList> getAlbumType() { long time = System.currentTimeMillis(); + ArrayList> res = new ArrayList>(); try { Document document = Jsoup.connect(ALBUM_DATA_URI) .userAgent("Java/DelesteRandomSelector More Information is available at https://github.com/hizumiaoba/DeresteRandomSelector/") .maxBodySize(0) .timeout(0) .get(); - Elements elements = document.head().getElementsByAttribute("Last-Modified"); - } catch (IOException e) { - // TODO 自動生成された catch ブロック + Elements elements = document.getElementsByTag("tbody"); + Elements newMasterPlus = elements.get(4).select("tr"); + Elements legacyMasterPlus = elements.get(5).select("tr"); + CompletableFuture> fetchNew = CompletableFuture.supplyAsync(() -> fetch(newMasterPlus)); + CompletableFuture> fetchLegacy = CompletableFuture.supplyAsync(() -> fetch(legacyMasterPlus)); + res.add(fetchNew.get()); + res.add(fetchLegacy.get()); + } catch (IOException | InterruptedException | ExecutionException e) { e.printStackTrace(); } + LimitedLog.println(AlbumTypeEstimate.class + ":[INFO]: " + "Album type fetched in " + (System.currentTimeMillis() - time) + "ms"); + return res; } + private static ArrayList fetch(Elements elements) { + ArrayList res = new ArrayList<>(); + elements.stream() + .forEach(element -> { + String type = element.select("td").get(0).text().isEmpty() ? "Not-implemented" : element.select("td").get(0).text(); + String songName = element.select("td").get(2).text(); + Album tmp = new Album(); + tmp.setSongName(songName); + tmp.setAlbumType(type); + res.add(tmp); + }); + return res; + } } -- 2.11.0