|
@@ -35,9 +35,18 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
+import org.jaudiotagger.audio.AudioFile;
|
|
|
+import org.jaudiotagger.audio.AudioFileIO;
|
|
|
+import org.jaudiotagger.audio.exceptions.CannotReadException;
|
|
|
+import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
|
|
+import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
|
|
+import org.jaudiotagger.tag.FieldKey;
|
|
|
+import org.jaudiotagger.tag.Tag;
|
|
|
+import org.jaudiotagger.tag.TagException;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -60,6 +69,61 @@ public class PLFileIO
|
|
|
* /Pfad/zu/UnsplittbarerListe.iZpl
|
|
|
*/
|
|
|
|
|
|
+ public static RawPlayListFile readFolderAsVirtualPlayListFile(String path) throws InvalidPlayListFileException
|
|
|
+ {
|
|
|
+ l.trace("Parsing Folder {}.",path);
|
|
|
+ File f = new File(path);
|
|
|
+ File[] elements = f.listFiles();
|
|
|
+ List<PlayListItem> virtualList = new LinkedList<>();
|
|
|
+ for (File element : elements)
|
|
|
+ {
|
|
|
+ if(element.isDirectory())
|
|
|
+ {
|
|
|
+ SinglePlayListItem item = new SinglePlayListItem(element.getPath(), element.getName(), 1, true, false);
|
|
|
+ virtualList.add(item);
|
|
|
+ l.info("Added Folder ({}) as include element",element.getPath());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(element.isFile()&&!element.isHidden())
|
|
|
+ {
|
|
|
+
|
|
|
+ //TODO subfunction!
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //itm.setTitle("#EXTINF,0,"+new File(ln).getName());
|
|
|
+ AudioFile file = AudioFileIO.read(element);
|
|
|
+ int length = file.getAudioHeader().getTrackLength();
|
|
|
+ Tag tag = file.getTag();
|
|
|
+ String metadata = "#EXTINF,length,";
|
|
|
+ if(tag!=null)
|
|
|
+ {
|
|
|
+ metadata+= tag.getFirst(FieldKey.ARTIST)+" - "+tag.getFirst(FieldKey.TITLE);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ metadata+=element.getName();
|
|
|
+ }
|
|
|
+ SinglePlayListItem item = new SinglePlayListItem(element.getPath(), metadata, length);
|
|
|
+ l.trace("Added File ({})to the list.",element.getPath());
|
|
|
+ virtualList.add(item);
|
|
|
+ } catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException ex)
|
|
|
+ {
|
|
|
+ l.info("Skipped invalid File ({})",element.getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ l.info("Skipped File ({})due to being hidden",element.getPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//private static Yaml y = new Yaml();
|
|
|
private static final Logger l = LogManager.getLogger();
|
|
@@ -235,7 +299,7 @@ public class PLFileIO
|
|
|
{
|
|
|
if(!extinf)
|
|
|
{
|
|
|
- itm.setTitle("#EXTINF,0,"+new File(ln).getName());
|
|
|
+ itm.setTitle("#EXTINF,0,"+new File(ln).getName()); //TODO ID3parse
|
|
|
}
|
|
|
if(!(ln.substring(1).startsWith(":")||ln.startsWith(File.separator)))
|
|
|
{
|