|
@@ -0,0 +1,161 @@
|
|
|
+/*
|
|
|
+ * Copyright (C) 2018 iZc
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
+ */
|
|
|
+package de.nplusc.izc.izpl.plugins.extractor;
|
|
|
+
|
|
|
+import de.nplusc.izc.iZpl.API.FeaturePlugin;
|
|
|
+import de.nplusc.izc.iZpl.API.IZPLApi;
|
|
|
+import de.nplusc.izc.iZpl.API.PlayListEditAPI;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.RawPlayListFile;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
|
|
|
+import de.nplusc.izc.iZpl.Utils.shared.PLFileIO;
|
|
|
+import de.nplusc.izc.tools.IOtools.FileTK;
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author iZc <nplusc.de>
|
|
|
+ */
|
|
|
+public class Extractor implements FeaturePlugin
|
|
|
+{
|
|
|
+ private static final Logger l = LogManager.getLogger(Extractor.class.getName());
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void parseParameter(String param)
|
|
|
+ {
|
|
|
+ File base = new File(param);
|
|
|
+ String basePath = base.getAbsolutePath();
|
|
|
+ if(base.exists()&&base.isDirectory())
|
|
|
+ {
|
|
|
+ String iZplPath = PlayListEditAPI.getCurrentPlaylist();
|
|
|
+ File izplFile = new File(iZplPath);
|
|
|
+ String absoluteiZplPath = izplFile.getAbsolutePath();
|
|
|
+ String relativizediZplPath = FileTK.getRelativePath(absoluteiZplPath, basePath);
|
|
|
+ if(relativizediZplPath.equals(absoluteiZplPath)||relativizediZplPath.startsWith(".."))
|
|
|
+ {
|
|
|
+ l.error("IZPL-Folder not inside base folder. Cannot continue.");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ String targetDir = new File(".").getAbsolutePath();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ getCopyStepList(basePath, targetDir, absoluteiZplPath);
|
|
|
+ }
|
|
|
+ catch(InvalidPlayListFileException e)
|
|
|
+ {
|
|
|
+ l.error("Cannot continue, Invalid playlist file");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ l.error("Invalid path given for the plugin.");
|
|
|
+ }
|
|
|
+
|
|
|
+ //intentionally quick quitting since the statefile should never get changed
|
|
|
+ IZPLApi.quickQuitWithoutSaving();
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String,String> getCopyStepList(String baseDir,String targetDir,String startList) throws InvalidPlayListFileException
|
|
|
+ {
|
|
|
+ HashMap<String,String> results = new HashMap<>();
|
|
|
+ boolean moreToHandle = true;
|
|
|
+ List<String> processedRootPaths = new ArrayList<String>();
|
|
|
+ List<String> scheduledPaths = new ArrayList<>();
|
|
|
+ scheduledPaths.add(startList);
|
|
|
+ l.trace("basedir|targetDir|startList:{}|{}|{}",baseDir,targetDir,startList);
|
|
|
+ while(moreToHandle)
|
|
|
+ {
|
|
|
+ ArrayList<String> temp = new ArrayList(scheduledPaths);
|
|
|
+ scheduledPaths.clear(); //resetting for the second part of the loop;
|
|
|
+ moreToHandle=false;
|
|
|
+ for (String currentList : temp)
|
|
|
+ {
|
|
|
+ if(processedRootPaths.contains(currentList))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RawPlayListFile currentData = PLFileIO.readSingleList(currentList);
|
|
|
+ List<SinglePlayListItem> currentEntries = currentData.getData();
|
|
|
+ for (SinglePlayListItem currentEntry : currentEntries)
|
|
|
+ {
|
|
|
+ File newItem = new File(currentEntry.getPath());
|
|
|
+ if(currentEntry.isIncludeElement())
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean hasUserInterface()
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void openUserInterface()
|
|
|
+ {
|
|
|
+ return; //TODO UI?
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean requiresLoadedPlayList()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getPluginName()
|
|
|
+ {
|
|
|
+ return "Extractor";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initializePlugin()
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void prepareUpgrade()
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|