|
@@ -1,237 +1,242 @@
|
|
|
-/*
|
|
|
- * To change this template, choose Tools | Templates
|
|
|
- * and open the template in the editor.
|
|
|
- */
|
|
|
-package de.nplusc.izc.iZpl.API;
|
|
|
-
|
|
|
-import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
|
|
|
-import de.nplusc.izc.iZpl.API.shared.PlayListItem;
|
|
|
-import de.nplusc.izc.iZpl.API.shared.MultiPlayListItem;
|
|
|
-import de.nplusc.izc.iZpl.Main;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
-import org.yaml.snakeyaml.Yaml;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author LH
|
|
|
- */
|
|
|
-public class PlayListEditAPI
|
|
|
-{
|
|
|
- private static final Logger l = LogManager.getLogger();
|
|
|
- private static Map<Integer,Integer> sortRemap = new HashMap<>();
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- public static enum SortMode{
|
|
|
- DEFAULT,
|
|
|
- NAME,
|
|
|
- PLAYCOUNT,
|
|
|
- MAXPLAYCOUNT;
|
|
|
- }
|
|
|
-
|
|
|
- private static SortMode m = SortMode.DEFAULT;
|
|
|
-
|
|
|
- /*
|
|
|
- public static void initPPP(PlProcessorV2 p)
|
|
|
- {
|
|
|
- iPPP = p;
|
|
|
- }*/
|
|
|
-
|
|
|
- private static List<String> playListItemKeys = new ArrayList<>();//wird genutzt um idx auf hasmap zu linkern
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * reloads the data from the Playlist managment. Use after any change
|
|
|
- */
|
|
|
- public static void refreshKeyList()
|
|
|
- {
|
|
|
-
|
|
|
- HashMap<String,PlayListItem> pool = Main.getPLServer().getPlProcessorV2().getPool();
|
|
|
- playListItemKeys = new ArrayList<>();//Liste flushen
|
|
|
- for (String k : pool.keySet())
|
|
|
- {
|
|
|
- playListItemKeys.add(k);
|
|
|
- }
|
|
|
- l.trace("SortMode="+m);
|
|
|
- if(m!=SortMode.DEFAULT)
|
|
|
- {
|
|
|
- l.trace("Re-ordering....");
|
|
|
- PlayListItem[] internalList = new PlayListItem[playListItemKeys.size()];
|
|
|
- for (int i = 0; i < playListItemKeys.size(); i++)
|
|
|
- {
|
|
|
- internalList[i] = pool.get(playListItemKeys.get(i));
|
|
|
- }
|
|
|
- l.trace("InternalList = "+new Yaml().dump(internalList));
|
|
|
- Arrays.sort(internalList, (PlayListItem o1, PlayListItem o2) ->
|
|
|
- {
|
|
|
- if(m==SortMode.NAME)
|
|
|
- {
|
|
|
- l.trace("Sorter: namesort");
|
|
|
- if(o1 instanceof MultiPlayListItem&&!(o2 instanceof MultiPlayListItem))
|
|
|
- {
|
|
|
- l.trace("Sorter: Multi_single:1");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else if(o2 instanceof MultiPlayListItem&&!(o1 instanceof MultiPlayListItem))
|
|
|
- {
|
|
|
- l.trace("Sorter: single_multi:-1");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- else if(o1 instanceof MultiPlayListItem&&(o2 instanceof MultiPlayListItem))
|
|
|
- {
|
|
|
- int r=o1.getM3UElement().trim().compareToIgnoreCase(o2.getM3UElement().trim());
|
|
|
- r=r>0?1:r<0?-1:0;//Fuckyou string.compare
|
|
|
- l.trace("Sorter: Multi_multi:"+r);
|
|
|
- return r;
|
|
|
- }
|
|
|
- else
|
|
|
- { //denk an die API oder es hagelt mysteryerrors
|
|
|
- String t1=((SinglePlayListItem)o1).getTitle().split(",")[1].trim();
|
|
|
- String t2=((SinglePlayListItem)o2).getTitle().split(",")[1].trim();
|
|
|
- int r=t1.compareToIgnoreCase(t2);
|
|
|
- r=r>0?1:r<0?-1:0;
|
|
|
- l.trace("Sorter: single_single:"+r+"\ncomparing"+t1+" and "+t2+"\n");
|
|
|
- return r;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int o1c=0,o2c=0;
|
|
|
- if(m==SortMode.PLAYCOUNT)
|
|
|
- {
|
|
|
- o1c=o1.getCountPlayed();
|
|
|
- o2c=o2.getCountPlayed();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- o1c=o1.getTargetPlaycount();
|
|
|
- o2c=o2.getTargetPlaycount();
|
|
|
- }
|
|
|
- return o1c>o2c?1:o1c<o2c?-1:0;
|
|
|
- }
|
|
|
- });
|
|
|
- l.trace("InternalList2 = "+new Yaml().dump(internalList));
|
|
|
- playListItemKeys = new ArrayList<>();//Liste nochmal flushen zum neu befüllen
|
|
|
- for (PlayListItem playListItem : internalList)
|
|
|
- {
|
|
|
- playListItemKeys.add(playListItem.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * obtains the listing of the track titles
|
|
|
- * @return Array with the list ordered in the internal ordering
|
|
|
- */
|
|
|
- public static String[] getTrackTitles()
|
|
|
- {
|
|
|
- String[] tt = new String[playListItemKeys.size()];
|
|
|
- for (int i=0;i<playListItemKeys.size();i++)
|
|
|
- {
|
|
|
- String k=playListItemKeys.get(i);
|
|
|
- PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
- if(x instanceof MultiPlayListItem)
|
|
|
- {
|
|
|
- tt[i] = ((MultiPlayListItem)x).getSrc();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- String t = ((SinglePlayListItem) x).getTitle();
|
|
|
- if(t!=null && !t.equals(""))
|
|
|
- {
|
|
|
- tt[i] = t.split(",")[1];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tt[i] =((SinglePlayListItem) x).getPath();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return tt;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Obtains the playcount of the track with the given ID
|
|
|
- * @param id Position in the track list obtained with getTrackTitles()
|
|
|
- * @return playcount of that track
|
|
|
- */
|
|
|
- public static int getPlayCount(int id)
|
|
|
- {
|
|
|
- String k=playListItemKeys.get(id);
|
|
|
- PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
- return x.getCountPlayed();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Obtains the playcount of the track with the given ID
|
|
|
- * @param id Position in the track list obtained with getTrackTitles()
|
|
|
- * @return Maximum amount before it is not played until all are fully played
|
|
|
- */
|
|
|
- public static int getTargetPlayCount(int id)
|
|
|
- {
|
|
|
- String k=playListItemKeys.get(id);
|
|
|
- PlayListItem x =Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
- return x.getTargetPlaycount();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the target playcount for the given title
|
|
|
- * @param id Position in the track list obtained with getTrackTitles()
|
|
|
- * @param tpc target amount to use
|
|
|
- */
|
|
|
- public static void setTargetPlayCount(int id,int tpc)
|
|
|
- {
|
|
|
- String k=playListItemKeys.get(id);
|
|
|
- PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
- int c = x.getCountPlayed();
|
|
|
- if(c>=tpc)
|
|
|
- {
|
|
|
- tpc=c+1;
|
|
|
- }
|
|
|
- x.setTargetPlaycount(tpc);
|
|
|
- Main.getPLServer().getPlProcessorV2().rebuildCache();//falls ein lied schon verbraucht ist; da es dann wieder playready ist uss der cache resetted werden...
|
|
|
- }
|
|
|
- /**
|
|
|
- * causes a reload of the Playlists from disk
|
|
|
- */
|
|
|
- public static void reloadList()
|
|
|
- {
|
|
|
- Main.getPLServer().getPlProcessorV2().reloadLists(true);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the SortMode that should be used from now on @ the list
|
|
|
- * @param mode SortMode to use
|
|
|
- */
|
|
|
- public static void setSortMode(SortMode mode)
|
|
|
- {
|
|
|
- m = mode;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the element with the given ID as guaranteed to play as next track
|
|
|
- * @param id Position in the track list obtained with getTrackTitles()
|
|
|
- */
|
|
|
- public static void forceElement(int id)
|
|
|
- {
|
|
|
-
|
|
|
- Main.getPLServer().getPlProcessorV2().addElementToForcedList(
|
|
|
- Main.getPLServer().getPlProcessorV2().getPool().get(playListItemKeys.get(id)));
|
|
|
- }
|
|
|
-
|
|
|
- private PlayListEditAPI()
|
|
|
- {
|
|
|
- }
|
|
|
-}
|
|
|
+/*
|
|
|
+ * To change this template, choose Tools | Templates
|
|
|
+ * and open the template in the editor.
|
|
|
+ */
|
|
|
+package de.nplusc.izc.iZpl.API;
|
|
|
+
|
|
|
+import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.PlayListItem;
|
|
|
+import de.nplusc.izc.iZpl.API.shared.MultiPlayListItem;
|
|
|
+import de.nplusc.izc.iZpl.Main;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+import org.yaml.snakeyaml.Yaml;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author LH
|
|
|
+ */
|
|
|
+public class PlayListEditAPI
|
|
|
+{
|
|
|
+ private static final Logger l = LogManager.getLogger();
|
|
|
+ private static Map<Integer,Integer> sortRemap = new HashMap<>();
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static enum SortMode{
|
|
|
+ DEFAULT,
|
|
|
+ NAME,
|
|
|
+ PLAYCOUNT,
|
|
|
+ MAXPLAYCOUNT;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SortMode m = SortMode.DEFAULT;
|
|
|
+
|
|
|
+ /*
|
|
|
+ public static void initPPP(PlProcessorV2 p)
|
|
|
+ {
|
|
|
+ iPPP = p;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ private static List<String> playListItemKeys = new ArrayList<>();//wird genutzt um idx auf hasmap zu linkern
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * reloads the data from the Playlist managment. Use after any change
|
|
|
+ */
|
|
|
+ public static void refreshKeyList()
|
|
|
+ {
|
|
|
+
|
|
|
+ HashMap<String,PlayListItem> pool = Main.getPLServer().getPlProcessorV2().getPool();
|
|
|
+ playListItemKeys = new ArrayList<>();//Liste flushen
|
|
|
+ for (String k : pool.keySet())
|
|
|
+ {
|
|
|
+ playListItemKeys.add(k);
|
|
|
+ }
|
|
|
+ l.trace("SortMode="+m);
|
|
|
+ if(m!=SortMode.DEFAULT)
|
|
|
+ {
|
|
|
+ l.trace("Re-ordering....");
|
|
|
+ PlayListItem[] internalList = new PlayListItem[playListItemKeys.size()];
|
|
|
+ for (int i = 0; i < playListItemKeys.size(); i++)
|
|
|
+ {
|
|
|
+ internalList[i] = pool.get(playListItemKeys.get(i));
|
|
|
+ }
|
|
|
+ l.trace("InternalList = "+new Yaml().dump(internalList));
|
|
|
+ Arrays.sort(internalList, (PlayListItem o1, PlayListItem o2) ->
|
|
|
+ {
|
|
|
+ if(m==SortMode.NAME)
|
|
|
+ {
|
|
|
+ l.trace("Sorter: namesort");
|
|
|
+ if(o1 instanceof MultiPlayListItem&&!(o2 instanceof MultiPlayListItem))
|
|
|
+ {
|
|
|
+ l.trace("Sorter: Multi_single:1");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else if(o2 instanceof MultiPlayListItem&&!(o1 instanceof MultiPlayListItem))
|
|
|
+ {
|
|
|
+ l.trace("Sorter: single_multi:-1");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ else if(o1 instanceof MultiPlayListItem&&(o2 instanceof MultiPlayListItem))
|
|
|
+ {
|
|
|
+ int r=o1.getM3UElement().trim().compareToIgnoreCase(o2.getM3UElement().trim());
|
|
|
+ r=r>0?1:r<0?-1:0;//Fuckyou string.compare
|
|
|
+ l.trace("Sorter: Multi_multi:"+r);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { //denk an die API oder es hagelt mysteryerrors
|
|
|
+ String t1=((SinglePlayListItem)o1).getTitle().split(",")[1].trim();
|
|
|
+ String t2=((SinglePlayListItem)o2).getTitle().split(",")[1].trim();
|
|
|
+ int r=t1.compareToIgnoreCase(t2);
|
|
|
+ r=r>0?1:r<0?-1:0;
|
|
|
+ l.trace("Sorter: single_single:"+r+"\ncomparing"+t1+" and "+t2+"\n");
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int o1c=0,o2c=0;
|
|
|
+ if(m==SortMode.PLAYCOUNT)
|
|
|
+ {
|
|
|
+ o1c=o1.getCountPlayed();
|
|
|
+ o2c=o2.getCountPlayed();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ o1c=o1.getTargetPlaycount();
|
|
|
+ o2c=o2.getTargetPlaycount();
|
|
|
+ }
|
|
|
+ return o1c>o2c?1:o1c<o2c?-1:0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ l.trace("InternalList2 = "+new Yaml().dump(internalList));
|
|
|
+ playListItemKeys = new ArrayList<>();//Liste nochmal flushen zum neu befüllen
|
|
|
+ for (PlayListItem playListItem : internalList)
|
|
|
+ {
|
|
|
+ playListItemKeys.add(playListItem.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * obtains the listing of the track titles
|
|
|
+ * @return Array with the list ordered in the internal ordering
|
|
|
+ */
|
|
|
+ public static String[] getTrackTitles()
|
|
|
+ {
|
|
|
+ String[] tt = new String[playListItemKeys.size()];
|
|
|
+ for (int i=0;i<playListItemKeys.size();i++)
|
|
|
+ {
|
|
|
+ String k=playListItemKeys.get(i);
|
|
|
+ PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
+ if(x==null)
|
|
|
+ {
|
|
|
+ Main.getPLServer().getPlProcessorV2().getPool().remove(k);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(x instanceof MultiPlayListItem)
|
|
|
+ {
|
|
|
+ tt[i] = ((MultiPlayListItem)x).getSrc();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ String t = ((SinglePlayListItem) x).getTitle();
|
|
|
+ if(t!=null && !t.equals(""))
|
|
|
+ {
|
|
|
+ tt[i] = t.split(",")[1];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tt[i] =((SinglePlayListItem) x).getPath();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tt;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Obtains the playcount of the track with the given ID
|
|
|
+ * @param id Position in the track list obtained with getTrackTitles()
|
|
|
+ * @return playcount of that track
|
|
|
+ */
|
|
|
+ public static int getPlayCount(int id)
|
|
|
+ {
|
|
|
+ String k=playListItemKeys.get(id);
|
|
|
+ PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
+ return x.getCountPlayed();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Obtains the playcount of the track with the given ID
|
|
|
+ * @param id Position in the track list obtained with getTrackTitles()
|
|
|
+ * @return Maximum amount before it is not played until all are fully played
|
|
|
+ */
|
|
|
+ public static int getTargetPlayCount(int id)
|
|
|
+ {
|
|
|
+ String k=playListItemKeys.get(id);
|
|
|
+ PlayListItem x =Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
+ return x.getTargetPlaycount();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the target playcount for the given title
|
|
|
+ * @param id Position in the track list obtained with getTrackTitles()
|
|
|
+ * @param tpc target amount to use
|
|
|
+ */
|
|
|
+ public static void setTargetPlayCount(int id,int tpc)
|
|
|
+ {
|
|
|
+ String k=playListItemKeys.get(id);
|
|
|
+ PlayListItem x = Main.getPLServer().getPlProcessorV2().getPool().get(k);
|
|
|
+ int c = x.getCountPlayed();
|
|
|
+ if(c>=tpc)
|
|
|
+ {
|
|
|
+ tpc=c+1;
|
|
|
+ }
|
|
|
+ x.setTargetPlaycount(tpc);
|
|
|
+ Main.getPLServer().getPlProcessorV2().rebuildCache();//falls ein lied schon verbraucht ist; da es dann wieder playready ist uss der cache resetted werden...
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * causes a reload of the Playlists from disk
|
|
|
+ */
|
|
|
+ public static void reloadList()
|
|
|
+ {
|
|
|
+ Main.getPLServer().getPlProcessorV2().reloadLists(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the SortMode that should be used from now on @ the list
|
|
|
+ * @param mode SortMode to use
|
|
|
+ */
|
|
|
+ public static void setSortMode(SortMode mode)
|
|
|
+ {
|
|
|
+ m = mode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the element with the given ID as guaranteed to play as next track
|
|
|
+ * @param id Position in the track list obtained with getTrackTitles()
|
|
|
+ */
|
|
|
+ public static void forceElement(int id)
|
|
|
+ {
|
|
|
+
|
|
|
+ Main.getPLServer().getPlProcessorV2().addElementToForcedList(
|
|
|
+ Main.getPLServer().getPlProcessorV2().getPool().get(playListItemKeys.get(id)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private PlayListEditAPI()
|
|
|
+ {
|
|
|
+ }
|
|
|
+}
|