summaryrefslogtreecommitdiff
path: root/cmpcj/src/de/schwarzrot/media
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-08-15 07:55:07 +0200
committergeronimo <geronimo013@gmx.de>2012-08-15 07:55:07 +0200
commitaf80bd2426282b7491d9ba0ebfb201abb42e3ca4 (patch)
tree8aeac09a815f3133773cb927597738d4150030f1 /cmpcj/src/de/schwarzrot/media
parent7eb41fd1431019f44227af6f5d707e7c98e0416e (diff)
downloadcmp-af80bd2426282b7491d9ba0ebfb201abb42e3ca4.tar.gz
cmp-af80bd2426282b7491d9ba0ebfb201abb42e3ca4.tar.bz2
next variant of java client
Diffstat (limited to 'cmpcj/src/de/schwarzrot/media')
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/AbstractMediaNode.java249
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Audio.java72
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Config.java128
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/DVDImage.java47
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Genre.java121
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/LegacyVdrRecording.java39
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Media.java55
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/MediaServer.java57
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/MediaType.java55
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Movie.java88
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/Picture.java78
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/PlayList.java70
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/PlayerDefinition.java115
-rw-r--r--cmpcj/src/de/schwarzrot/media/domain/VdrRecording.java67
-rw-r--r--cmpcj/src/de/schwarzrot/media/service/DataManager.java152
-rw-r--r--cmpcj/src/de/schwarzrot/media/service/MediaExecutor.java58
-rw-r--r--cmpcj/src/de/schwarzrot/media/service/MediaFactory.java137
-rw-r--r--cmpcj/src/de/schwarzrot/media/util/ElementConsumer.java31
-rw-r--r--cmpcj/src/de/schwarzrot/media/util/ListLoader.java34
-rw-r--r--cmpcj/src/de/schwarzrot/media/util/MedialistParser.java169
20 files changed, 1822 insertions, 0 deletions
diff --git a/cmpcj/src/de/schwarzrot/media/domain/AbstractMediaNode.java b/cmpcj/src/de/schwarzrot/media/domain/AbstractMediaNode.java
new file mode 100644
index 0000000..573726c
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/AbstractMediaNode.java
@@ -0,0 +1,249 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AbstractMediaNode.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Map;
+import java.util.TreeMap;
+
+
+public abstract class AbstractMediaNode implements Serializable, Comparable<AbstractMediaNode> {
+ public static final String FORMAT_PROPERTY = "format";
+ public static final String NAME_PROPERTY = "name";
+ public static final String PATH_PROPERTY = "path";
+ public static final String TYPE_PROPERTY = "type";
+ public static final String SEARCH_PROPERTY = "search";
+ private static final long serialVersionUID = 713L;
+ public enum SupportedMediaType {
+ Genre, //
+ Audio, //
+ Movie, IMovie, DVDImage, IDVDImage, //
+ LegacyVdrRecording, ILegacyVdrRecording, VdrRecording, IVdrRecording, //
+ Picture, //
+ Unknown
+ }
+
+
+ protected AbstractMediaNode(AbstractMediaNode parent, SupportedMediaType type, String mimeType, File path) {
+ properties = new TreeMap<String, Object>();
+ setParent(parent);
+ setType(type);
+ setMimeType(mimeType);
+ setRealPath(path);
+ originalPath = realPath;
+ }
+
+
+ @Override
+ public int compareTo(AbstractMediaNode o) {
+ if (o == null)
+ return -1;
+
+ if (this != o) {
+ int rv = type.ordinal() - o.getType().ordinal();
+
+ if (rv == 0)
+ rv = getName().compareToIgnoreCase(o.getName());
+
+ return rv;
+ }
+ return 0;
+ }
+
+
+ public String getFormat() {
+ return format;
+ }
+
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public File getOriginalPath() {
+ return originalPath;
+ }
+
+
+ public AbstractMediaNode getParent() {
+ return parent;
+ }
+
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+
+ public File getRealPath() {
+ return realPath;
+ }
+
+
+ public String getSearch() {
+ return search;
+ }
+
+
+ public SupportedMediaType getType() {
+ return type;
+ }
+
+
+ public URI getURI() {
+ return uri;
+ }
+
+
+ public void setFormat(String format) {
+ this.format = format;
+ properties.put(FORMAT_PROPERTY, format);
+ }
+
+
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ properties.put(NAME_PROPERTY, name);
+ }
+
+
+ public void setParent(AbstractMediaNode parent) {
+ if ((this.parent = parent) != null)
+ refresh();
+ }
+
+
+ public void setPath(String path) {
+ if (uri == null) {
+ try {
+ // properties.put(PATH_PROPERTY, path);
+ uri = new URI(path);
+ properties.put(PATH_PROPERTY, uri.toString());
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ File tmp = new File(URLDecoder.decode(path, "UTF-8"));
+
+ if (path != null && originalPath == null)
+ originalPath = tmp;
+ setRealPath(tmp);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+
+ public void setProperty(String key, Object value) {
+ properties.put(key, value);
+ }
+
+
+ public void setRealPath(File realPath) {
+ this.realPath = realPath;
+ if (name == null && realPath != null)
+ setName(realPath.getName());
+ }
+
+
+ public void setSearch(String search) {
+ this.search = search;
+ properties.put(SEARCH_PROPERTY, search);
+ }
+
+
+ public void setType(int type) {
+ if (type == SupportedMediaType.Audio.ordinal())
+ this.type = SupportedMediaType.Audio;
+ else if (type == SupportedMediaType.Movie.ordinal())
+ this.type = SupportedMediaType.Movie;
+ else if (type == SupportedMediaType.IMovie.ordinal())
+ this.type = SupportedMediaType.IMovie;
+ else if (type == SupportedMediaType.DVDImage.ordinal())
+ this.type = SupportedMediaType.DVDImage;
+ else if (type == SupportedMediaType.IDVDImage.ordinal())
+ this.type = SupportedMediaType.IDVDImage;
+ else if (type == SupportedMediaType.LegacyVdrRecording.ordinal())
+ this.type = SupportedMediaType.LegacyVdrRecording;
+ else if (type == SupportedMediaType.ILegacyVdrRecording.ordinal())
+ this.type = SupportedMediaType.ILegacyVdrRecording;
+ else if (type == SupportedMediaType.VdrRecording.ordinal())
+ this.type = SupportedMediaType.VdrRecording;
+ else if (type == SupportedMediaType.IVdrRecording.ordinal())
+ this.type = SupportedMediaType.IVdrRecording;
+ else if (type == SupportedMediaType.Picture.ordinal())
+ this.type = SupportedMediaType.Picture;
+ else
+ throw new EnumConstantNotPresentException(SupportedMediaType.class, "unknown ordinal #" + type);
+ properties.put(TYPE_PROPERTY, this.type);
+ }
+
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+
+ protected void refresh() {
+ if (parent != null && realPath != null)
+ realPath = new File(parent.getRealPath(), realPath.getName());
+ }
+
+
+ protected void setType(SupportedMediaType type) {
+ this.type = type;
+ properties.put(TYPE_PROPERTY, this.type);
+ }
+
+ private File realPath;
+ private File originalPath;
+ private URI uri;
+ private SupportedMediaType type;
+ private AbstractMediaNode parent;
+ private String name;
+ private String mimeType;
+ private String search;
+ private String format;
+ private Map<String, Object> properties;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Audio.java b/cmpcj/src/de/schwarzrot/media/domain/Audio.java
new file mode 100644
index 0000000..7e3bf20
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Audio.java
@@ -0,0 +1,72 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Audio.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Audio extends Media {
+ private static final long serialVersionUID = 713L;
+ private static final Map<String, String> knownExtensions;
+
+
+ public Audio(Genre parent, File path, String mimeType) {
+ super(parent, SupportedMediaType.Audio, mimeType, path);
+ }
+
+
+ public static String getContentType(String extension) {
+ return knownExtensions.get(extension);
+ }
+
+
+ public static boolean isSupportedExtension(String extension) {
+ return knownExtensions.containsKey(extension);
+ }
+
+ static {
+ knownExtensions = new HashMap<String, String>();
+
+ knownExtensions.put("aac", "audio/aac");
+ knownExtensions.put("aif", "audio/x-aiff");
+ knownExtensions.put("aiff", "audio/x-aiff");
+ knownExtensions.put("aifc", "audio/x-aiff");
+ knownExtensions.put("au", "audio/x-au");
+ knownExtensions.put("fla", "audio/flac");
+ knownExtensions.put("flac", "audio/flac");
+ knownExtensions.put("oga", "audio/ogg");
+ knownExtensions.put("ogg", "audio/ogg");
+ knownExtensions.put("mka", "audio/x-matroska");
+ knownExtensions.put("mp3", "audio/mpeg");
+ knownExtensions.put("mp4", "audio/x-mpeg4");
+ knownExtensions.put("m4a", "audio/x-m4");
+ knownExtensions.put("mpp", "audio/x-musepack");
+ knownExtensions.put("ram", "audio/x-realaudio");
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Config.java b/cmpcj/src/de/schwarzrot/media/domain/Config.java
new file mode 100644
index 0000000..d273972
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Config.java
@@ -0,0 +1,128 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Config.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public class Config {
+ public Config() {
+ knownServers = new ArrayList<MediaServer>();
+ playerMap = new HashMap<Media.SupportedMediaType, PlayerDefinition>();
+ }
+
+
+ public void addServer(MediaServer ms) {
+ knownServers.add(ms);
+ }
+
+
+ public List<MediaServer> getKnownServers() {
+ return knownServers;
+ }
+
+
+ public int getMainHeight() {
+ return mainHeight;
+ }
+
+
+ public int getMainWidth() {
+ return mainWidth;
+ }
+
+
+ public Map<Media.SupportedMediaType, PlayerDefinition> getPlayerMap() {
+ return playerMap;
+ }
+
+
+ public int getPosX() {
+ return posX;
+ }
+
+
+ public int getPosY() {
+ return posY;
+ }
+
+
+ public boolean isDebug() {
+ return debug;
+ }
+
+
+ public void putPlayer(Media.SupportedMediaType type, PlayerDefinition pd) {
+ playerMap.put(type, pd);
+ }
+
+
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+
+ public void setKnownServers(List<MediaServer> knownServers) {
+ this.knownServers = knownServers;
+ }
+
+
+ public void setMainHeight(int mainHeight) {
+ this.mainHeight = mainHeight;
+ }
+
+
+ public void setMainWidth(int mainWidth) {
+ this.mainWidth = mainWidth;
+ }
+
+
+ public void setPlayerMap(Map<Media.SupportedMediaType, PlayerDefinition> playerMap) {
+ this.playerMap = playerMap;
+ }
+
+
+ public void setPosX(int posX) {
+ this.posX = posX;
+ }
+
+
+ public void setPosY(int posY) {
+ this.posY = posY;
+ }
+
+ private List<MediaServer> knownServers;
+ private Map<Media.SupportedMediaType, PlayerDefinition> playerMap;
+ private boolean debug;
+ private int posX;
+ private int posY;
+ private int mainWidth;
+ private int mainHeight;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/DVDImage.java b/cmpcj/src/de/schwarzrot/media/domain/DVDImage.java
new file mode 100644
index 0000000..ff5451a
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/DVDImage.java
@@ -0,0 +1,47 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: DVDImage.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+
+
+public class DVDImage extends Movie {
+ private static final long serialVersionUID = 713L;
+ private static final String DVDContentType = "video/mpeg";
+ private static final String BASE_DIR = "VIDEO_TS";
+ private static final String KEY_FILE = "VIDEO_TS.IFO";
+
+
+ public DVDImage(Genre parent, File path) {
+ super(parent, SupportedMediaType.DVDImage, DVDContentType, path);
+ }
+
+
+ public static boolean isKeyFile(File file2Check) {
+ return file2Check.getName().equals(KEY_FILE) && file2Check.getParentFile().getName().equals(BASE_DIR);
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Genre.java b/cmpcj/src/de/schwarzrot/media/domain/Genre.java
new file mode 100644
index 0000000..5bbb463
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Genre.java
@@ -0,0 +1,121 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Genre.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class Genre extends AbstractMediaNode {
+ private static final long serialVersionUID = 713L;
+ private static final String MIME_TYPE = "text/plain";
+
+
+ public Genre(File path) {
+ this(null, path);
+ }
+
+
+ public Genre(Genre parent, File path) {
+ super(parent, SupportedMediaType.Genre, MIME_TYPE, path);
+ mediaList = new ArrayList<Media>();
+ children = new ArrayList<Genre>();
+ if (parent != null)
+ parent.addGenre(this);
+ }
+
+
+ public void addGenre(Genre g) {
+ children.add(g);
+ }
+
+
+ public void addMedia(Media m) {
+ mediaList.add(m);
+ }
+
+
+ public List<Genre> getChildren() {
+ return children;
+ }
+
+
+ public List<Media> getMediaList() {
+ return mediaList;
+ }
+
+
+ public void removeGenre(Genre g) {
+ children.remove(g);
+ }
+
+
+ public void removeMedia(Media m) {
+ mediaList.remove(m);
+ }
+
+
+ public void setChildren(List<Genre> children) {
+ this.children = children;
+ }
+
+
+ public void setMediaList(List<Media> mediaList) {
+ this.mediaList = mediaList;
+ }
+
+
+ public void setParent(Genre parent) {
+ Genre oldParent = (Genre) getParent();
+
+ super.setParent(parent);
+ if (oldParent != null)
+ oldParent.removeGenre(this);
+ parent.addGenre(this);
+ }
+
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+
+ public void update() {
+ // instances has moved, so all children and media members must be updated
+ for (Genre g : children) {
+ g.refresh();
+ g.update();
+ }
+ for (Media m : mediaList)
+ m.refresh();
+ }
+
+ private List<Media> mediaList;
+ private List<Genre> children;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/LegacyVdrRecording.java b/cmpcj/src/de/schwarzrot/media/domain/LegacyVdrRecording.java
new file mode 100644
index 0000000..b98688f
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/LegacyVdrRecording.java
@@ -0,0 +1,39 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: LegacyVdrRecording.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+
+
+public class LegacyVdrRecording extends VdrRecording {
+ private static final long serialVersionUID = 713L;
+
+
+ public LegacyVdrRecording(Genre parent, File path) {
+ super(parent, SupportedMediaType.LegacyVdrRecording, DEFAULT_MIME_TYPE, path);
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Media.java b/cmpcj/src/de/schwarzrot/media/domain/Media.java
new file mode 100644
index 0000000..6cc4aac
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Media.java
@@ -0,0 +1,55 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Media.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+
+
+public class Media extends AbstractMediaNode {
+ private static final long serialVersionUID = 713L;
+
+
+ public Media() {
+ super(null, SupportedMediaType.Unknown, null, null);
+ }
+
+
+ public Media(Genre parent, SupportedMediaType type, String mimeType, File path) {
+ super(parent, type, mimeType, path);
+ parent.addMedia(this);
+ }
+
+
+ public void setParent(Genre parent) {
+ Genre oldParent = (Genre) getParent();
+
+ super.setParent(parent);
+ if (oldParent != null)
+ oldParent.removeMedia(this);
+ parent.addMedia(this);
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/MediaServer.java b/cmpcj/src/de/schwarzrot/media/domain/MediaServer.java
new file mode 100644
index 0000000..a8968c4
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/MediaServer.java
@@ -0,0 +1,57 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaServer.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+public class MediaServer {
+ public String getHostName() {
+ return hostName;
+ }
+
+
+ public int getPort() {
+ return port;
+ }
+
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+
+ @Override
+ public String toString() {
+ return hostName;
+ }
+
+ private String hostName;
+ private int port;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/MediaType.java b/cmpcj/src/de/schwarzrot/media/domain/MediaType.java
new file mode 100644
index 0000000..b571090
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/MediaType.java
@@ -0,0 +1,55 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaType.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+public class MediaType {
+ public static final String NAME_PROPERTY = "name";
+ public static final String START_PROPERTY = "start";
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public long getStart() {
+ return start;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public void setStart(long start) {
+ this.start = start;
+ }
+
+ private String name;
+ private long start;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Movie.java b/cmpcj/src/de/schwarzrot/media/domain/Movie.java
new file mode 100644
index 0000000..1191da3
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Movie.java
@@ -0,0 +1,88 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Movie.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Movie extends Media {
+ private static final long serialVersionUID = 713L;
+ private static final Map<String, String> knownExtensions;
+
+
+ public Movie(Genre parent, File path, String mimeType) {
+ this(parent, SupportedMediaType.Movie, mimeType, path);
+ }
+
+
+ public Movie(Genre parent, SupportedMediaType type, String mimeType, File path) {
+ super(parent, type, mimeType, path);
+ }
+
+
+ public boolean isInterlaced() {
+ return interlaced;
+ }
+
+
+ public void setInterlaced(boolean interlaced) {
+ this.interlaced = interlaced;
+ setType(getType().ordinal() + 1);
+ }
+
+
+ public static String getContentType(String extension) {
+ return knownExtensions.get(extension);
+ }
+
+
+ public static boolean isSupportedExtension(String extension) {
+ return knownExtensions.containsKey(extension);
+ }
+
+ boolean interlaced;
+ static {
+ knownExtensions = new HashMap<String, String>();
+
+ knownExtensions.put("aac", "audio/aac");
+ knownExtensions.put("asd", "video/x-ms-asf");
+ knownExtensions.put("asf", "video/x-ms-asf");
+ knownExtensions.put("avi", "video/x-msvideo");
+ knownExtensions.put("dv", "video/x-dv");
+ knownExtensions.put("flv", "video/x-flv");
+ knownExtensions.put("gl", "video/x-gl");
+ knownExtensions.put("iso", "application/x-iso9660-image");
+ knownExtensions.put("ogv", "video/ogg");
+ knownExtensions.put("mkv", "video/x-matroska");
+ knownExtensions.put("mov", "video/quicktime");
+ knownExtensions.put("mpg", "video/mpeg");
+ knownExtensions.put("mpeg", "video/mpeg");
+ knownExtensions.put("swf", "application/x-shockwave-flash");
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/Picture.java b/cmpcj/src/de/schwarzrot/media/domain/Picture.java
new file mode 100644
index 0000000..4d0cab9
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/Picture.java
@@ -0,0 +1,78 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Picture.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Picture extends Media {
+ private static final long serialVersionUID = 713L;
+ private static final Map<String, String> knownExtensions;
+
+
+ public Picture(Genre parent, File path, String mimeType) {
+ super(parent, SupportedMediaType.Picture, mimeType, path);
+ }
+
+
+ public static String getContentType(String extension) {
+ return knownExtensions.get(extension);
+ }
+
+
+ public static boolean isSupportedExtension(String extension) {
+ return knownExtensions.containsKey(extension);
+ }
+
+ static {
+ knownExtensions = new HashMap<String, String>();
+
+ knownExtensions.put("aac", "audio/aac");
+ knownExtensions.put("bmp", "image/x-windows-bmp");
+ knownExtensions.put("gif", "image/gif");
+ knownExtensions.put("jff", "image/jpeg");
+ knownExtensions.put("jfif", "image/jpeg");
+ knownExtensions.put("jif", "image/jpeg");
+ knownExtensions.put("jp2", "image/jp2");
+ knownExtensions.put("jpe", "image/jpeg");
+ knownExtensions.put("jpeg", "image/jpeg");
+ knownExtensions.put("jpg", "image/jpeg");
+ knownExtensions.put("jpm", "image/jpm");
+ knownExtensions.put("jpx", "image/jpx");
+ knownExtensions.put("pbm", "image/x-portable-bitmap");
+ knownExtensions.put("pct", "image/x-pict");
+ knownExtensions.put("pcx", "image/x-pcx");
+ knownExtensions.put("png", "image/png");
+ knownExtensions.put("pnm", "image/x-portable-anymap");
+ knownExtensions.put("ppm", "image/x-portable-pixmap");
+ knownExtensions.put("qti", "image/quicktime");
+ knownExtensions.put("ras", "image/x-cmu-raster");
+ knownExtensions.put("rgb", "image/x-rgb");
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/PlayList.java b/cmpcj/src/de/schwarzrot/media/domain/PlayList.java
new file mode 100644
index 0000000..ec7a393
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/PlayList.java
@@ -0,0 +1,70 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: PlayList.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.util.List;
+
+
+public class PlayList {
+ public static final String TOTAL_PROPERTY = "total";
+ public static final String RESULTS_PROPERTY = "results";
+ public static final String TYPES_PROPERTY = "types";
+
+
+ public List<Media> getResults() {
+ return results;
+ }
+
+
+ public long getTotal() {
+ return total;
+ }
+
+
+ public List<MediaType> getTypes() {
+ return types;
+ }
+
+
+ public void setResults(List<Media> results) {
+ this.results = results;
+ }
+
+
+ public void setTotal(long total) {
+ this.total = total;
+ }
+
+
+ public void setTypes(List<MediaType> types) {
+ this.types = types;
+ }
+
+ private long total;
+ private List<Media> results;
+ private List<MediaType> types;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/PlayerDefinition.java b/cmpcj/src/de/schwarzrot/media/domain/PlayerDefinition.java
new file mode 100644
index 0000000..05b9bbc
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/PlayerDefinition.java
@@ -0,0 +1,115 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: PlayerDefinition.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class PlayerDefinition {
+ public PlayerDefinition() {
+ parameters = new ArrayList<String>();
+ }
+
+
+ public void addParameter(String parameter) {
+ parameters.add(parameter);
+ }
+
+
+ public String getCommandLine() {
+ if (commandLine == null)
+ assembleCommandLine();
+ return commandLine;
+ }
+
+
+ public String getExecutable() {
+ return executable;
+ }
+
+
+ public AbstractMediaNode.SupportedMediaType getMediaType() {
+ return mediaType;
+ }
+
+
+ public List<String> getParameters() {
+ return parameters;
+ }
+
+
+ public void setCommandLine(String commandLine) {
+ this.commandLine = commandLine;
+ decodeCommandLine();
+ }
+
+
+ public void setExecutable(String executable) {
+ this.executable = executable;
+ assembleCommandLine();
+ }
+
+
+ public void setMediaType(AbstractMediaNode.SupportedMediaType mediaType) {
+ this.mediaType = mediaType;
+ }
+
+
+ public void setParameters(List<String> parameters) {
+ this.parameters = parameters;
+ assembleCommandLine();
+ }
+
+
+ protected void assembleCommandLine() {
+ if (executable == null || parameters == null || parameters.size() < 1)
+ return;
+ StringBuilder sb = new StringBuilder(executable);
+
+ for (String p : parameters) {
+ sb.append(" ").append(p);
+ }
+ commandLine = sb.toString();
+ }
+
+
+ protected void decodeCommandLine() {
+ String[] parts = commandLine.split("\\s+");
+
+ executable = parts[0];
+ parameters.clear();
+ for (int i = 1; i < parts.length; ++i) {
+ parameters.add(parts[i]);
+ }
+ }
+
+ private AbstractMediaNode.SupportedMediaType mediaType;
+ private String executable;
+ private String commandLine;
+ private List<String> parameters;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/domain/VdrRecording.java b/cmpcj/src/de/schwarzrot/media/domain/VdrRecording.java
new file mode 100644
index 0000000..b11cb03
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/domain/VdrRecording.java
@@ -0,0 +1,67 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: VdrRecording.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.domain;
+
+
+import java.io.File;
+
+
+public class VdrRecording extends Movie {
+ private static final long serialVersionUID = 713L;
+ protected static final String DEFAULT_MIME_TYPE = "video/mpeg";
+ protected static final String KEY_FILE = "00001.vdr";
+
+
+ public VdrRecording(Genre parent, File path) {
+ this(parent, SupportedMediaType.VdrRecording, DEFAULT_MIME_TYPE, path);
+ }
+
+
+ protected VdrRecording(Genre parent, SupportedMediaType type, String mimeType, File path) {
+ super(parent, type, mimeType, path);
+ }
+
+
+ @Override
+ public String getName() {
+ return getRealPath().getParentFile().getName();
+ }
+
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(getName());
+
+ sb.append(" (").append(super.getName()).append(")");
+
+ return sb.toString();
+ }
+
+
+ public static boolean isKeyFile(File file2Check) {
+ return file2Check.getName().equals(KEY_FILE);
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/media/service/DataManager.java b/cmpcj/src/de/schwarzrot/media/service/DataManager.java
new file mode 100644
index 0000000..3d6940f
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/service/DataManager.java
@@ -0,0 +1,152 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: DataManager.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.service;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultMutableTreeNode;
+import ca.odell.glazedlists.EventList;
+import de.schwarzrot.base.util.ApplicationServiceProvider;
+import de.schwarzrot.base.util.SuccessHandler;
+import de.schwarzrot.media.domain.AbstractMediaNode;
+import de.schwarzrot.media.domain.Genre;
+import de.schwarzrot.media.domain.Media;
+import de.schwarzrot.media.util.ElementConsumer;
+import de.schwarzrot.media.util.ListLoader;
+
+
+public class DataManager implements Runnable, ElementConsumer<Media> {
+ public DataManager(File input) {
+ this.input = input;
+ nodeCache = new HashMap<File, DefaultMutableTreeNode>();
+ }
+
+
+ @Override
+ public void consumeElement(Media m) {
+ if (m.getParent() == null)
+ m.setParent(getGenre(m.getRealPath().getParentFile()));
+
+ mediaList.getReadWriteLock().writeLock().lock();
+ mediaList.add(m);
+ mediaList.getReadWriteLock().writeLock().unlock();
+ }
+
+
+ public void load(DefaultMutableTreeNode root, EventList<Media> mediaList, SuccessHandler successHandler) {
+ Thread backgroundThread = new Thread(this);
+
+ nodeCache.clear();
+ resultHandler = successHandler;
+ rootNode = root;
+ nodeCache.put(new File("/"), rootNode);
+ this.mediaList = mediaList;
+ backgroundThread.setName("load media list");
+ backgroundThread.setDaemon(true);
+ backgroundThread.start();
+ }
+
+
+ @Override
+ public void run() {
+ @SuppressWarnings("unchecked")
+ ListLoader<Media> ll = ApplicationServiceProvider.getService(ListLoader.class);
+
+ try {
+ long[] info = ll.loadFirst(this);
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ resultHandler.handleSuccess(); // feedback to main thread
+ }
+ });
+ ll.loadRest(info, this);
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ resultHandler.handleSuccess(); // feedback to main thread
+ }
+ });
+ } catch (final Throwable t) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ resultHandler.handleFailure(t); // feedback to main thread
+ }
+ });
+ }
+ }
+
+
+ protected void createGenre(File path) {
+ File tmp = path;
+ Stack<File> unknownGenres = new Stack<File>();
+
+ while (tmp != null && !nodeCache.containsKey(tmp)) {
+ unknownGenres.push(tmp);
+ tmp = tmp.getParentFile();
+ }
+ DefaultMutableTreeNode treeNode = tmp == null ? rootNode : nodeCache.get(tmp);
+ AbstractMediaNode media = (AbstractMediaNode) treeNode.getUserObject();
+ DefaultMutableTreeNode subNode = null;
+ Genre g = null;
+
+ if (media != null && media instanceof Genre)
+ g = (Genre) media;
+
+ while (unknownGenres.size() > 0) {
+ tmp = unknownGenres.pop();
+ g = new Genre(g, tmp);
+ subNode = new DefaultMutableTreeNode(g);
+ nodeCache.put(tmp, subNode);
+ treeNode.add(subNode);
+ treeNode = subNode;
+ }
+ }
+
+
+ protected Genre getGenre(File path) {
+ if (!nodeCache.containsKey(path))
+ createGenre(path);
+ DefaultMutableTreeNode n = nodeCache.get(path);
+ AbstractMediaNode rv = (AbstractMediaNode) n.getUserObject();
+
+ if (rv instanceof Genre)
+ return (Genre) rv;
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ private File input;
+ private SuccessHandler resultHandler;
+ private DefaultMutableTreeNode rootNode;
+ private EventList<Media> mediaList;
+ private Map<File, DefaultMutableTreeNode> nodeCache;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/service/MediaExecutor.java b/cmpcj/src/de/schwarzrot/media/service/MediaExecutor.java
new file mode 100644
index 0000000..0cd6fe7
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/service/MediaExecutor.java
@@ -0,0 +1,58 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaExecutor.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.service;
+
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.JTable;
+import ca.odell.glazedlists.EventList;
+import de.schwarzrot.control.client.MediaClientExecutor;
+import de.schwarzrot.media.domain.Media;
+
+
+public class MediaExecutor extends MouseAdapter {
+ public MediaExecutor(JTable table, EventList<Media> list, MediaClientExecutor mce) {
+ this.table = table;
+ this.list = list;
+ executor = mce;
+ }
+
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) {
+ int i = table.rowAtPoint(e.getPoint());
+ Media m = list.get(i);
+
+ executor.playMedia(m);
+ }
+ }
+
+ private JTable table;
+ private EventList<Media> list;
+ private MediaClientExecutor executor;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/service/MediaFactory.java b/cmpcj/src/de/schwarzrot/media/service/MediaFactory.java
new file mode 100644
index 0000000..ff31822
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/service/MediaFactory.java
@@ -0,0 +1,137 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaFactory.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.service;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+import de.schwarzrot.media.domain.AbstractMediaNode;
+import de.schwarzrot.media.domain.Audio;
+import de.schwarzrot.media.domain.DVDImage;
+import de.schwarzrot.media.domain.Genre;
+import de.schwarzrot.media.domain.LegacyVdrRecording;
+import de.schwarzrot.media.domain.Media;
+import de.schwarzrot.media.domain.Movie;
+import de.schwarzrot.media.domain.Picture;
+import de.schwarzrot.media.domain.VdrRecording;
+
+
+public class MediaFactory {
+ public MediaFactory(File baseDir) {
+ this.baseDir = baseDir;
+ prefix = baseDir.getAbsolutePath();
+ mediaCache = new HashMap<File, AbstractMediaNode>();
+ mediaCache.put(baseDir, new Genre(baseDir));
+ }
+
+
+ //TODO:
+ // here we can't rely on file system information.
+ // may be we got files from remote system ...
+ // so instead to use lookahead for multifile movies, we need to go back
+ // from keyfiles
+ public Media createMedia(File mayBeMedia) {
+ if (!mayBeMedia.getAbsolutePath().startsWith(prefix))
+ return null;
+ String xt = mayBeMedia.getName().substring(mayBeMedia.getName().lastIndexOf(".") + 1);
+ Genre parent = null;
+ Media rv = null;
+
+ if (VdrRecording.isKeyFile(mayBeMedia)) {
+ parent = getGenre(mayBeMedia.getParentFile().getParentFile().getParentFile());
+
+ rv = new VdrRecording(parent, mayBeMedia.getParentFile());
+ } else if (LegacyVdrRecording.isKeyFile(mayBeMedia)) {
+ parent = getGenre(mayBeMedia.getParentFile().getParentFile().getParentFile());
+
+ rv = new LegacyVdrRecording(parent, mayBeMedia.getParentFile());
+ } else if (DVDImage.isKeyFile(mayBeMedia)) {
+ parent = getGenre(mayBeMedia.getParentFile().getParentFile().getParentFile());
+
+ rv = new DVDImage(parent, mayBeMedia.getParentFile().getParentFile());
+ } else if (Movie.isSupportedExtension(xt)) {
+ parent = getGenre(mayBeMedia.getParentFile());
+ rv = new Movie(parent, mayBeMedia, Movie.getContentType(xt));
+ } else if (Audio.isSupportedExtension(xt)) {
+ parent = getGenre(mayBeMedia.getParentFile());
+ rv = new Audio(parent, mayBeMedia, Audio.getContentType(xt));
+ } else if (Picture.isSupportedExtension(xt)) {
+ parent = getGenre(mayBeMedia.getParentFile());
+ rv = new Picture(parent, mayBeMedia, Picture.getContentType(xt));
+ }
+ if (rv != null)
+ mediaCache.put(mayBeMedia, rv);
+
+ return rv;
+ }
+
+
+ public Map<File, AbstractMediaNode> getCache() {
+ return mediaCache;
+ }
+
+
+ public Genre getGenre(File mayBeGenre) {
+ if (!mayBeGenre.isDirectory())
+ return null;
+
+ if (!mediaCache.containsKey(mayBeGenre))
+ createGenre(mayBeGenre);
+ AbstractMediaNode rv = mediaCache.get(mayBeGenre);
+
+ if (rv instanceof Genre)
+ return (Genre) rv;
+ return null;
+ }
+
+
+ protected void createGenre(File shouldBeGenre) {
+ File tmp = shouldBeGenre;
+ Stack<File> unknownGenres = new Stack<File>();
+
+ while (tmp != null && !mediaCache.containsKey(tmp)) {
+ unknownGenres.push(tmp);
+ tmp = tmp.getParentFile();
+ }
+ AbstractMediaNode node = mediaCache.get(tmp != null ? tmp : baseDir);
+ Genre g = null;
+
+ if (node != null && node instanceof Genre)
+ g = (Genre) node;
+
+ while (unknownGenres.size() > 0) {
+ tmp = unknownGenres.pop();
+ g = new Genre(g, tmp);
+ mediaCache.put(tmp, g);
+ }
+ }
+
+ private Map<File, AbstractMediaNode> mediaCache;
+ private File baseDir;
+ private String prefix;
+}
diff --git a/cmpcj/src/de/schwarzrot/media/util/ElementConsumer.java b/cmpcj/src/de/schwarzrot/media/util/ElementConsumer.java
new file mode 100644
index 0000000..e50894d
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/util/ElementConsumer.java
@@ -0,0 +1,31 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ElementConsumer.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.util;
+
+
+public interface ElementConsumer<E> {
+ public void consumeElement(E element);
+}
diff --git a/cmpcj/src/de/schwarzrot/media/util/ListLoader.java b/cmpcj/src/de/schwarzrot/media/util/ListLoader.java
new file mode 100644
index 0000000..5542cf2
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/util/ListLoader.java
@@ -0,0 +1,34 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ListLoader.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.util;
+
+
+public interface ListLoader<E> {
+ public long[] loadFirst(ElementConsumer<E> consumer);
+
+
+ public long loadRest(long[] listInfo, ElementConsumer<E> consumer);
+}
diff --git a/cmpcj/src/de/schwarzrot/media/util/MedialistParser.java b/cmpcj/src/de/schwarzrot/media/util/MedialistParser.java
new file mode 100644
index 0000000..756c795
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/media/util/MedialistParser.java
@@ -0,0 +1,169 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MedialistParser.java
+ * Created: 13. June 2012, 04:57
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmpc - a java frontend (client) part of compound media player
+ * uses external players to play the media
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.media.util;
+
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import com.google.gson.stream.JsonReader;
+import de.schwarzrot.media.domain.Media;
+import de.schwarzrot.media.domain.MediaType;
+import de.schwarzrot.media.domain.PlayList;
+
+
+public class MedialistParser {
+ public PlayList parseListChunk(InputStream is) {
+ JsonReader reader = null;
+ PlayList rv = null;
+
+ try {
+ reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
+
+ rv = readPlayList(reader);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ try {
+ reader.close();
+ } catch (Throwable t) {
+ }
+ }
+ return rv;
+ }
+
+
+ protected Media readMedia(JsonReader reader) {
+ Media rv = new Media();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if (Media.NAME_PROPERTY.equals(name)) {
+ rv.setName(reader.nextString());
+ } else if (Media.TYPE_PROPERTY.equals(name)) {
+ rv.setType(reader.nextInt());
+ } else if (Media.FORMAT_PROPERTY.equals(name)) {
+ rv.setFormat(reader.nextString());
+ } else if (Media.PATH_PROPERTY.equals(name)) {
+ rv.setPath(reader.nextString());
+ } else {
+ rv.setProperty(name, reader.nextString());
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected List<Media> readMediaArray(JsonReader reader) {
+ List<Media> rv = new ArrayList<Media>();
+
+ try {
+ reader.beginArray();
+ while (reader.hasNext()) {
+ rv.add(readMedia(reader));
+ }
+ reader.endArray();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected MediaType readMediaType(JsonReader reader) {
+ MediaType rv = new MediaType();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if (MediaType.NAME_PROPERTY.equals(name)) {
+ rv.setName(reader.nextString());
+ } else if (MediaType.START_PROPERTY.equals(name)) {
+ rv.setStart(reader.nextLong());
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected PlayList readPlayList(JsonReader reader) {
+ PlayList rv = new PlayList();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if (PlayList.TOTAL_PROPERTY.equals(name)) {
+ rv.setTotal(reader.nextLong());
+ } else if (PlayList.TYPES_PROPERTY.equals(name)) {
+ rv.setTypes(readTypeArray(reader));
+ } else if (PlayList.RESULTS_PROPERTY.equals(name)) {
+ rv.setResults(readMediaArray(reader));
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ rv = null;
+ }
+ return rv;
+ }
+
+
+ protected List<MediaType> readTypeArray(JsonReader reader) {
+ List<MediaType> rv = new ArrayList<MediaType>();
+
+ try {
+ reader.beginArray();
+ while (reader.hasNext()) {
+ rv.add(readMediaType(reader));
+ }
+ reader.endArray();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+}