2021-09-27 17:45:14 +01:00
|
|
|
/*
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
|
|
|
package moe.nekojimi.musicsearcher;
|
|
|
|
|
2021-09-29 17:19:09 +01:00
|
|
|
import java.net.URL;
|
|
|
|
|
2021-09-27 17:45:14 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author jim
|
|
|
|
*/
|
2021-10-01 13:21:49 +01:00
|
|
|
public class Result implements Comparable<Result>
|
2021-09-29 17:19:09 +01:00
|
|
|
{
|
|
|
|
private URL link;
|
|
|
|
private String artist;
|
|
|
|
private String album;
|
|
|
|
private String title;
|
|
|
|
|
2021-10-01 13:21:49 +01:00
|
|
|
private String sourceName;
|
|
|
|
private String sourceAbbr;
|
|
|
|
|
|
|
|
private double score;
|
|
|
|
|
2021-09-29 17:19:09 +01:00
|
|
|
public URL getLink() {
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLink(URL link) {
|
|
|
|
this.link = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getArtist() {
|
|
|
|
return artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setArtist(String artist) {
|
|
|
|
this.artist = artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getAlbum() {
|
|
|
|
return album;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAlbum(String album) {
|
|
|
|
this.album = album;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTitle(String title) {
|
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
|
2021-10-01 13:21:49 +01:00
|
|
|
public String getSourceName()
|
|
|
|
{
|
|
|
|
return sourceName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSource(String name, String abbr)
|
|
|
|
{
|
|
|
|
sourceName = name;
|
|
|
|
sourceAbbr = abbr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSourceAbbr()
|
|
|
|
{
|
|
|
|
return sourceAbbr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getScore()
|
|
|
|
{
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScore(double score)
|
|
|
|
{
|
|
|
|
this.score = score;
|
|
|
|
}
|
|
|
|
|
2021-09-29 17:19:09 +01:00
|
|
|
@Override
|
2021-10-01 13:21:49 +01:00
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return "Result{" + "artist=" + artist + ", album=" + album + ", title=" + title + ", sourceAbbr=" + sourceAbbr + ", score=" + score + '}';
|
2021-09-29 17:19:09 +01:00
|
|
|
}
|
2021-09-30 17:05:59 +01:00
|
|
|
|
2021-10-01 13:21:49 +01:00
|
|
|
public void setAlbumArtist(String field)
|
2021-09-30 17:05:59 +01:00
|
|
|
{
|
|
|
|
// 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 + " ";
|
|
|
|
}
|
2021-10-01 13:21:49 +01:00
|
|
|
|
2021-09-30 17:05:59 +01:00
|
|
|
}
|
2021-10-01 13:21:49 +01:00
|
|
|
artist = artist.trim();
|
|
|
|
album = album.trim();
|
2021-09-30 17:05:59 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-01 13:21:49 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Result t)
|
|
|
|
{
|
|
|
|
return (int) Math.signum(score - t.score);
|
|
|
|
}
|
|
|
|
|
2021-09-27 17:45:14 +01:00
|
|
|
}
|