Track: handle bad URLs better, properly serialise artist, allow for clearing input stream.
This commit is contained in:
parent
8f35828c84
commit
fd8cb9ebf0
|
@ -9,14 +9,13 @@ import com.amihaiemil.eoyaml.Yaml;
|
|||
import com.amihaiemil.eoyaml.YamlMapping;
|
||||
import com.amihaiemil.eoyaml.YamlSequence;
|
||||
import com.amihaiemil.eoyaml.YamlSequenceBuilder;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,31 +62,39 @@ public class Track implements Comparable<Track>
|
|||
.add("url", url.toExternalForm())
|
||||
.add("location", location.getAbsolutePath())
|
||||
.add("num", Integer.toString(number))
|
||||
.add("formats", build.build())
|
||||
// .add("formats", build.build())
|
||||
.add("artist", artist)
|
||||
// .add("requestedBy", requestedBy)
|
||||
// .add("requestedIn", requestedIn)
|
||||
.add("kept", Boolean.toString(kept))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Track fromYaml(YamlMapping map) throws MalformedURLException
|
||||
public static Track fromYaml(YamlMapping map)
|
||||
{
|
||||
Track track = new Track(new URL(map.string("url")), null);
|
||||
track.setArtist(map.string("artist"));
|
||||
track.setTitle(map.string("title"));
|
||||
track.setLocation(new File(map.string("location")));
|
||||
track.setNumber(map.integer("num"));
|
||||
track.setKept(Boolean.parseBoolean(map.string("kept")));
|
||||
try
|
||||
{
|
||||
Track track = new Track(new URL(map.string("url")), null);
|
||||
track.setArtist(map.string("artist"));
|
||||
track.setTitle(map.string("title"));
|
||||
track.setLocation(new File(map.string("location")));
|
||||
track.setNumber(map.integer("num"));
|
||||
track.setKept(Boolean.parseBoolean(map.string("kept")));
|
||||
// track.setRequestedBy(map.string("requestedBy"));
|
||||
// track.setRequestedIn(map.string("requestedIn"));
|
||||
|
||||
List<Format> formats = new ArrayList<>();
|
||||
YamlSequence formatSeq = map.yamlSequence("formats");
|
||||
for (int i = 0; i < formats.size(); i++)
|
||||
formats.add(Format.fromYaml(formatSeq.yamlMapping(i)));
|
||||
track.setFormats(formats);
|
||||
// List<Format> formats = new ArrayList<>();
|
||||
// YamlSequence formatSeq = map.yamlSequence("formats");
|
||||
// for (int i = 0; i < formats.size(); i++)
|
||||
// formats.add(Format.fromYaml(formatSeq.yamlMapping(i)));
|
||||
// track.setFormats(formats);
|
||||
|
||||
return track;
|
||||
return track;
|
||||
} catch (MalformedURLException ex)
|
||||
{
|
||||
Logger.getLogger(Track.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDownloaded()
|
||||
|
@ -152,6 +159,21 @@ public class Track implements Comparable<Track>
|
|||
this.inputStream = inputStream;
|
||||
}
|
||||
|
||||
void clearInputStream()
|
||||
{
|
||||
if (inputStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
inputStream.close();
|
||||
} catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(Track.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
inputStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
void delete()
|
||||
{
|
||||
if (location != null)
|
||||
|
|
Loading…
Reference in New Issue