From fe210ad8d0d0c54f8a22b90db2ae4f22c79075b9 Mon Sep 17 00:00:00 2001 From: Nekojimi Date: Thu, 30 Sep 2021 17:05:59 +0100 Subject: [PATCH] Added initial support for parsing album-artist fields. --- .../moe/nekojimi/musicsearcher/Result.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/moe/nekojimi/musicsearcher/Result.java b/src/main/java/moe/nekojimi/musicsearcher/Result.java index d0d47f1..a046226 100644 --- a/src/main/java/moe/nekojimi/musicsearcher/Result.java +++ b/src/main/java/moe/nekojimi/musicsearcher/Result.java @@ -54,6 +54,33 @@ public class Result public String toString() { return "Result{" + "link=" + link + ", artist=" + artist + ", album=" + album + ", title=" + title + '}'; } + + public void setAlbumArtist(String field) + { +// System.out.println("Parsing album-artist: " + field); + String fieldLower = field.toLowerCase(); + if (fieldLower.contains("from") || field.toLowerCase().contains("by")) + { + artist = ""; + album = ""; + String[] words = field.split("\\s+"); + boolean readingArtist = false; + for (String word: words) + { + if (word.equals("from")) + readingArtist = false; + else if (word.equals("by")) + readingArtist = true; + else + { + if (readingArtist) + artist += word + " "; + else + album += word + " "; + } + } + } + } }