Merges the two album tables into one.

Albums are independent of how the song is stored. We don't need to separate them.
This commit is contained in:
Markil3
2021-09-18 15:00:12 -06:00
parent 8bb7086a44
commit 2e2748f9e9
26 changed files with 2553 additions and 2576 deletions

View File

@@ -6,6 +6,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Optional;
import java.util.Properties;
public class ConfigManager
{
@@ -23,6 +32,13 @@ public class ConfigManager
private static File appDir;
private static File firefoxDir;
private static final File propsFile = new File(getConfigDir(), "config" +
".prop");
private static Properties props;
private static Path[] musicDirs;
private static Path[] musicIgnoreDirs;
/**
* Obtains the install directory for the application.
*
@@ -53,7 +69,8 @@ public class ConfigManager
}
else
{
firefoxDir = new File(firefoxDir.getParentFile().getParent(),
firefoxDir = new File(firefoxDir.getParentFile()
.getParent(),
"firefox");
if (firefoxDir.exists())
{
@@ -155,4 +172,141 @@ public class ConfigManager
}
return commDir;
}
/**
* Gets the properties file
*
* @return The settings contained within the properties object.
*/
public static Properties getProperties()
{
if (props == null)
{
Properties defaultProps = new Properties();
defaultProps.setProperty("musicInclude", System.getProperty("user" +
".home") + File.separator + "Music" + File.pathSeparator + System
.getProperty("user.home") + File.separator + "My Music");
defaultProps.setProperty("musicExclude", "");
props = new Properties(defaultProps);
if (propsFile.exists())
{
loadProperties();
}
else
{
saveProperties();
}
}
return props;
}
public static void loadProperties()
{
try
{
props.load(new FileReader(propsFile));
}
catch (IOException e)
{
logger.error("Error reading configuration file", e);
}
}
public static void saveProperties()
{
try
{
props.store(new FileWriter(propsFile), "Universal Music " +
"Player Properties");
}
catch (IOException e)
{
logger.error("Error writing configuration file", e);
}
}
/**
* Obtains folders to scan for music.
*
* @return A list of folders to pay attention to.
*/
public static Path[] getMusicDirs()
{
if (musicDirs == null)
{
musicDirs =
Optional.ofNullable(getProperties().getProperty(
"musicInclude"))
.map(s -> s.split(File.pathSeparator)).stream()
.flatMap(Arrays::stream)
.map(String::trim).map(Paths::get)
.sorted(Path::compareTo)
.toArray(Path[]::new);
}
return musicDirs;
}
/**
* Obtains folders to ignore when scanning for music.
*
* @return A list of folders to ignore.
*/
public static Path[] getMusicExcludeDirs()
{
if (musicIgnoreDirs == null)
{
musicIgnoreDirs =
Optional.ofNullable(getProperties().getProperty(
"musicExclude"))
.map(s -> s.split(File.pathSeparator)).stream()
.flatMap(Arrays::stream)
.map(String::trim).map(Paths::get)
.sorted(Path::compareTo)
.toArray(Path[]::new);
}
return musicIgnoreDirs;
}
/**
* Checks to see whether a file should be scanned.
*
* @param file - The file to scan.
* @return Whether or not a file is scanned.
*/
public static boolean scanFolder(Path file)
{
for (Path musicIgnoreDir : musicIgnoreDirs)
{
if (file.startsWith(musicIgnoreDir) || musicIgnoreDir
.endsWith(file))
{
/*
* Make sure that we don't have an include path that takes
* precedence. Working backwards from more specific paths is
* more likely to get our results faster.
*/
for (int j = musicDirs.length - 1; j >= 0; j--)
{
if (file.startsWith(musicDirs[j]) || musicDirs[j]
.endsWith(file))
{
return true;
}
}
return false;
}
}
/*
* Considering that there was nothing in the ignore list, look to
* make sure that we are allowed to scan it.
*/
for (Path musicDir : musicDirs)
{
if (file.startsWith(musicDir) || musicDir.endsWith(file))
{
return true;
}
}
return false;
}
}

View File

@@ -60,4 +60,14 @@ public class PlaybackInfo implements Serializable
{
return this.status;
}
@Override
public String toString()
{
return "PlaybackInfo{" +
"playTime=" + playTime +
", status=" + status +
", currentSong=" + currentSong +
'}';
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
*/
package edu.regis.universeplayer.browserCommands;
import java.net.URL;
import edu.regis.universeplayer.data.InternetSong;
/**
* Asks the browser for information on a certain song.
*
* @author William Hubbard
* @version 0.2
*/
public class QuerySongData implements BrowserQuery<InternetSong>
{
/**
* The song to get data for.
*/
private URL url;
/**
* For serialization only. Do not use.
*/
public QuerySongData()
{
}
/**
* Creates a song data request.
*
* @param url - The URL to request data for.
*/
public QuerySongData(URL url)
{
this.url = url;
}
/**
* Obtains the name of the command.
*
* @return The command name.
*/
@Override
public String getCommandName()
{
return "getSongData";
}
/**
* Obtains the type of value this command returns.
*
* @return The return type.
*/
@Override
public Class<InternetSong> getReturnType()
{
return InternetSong.class;
}
/**
* Gets the location of the song to query.
*
* @return The song location.
*/
public URL getUrl()
{
return this.url;
}
}

View File

@@ -24,11 +24,25 @@ public class Album implements Comparable<Album>
{
if (o != null && o.name != null)
{
return this.name.compareToIgnoreCase(o.name);
if (this.name == null)
{
return 1;
}
else
{
return this.name.compareToIgnoreCase(o.name);
}
}
else
{
return -1;
if (this.name == null)
{
return 0;
}
else
{
return -1;
}
}
}

View File

@@ -15,6 +15,10 @@ public class InternetSong extends Song
{
private static final Logger logger = LoggerFactory
.getLogger(InternetSong.class);
/**
* The location of the song.
*/
public URL location;
@Override
@@ -23,7 +27,7 @@ public class InternetSong extends Song
int compare = super.compareTo(o);
if (compare == 0)
{
if (o instanceof LocalSong)
if (o instanceof InternetSong)
{
try
{

View File

@@ -12,9 +12,23 @@ import java.util.Arrays;
*/
public class LocalSong extends Song
{
/**
* The file the song is stored at.
*/
public File file;
/**
* The format type the song is stored in.
*/
public String type;
/**
* The encoding format the song is recorded in.
*/
public String codec;
/**
* The last modification time of this song file, as returned by {@link
* File#lastModified()}.
*/
public long lastMod;
@Override
public int compareTo(Song o)

View File

@@ -12,10 +12,29 @@ import java.util.Arrays;
*/
public class Song implements Comparable<Song>, Serializable
{
/**
* The internal ID representing this song in the database.
*/
public int id;
/**
* The name of the song.
*/
public String title;
/**
* Artists who contributed to the song.
*/
public String[] artists;
/**
* Which track number in the album the song belongs to.
*/
public int trackNum;
/**
* Which disc
*/
public int disc;
/**
* How long the song is in milliseconds.
*/
public long duration;
/**