f50c04c828
build / build (push) Has been cancelled
- Renamed package from me.zacharias.chat to me.neurodock across all 8 modules - Updated Gradle group from me.zacharias.neurodock to me.neurodock - Updated README and other files to reflect new Gitea org URL (Chat_things → neurodock) Dev note: 95 files touched. The Great Refactor is complete, long may it rest.
58 lines
1.8 KiB
Java
58 lines
1.8 KiB
Java
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.nodes.Node;
|
|
import org.jsoup.nodes.TextNode;
|
|
import org.jsoup.select.Elements;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
public class LyricsFetch {
|
|
Pattern pattern = Pattern.compile("(?i)\\[(verse.*)|(chorus.*)|(bridge.*)|(outro.*)|(intro.*)]");
|
|
|
|
@Test
|
|
public void testFetchLyrics() throws Exception {
|
|
Document doc = Jsoup.connect("https://genius.com/Neuro-sama-life-lyrics")
|
|
.userAgent("Mozilla/5.0")
|
|
.get();
|
|
|
|
Elements containers = doc.select("div[data-lyrics-container=true]");
|
|
|
|
StringBuilder lyrics = new StringBuilder();
|
|
|
|
for (Element container : containers) {
|
|
for(Node n : container.childNodes())
|
|
{
|
|
if(n instanceof Element e) {
|
|
if (e.attribute("data-exclude-from-selection") != null && e.attr("data-exclude-from-selection").equals("true")) {
|
|
continue;
|
|
}
|
|
else if(e.tagName().equalsIgnoreCase("br"))
|
|
{
|
|
lyrics.append("\n");
|
|
}
|
|
else {
|
|
System.out.println(container.tagName());
|
|
String s = e.text();
|
|
lyrics.append(s.trim());
|
|
}
|
|
}
|
|
else if(n instanceof TextNode tn)
|
|
{
|
|
String s = tn.text();
|
|
if (!s.isBlank()) {
|
|
lyrics.append(s.trim());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
System.out.println(lyrics.toString());
|
|
assertNotNull(lyrics.toString());
|
|
|
|
}
|
|
}
|