summaryrefslogtreecommitdiff
path: root/libs/mediaScan/src
diff options
context:
space:
mode:
Diffstat (limited to 'libs/mediaScan/src')
-rw-r--r--libs/mediaScan/src/AbstractMedia.cc135
-rw-r--r--libs/mediaScan/src/AbstractMultiFileMovie.cc108
-rw-r--r--libs/mediaScan/src/Audio.cc70
-rw-r--r--libs/mediaScan/src/DVDImage.cc117
-rw-r--r--libs/mediaScan/src/FSMediaScanner.cc111
-rw-r--r--libs/mediaScan/src/LegacyVdrRecording.cc104
-rw-r--r--libs/mediaScan/src/MediaFactory.cc148
-rw-r--r--libs/mediaScan/src/Movie.cc67
-rw-r--r--libs/mediaScan/src/Picture.cc69
-rw-r--r--libs/mediaScan/src/VdrRecording.cc103
10 files changed, 1032 insertions, 0 deletions
diff --git a/libs/mediaScan/src/AbstractMedia.cc b/libs/mediaScan/src/AbstractMedia.cc
new file mode 100644
index 0000000..924f01a
--- /dev/null
+++ b/libs/mediaScan/src/AbstractMedia.cc
@@ -0,0 +1,135 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AbstractMedia.cc
+ * Created: 2. Juli 2012, 14
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <AbstractMedia.h>
+#include <Logging.h>
+#include <File.h>
+#include <Url.h>
+#include <Codec.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <util.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+cAbstractMedia::cAbstractMedia(const cFile &File, const char *Mime, SupportedMediaType Type)
+ : fd(-1)
+ , mediaType(Type)
+ , mimeType(Mime ? strdup(Mime) : NULL)
+ , uri(NULL)
+ , logicalPath(NULL)
+ , keyPath(File)
+{
+ uri = keyPath.toURI();
+ logicalPath = cUrl::Decoder()->Decode(uri);
+}
+
+cAbstractMedia::~cAbstractMedia()
+{
+ free(mimeType);
+ free(uri);
+ free(logicalPath);
+}
+
+const char *cAbstractMedia::Name(void) const
+{
+ return keyPath.Name();
+}
+
+void cAbstractMedia::Refresh(void)
+{
+}
+
+size_t cAbstractMedia::ReadChunk(char* Buf, size_t bufSize)
+{
+ long rv = 0;
+ const char *path = AbsolutePath();
+
+ if (fd < 1) { // fd stays open between various calls
+ fd = open(path, O_RDONLY | O_LARGEFILE);
+ if (fd < 1) {
+ esyslog("could not open requested path %s - Error #%d", path, errno);
+ return 0;
+ }
+ }
+ isyslog("have filehandle #%d (%s)", fd, path);
+ if ((rv = read(fd, Buf, bufSize)) < 0)
+ esyslog("ERROR: failed to read from file %s #%d", path, errno);
+ else
+ isyslog("read %u bytes from file %s", rv, path);
+ if (rv < (long) bufSize) { // most probabely end of file
+ close(fd);
+ }
+ return rv;
+}
+
+void cAbstractMedia::Reset(void)
+{
+ if (fd >= 0) {
+ close(fd);
+ fd = -1;
+ }
+}
+
+size_t cAbstractMedia::Size(void) const
+{
+ return keyPath.Size();
+}
+
+const char *cAbstractMedia::MediaType2Text(int Type)
+{
+ switch(Type) {
+ case Audio: return TO_STRING(Audio);
+ case Movie: return TO_STRING(Movie);
+ case DVDImage: return TO_STRING(DVDImage);
+ case LegacyVdrRecording: return TO_STRING(LegacyVdrRecording);
+ case VdrRecording: return TO_STRING(VdrRecording);
+ case Picture: return TO_STRING(Picture);
+ default: return TO_STRING(Invalid);
+ }
+}
+
+bool cAbstractMedia::NeedsFurtherScan(void) const
+{
+ return false;
+}
+
+const char *cAbstractMedia::AbsolutePath(void) const
+{
+ return keyPath.AbsolutePath();
+}
+
+ulong cAbstractMedia::LastModified(void) const
+{
+ return keyPath.LastModified();
+}
+
+void cAbstractMedia::SetMimeType(const char *MimeType)
+{
+ if (mimeType == MimeType) return;
+ free(mimeType);
+ mimeType = strdup(MimeType);
+}
diff --git a/libs/mediaScan/src/AbstractMultiFileMovie.cc b/libs/mediaScan/src/AbstractMultiFileMovie.cc
new file mode 100644
index 0000000..f679511
--- /dev/null
+++ b/libs/mediaScan/src/AbstractMultiFileMovie.cc
@@ -0,0 +1,108 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AbstractMultiFileMovie.cc
+ * Created: 3. Juli 2012, 07
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <AbstractMultiFileMovie.h>
+#include <Logging.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+cAbstractMultiFileMovie::cAbstractMultiFileMovie(const cFile &File, const char *Mime, SupportedMediaType Type)
+ : cMovie(File, Mime, Type)
+ , movieFiles(0)
+ , curFileNo(0)
+ , buf(NULL)
+ , bufSize(0)
+ , name(NULL)
+{
+}
+
+cAbstractMultiFileMovie::~cAbstractMultiFileMovie()
+{
+ free(name);
+ free(buf);
+}
+
+bool cAbstractMultiFileMovie::checkBuffer()
+{
+ if (!buf && bufSize) {
+ buf = (char *) malloc(bufSize);
+ }
+ return buf != NULL;
+}
+
+size_t cAbstractMultiFileMovie::ReadChunk(char* Buf, size_t bufSize)
+{
+ long rv = 0;
+ const char *path = NULL;
+
+ if (fd < 1) {
+ path = FirstFile();
+ fd = open(path, O_RDONLY | O_LARGEFILE);
+ if (fd < 1) {
+ esyslog("could not open requested path %s - Error #%d", path, errno);
+ return 0;
+ }
+ }
+ isyslog("have filehandle #%d (%s)", fd, path);
+ rv = read(fd, Buf, bufSize);
+
+ if (rv < (long) bufSize) {
+ path = NextFile();
+
+ if (path) {
+ close(fd);
+ fd = open(path, O_RDONLY | O_LARGEFILE);
+ if (fd < 1) {
+ esyslog("could not open requested path %s - Error #%d", path, errno);
+ return 0;
+ }
+ isyslog("have filehandle #%d (%s)", fd, path);
+ rv = read(fd, Buf, bufSize);
+ }
+ if (rv < (long) bufSize) {
+ close(fd);
+ fd = -1;
+ }
+ }
+ return rv;
+}
+
+void cAbstractMultiFileMovie::Reset()
+{
+ cMovie::Reset();
+ curFileNo = 0;
+}
+
+void cAbstractMultiFileMovie::SetName(char* Name)
+///< Name must have already been allocated from heap!
+{
+ name = Name;
+}
+
+void cAbstractMultiFileMovie::SetSize(size_t Size)
+{
+ size = Size;
+} \ No newline at end of file
diff --git a/libs/mediaScan/src/Audio.cc b/libs/mediaScan/src/Audio.cc
new file mode 100644
index 0000000..6c90fbc
--- /dev/null
+++ b/libs/mediaScan/src/Audio.cc
@@ -0,0 +1,70 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Audio.cc
+ * Created: 2. Juli 2012, 15
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <Audio.h>
+#include <stddef.h>
+#include <string.h>
+
+SupportedExtension cAudio::knownExtensions[] = {
+ { "aac", "audio/aac" },
+ { "aif", "audio/x-aiff" },
+ { "aiff", "audio/x-aiff" },
+ { "aifc", "audio/x-aiff" },
+ { "au", "audio/x-au" },
+ { "fla", "audio/flac" },
+ { "flac", "audio/flac" },
+ { "oga", "audio/ogg" },
+ { "ogg", "audio/ogg" },
+ { "mka", "audio/x-matroska" },
+ { "mp3", "audio/mpeg" },
+ { "mp4", "audio/x-mpeg4" },
+ { "m4a", "audio/x-m4" },
+// { "mpg", "audio/mpeg" },
+ { "mpp", "audio/x-musepack" },
+ { "ram", "audio/x-realaudio" },
+ { NULL, NULL }
+};
+
+cAudio::cAudio(const cFile &File, const char *Mime)
+ : cAbstractMedia(File, Mime, Audio)
+{
+}
+
+cAudio::~cAudio()
+{
+}
+
+const char *cAudio::ContentType(const char* Extension)
+{
+ for (SupportedExtension *p = knownExtensions; p && p->extension; ++p) {
+ if (!strcasecmp(p->extension, Extension)) return p->mimeType;
+ }
+ return NULL;
+}
+
+bool cAudio::NeedsFurtherScan(void) const
+{
+//TODO: common meta data: artist, title
+ return true;
+}
diff --git a/libs/mediaScan/src/DVDImage.cc b/libs/mediaScan/src/DVDImage.cc
new file mode 100644
index 0000000..0d23ae1
--- /dev/null
+++ b/libs/mediaScan/src/DVDImage.cc
@@ -0,0 +1,117 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: DVDImage.cc
+ * Created: 3. Juli 2012, 08
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <DVDImage.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "File.h"
+#define FILE_MASK "VIDEO_TS/VTS_%02d_%d.VOB"
+
+cDVDImage::cDVDImage(const cFile &File)
+ : cAbstractMultiFileMovie(File, "video/mpeg", DVDImage)
+{
+ bufSize = 32;
+}
+
+cDVDImage::~cDVDImage()
+{
+}
+
+const char *cDVDImage::Name(void) const
+{
+ return cAbstractMedia::Name();
+}
+
+size_t cDVDImage::Size(void) const
+{
+ return cAbstractMedia::Size();
+}
+
+void cDVDImage::Refresh(void)
+{
+ size_t maxSize = 0;
+ size_t total = 0;
+ int numOfMovieFiles = 0;
+ cFile *tmp;
+
+ movieFiles = 0;
+ mainMovie = 0;
+ if (!checkBuffer()) return;
+ for (int movie = 1; movie < 100; ++movie) {
+ total = 0;
+ for (int fileNo = 1;; ++fileNo) {
+ sprintf(buf, FILE_MASK, movie, fileNo);
+ tmp = new cFile(KeyPath(), buf);
+
+ if (!tmp || !tmp->Exists()) {
+ numOfMovieFiles = fileNo - 1;
+ break;
+ }
+ total += tmp->Size();
+ delete tmp;
+ }
+ if (total > maxSize) {
+ maxSize = total;
+ mainMovie = movie;
+ movieFiles = numOfMovieFiles;
+ }
+ }
+ SetSize(total);
+}
+
+const char *cDVDImage::FirstFile(void)
+{
+ if (!checkBuffer()) return NULL;
+
+ curFileNo = 1;
+ sprintf(buf, FILE_MASK, mainMovie, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ rv = tmp->AbsolutePath();
+ delete tmp;
+ }
+ return rv;
+}
+
+const char *cDVDImage::NextFile(void)
+{
+ if (++curFileNo < movieFiles) {
+ if (!checkBuffer()) return NULL;
+ sprintf(buf, FILE_MASK, mainMovie, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ tmp->AbsolutePath();
+ delete tmp;
+
+ return rv;
+ }
+ }
+ return NULL;
+}
diff --git a/libs/mediaScan/src/FSMediaScanner.cc b/libs/mediaScan/src/FSMediaScanner.cc
new file mode 100644
index 0000000..f4ac14e
--- /dev/null
+++ b/libs/mediaScan/src/FSMediaScanner.cc
@@ -0,0 +1,111 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: FSMediaScanner.cc
+ * Created: 2. Juli 2012, 13
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <FSMediaScanner.h>
+#include <AbstractMedia.h>
+#include <Logging.h>
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/dir.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <util.h>
+
+void freeMediaCallback(void *elem)
+{
+ delete (cAbstractMedia *)elem;
+}
+
+cFSMediaScanner::cFSMediaScanner()
+ : fileBufSize(512)
+ , pool(freeMediaCallback)
+ , mediaFactory(NULL)
+{
+}
+
+cFSMediaScanner::~cFSMediaScanner()
+{
+ pool.clear();
+ if (mediaFactory) delete mediaFactory;
+}
+
+void cFSMediaScanner::SetMediaFactory(cMediaFactory* factory)
+{
+ mediaFactory = factory;
+}
+
+// return true if "a" should be ordered before "b"
+bool defaultMediaSortOrder(void *a, void *b)
+{
+ if (a == b) return false;
+ if (!a) return false;
+ if (!b) return true;
+ cAbstractMedia *m0 = (cAbstractMedia *)a;
+ cAbstractMedia *m1 = (cAbstractMedia *)b;
+ bool rv = false;
+
+ if (m0->MediaType() == m1->MediaType())
+ rv = strcasecmp(m0->Name(), m1->Name()) < 0;
+ else
+ rv = (m0->MediaType() - m1->MediaType()) < 0;
+
+ return rv;
+}
+
+void cFSMediaScanner::Refresh()
+{
+ if (!mediaFactory) return;
+ pool.clear();
+ categories.clear();
+
+ mediaFactory->Scan4Media(pool);
+ cAbstractMedia::SupportedMediaType ot = cAbstractMedia::Invalid;
+ cAbstractMedia *m;
+
+ pool.sort(defaultMediaSortOrder);
+ for (size_t i=0; i < pool.size(); ++i) {
+ m = (cAbstractMedia *) pool[i];
+ if (m->MediaType() != ot) {
+ ot = m->MediaType();
+ categories[ot] = i;
+ }
+ }
+}
+
+cAbstractMedia *cFSMediaScanner::FindMedia(const char *Path)
+{
+ cAbstractMedia *rv = NULL, *tmp;
+
+ for (size_t i=0; i < pool.size(); ++i) {
+ tmp = (cAbstractMedia *) pool[i];
+ if (!strcmp(tmp->LogicalPath(), Path)) {
+ rv = tmp;
+ break;
+ }
+ }
+ return rv;
+}
diff --git a/libs/mediaScan/src/LegacyVdrRecording.cc b/libs/mediaScan/src/LegacyVdrRecording.cc
new file mode 100644
index 0000000..5ee635c
--- /dev/null
+++ b/libs/mediaScan/src/LegacyVdrRecording.cc
@@ -0,0 +1,104 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: LegacyVdrRecording.cc
+ * Created: 3. Juli 2012, 08
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <LegacyVdrRecording.h>
+#include <StringBuilder.h>
+#include <File.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define FILE_MASK "%03d.vdr"
+
+cLegacyVdrRecording::cLegacyVdrRecording(const cFile &File)
+ : cAbstractMultiFileMovie(File, "video/mpeg", LegacyVdrRecording)
+{
+ cStringBuilder sb;
+ cFile *parent = File.Parent();
+
+ sb.Append(parent->Name());
+ sb.Append(" (").Append(File.Name()).Append(")");
+ delete parent;
+ SetName(sb.toString());
+ bufSize = 8;
+}
+
+cLegacyVdrRecording::~cLegacyVdrRecording()
+{
+}
+
+void cLegacyVdrRecording::Refresh(void)
+{
+ size_t total = 0;
+ cFile *tmp;
+
+ if (!checkBuffer()) return;
+ movieFiles = 0;
+ for (int fileNo = 1;; ++fileNo) {
+ sprintf(buf, FILE_MASK, fileNo);
+ tmp = new cFile(KeyPath(), buf);
+
+ if (!tmp || !tmp->Exists()) {
+ movieFiles = fileNo - 1;
+ delete tmp;
+ break;
+ }
+ total += tmp->Size();
+ delete tmp;
+ }
+ SetSize(total);
+}
+
+const char *cLegacyVdrRecording::FirstFile(void)
+{
+ if (!checkBuffer()) return NULL;
+ curFileNo = 1;
+ sprintf(buf, FILE_MASK, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ rv = tmp->AbsolutePath();
+ delete tmp;
+ }
+ return rv;
+}
+
+const char *cLegacyVdrRecording::NextFile(void)
+{
+ if (++curFileNo < movieFiles) {
+ if (!checkBuffer()) return NULL;
+ sprintf(buf, FILE_MASK, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ rv = tmp->AbsolutePath();
+ delete tmp;
+
+ return rv;
+ }
+ }
+ return NULL;
+}
diff --git a/libs/mediaScan/src/MediaFactory.cc b/libs/mediaScan/src/MediaFactory.cc
new file mode 100644
index 0000000..4dec763
--- /dev/null
+++ b/libs/mediaScan/src/MediaFactory.cc
@@ -0,0 +1,148 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaFactory.cc
+ * Created: 2. Juli 2012, 15
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <MediaFactory.h>
+#include <Audio.h>
+#include <Movie.h>
+#include <Picture.h>
+#include <LegacyVdrRecording.h>
+#include <VdrRecording.h>
+#include <DVDImage.h>
+#include <ServerConfig.h>
+#include <StringBuilder.h>
+#include <Logging.h>
+#include <File.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+cMediaFactory::cMediaFactory(const cServerConfig &sc)
+ : config(sc)
+ , baseDirectory(sc.DocumentRoot())
+ , scratch(NULL)
+ , scratchSize(1024)
+{
+ scratch = (char *)malloc(scratchSize);
+}
+
+cMediaFactory::~cMediaFactory()
+{
+ free(scratch);
+}
+
+void cMediaFactory::SetBaseDirectory(const cFile &dir)
+{
+ if (!dir.IsDirectory()) {
+ esyslog("ERROR: attempt to set base directory to a file (%s)", dir.Name());
+ return;
+ }
+ baseDirectory = dir;
+}
+
+int cMediaFactory::createMedia(void *opaque, cFile *Parent, const char *Name)
+{
+ if (!opaque) return -1;
+ cMediaFactory *mf = (cMediaFactory *) opaque;
+
+ return mf->CreateMedia(Parent, Name);
+}
+
+int cMediaFactory::CreateMedia(const cFile *Parent, const char *Name)
+{
+// cManagedVector *pool = (cManagedVector *) opaque;
+ cFile *curFile = new cFile(*Parent, Name);
+ const char *mimeType = NULL;
+ cAbstractMedia *rv = NULL;
+
+ if (!curFile) {
+ esyslog("ERROR: out of memory!");
+ return -1;
+ }
+ if (!curFile->Exists()) {
+ delete curFile;
+ return -1;
+ }
+ if (curFile->IsDirectory()) {
+ static const char *keyFiles[] = { "001.vdr", "00001.ts", "VIDEO_TS/VIDEO_TS.IFO", NULL };
+ cFile *tmp;
+ const char *check;
+ int n=0;
+
+ for (const char **kf = keyFiles; kf && *kf; ++kf, ++n) {
+ tmp = new cFile(*curFile, *kf);
+ check = tmp ? tmp->AbsolutePath() : NULL;
+
+ if (tmp->Exists() && tmp->IsFile() && !tmp->IsDirectory()) {
+ switch (n) {
+ case 0: rv = new cLegacyVdrRecording(*curFile); break;
+ case 1: rv = new cVdrRecording(*curFile); break;
+ default: rv = new cDVDImage(*curFile); break;
+ }
+ }
+ delete tmp;
+ }
+ if (!rv) curFile->VisitFiles(createMedia, this);
+ }
+ else {
+ const char *extension = strrchr(Name, '.');
+
+ if (!extension) {
+ delete curFile;
+
+ return -1;
+ }
+ ++extension;
+ mimeType = cMovie::ContentType(extension);
+ if (mimeType) rv = new cMovie(*curFile, mimeType);
+ else {
+ mimeType = cAudio::ContentType(extension);
+ if (mimeType) rv = new cAudio(*curFile, mimeType);
+ else {
+ mimeType = cPicture::ContentType(extension);
+ if (mimeType) rv = new cPicture(*curFile, mimeType);
+ }
+ }
+ }
+ delete curFile;
+ if (rv) {
+ if (config.WantExtendedScan() && rv->NeedsFurtherScan()) Scan4MetaData(rv);
+ mediaPool->push_back(rv);
+ return 0;
+ }
+ return -1;
+}
+
+void cMediaFactory::Scan4Media(cManagedVector& pool)
+{
+ if (!baseDirectory.Exists() || !baseDirectory.IsDirectory()) return;
+
+ baseDirectory.SetVirtualRoot();
+ mediaPool = &pool;
+ baseDirectory.VisitFiles(createMedia, this);
+}
+
+void cMediaFactory::Scan4MetaData(cAbstractMedia* media)
+{
+ //TODO:
+}
diff --git a/libs/mediaScan/src/Movie.cc b/libs/mediaScan/src/Movie.cc
new file mode 100644
index 0000000..a63ff19
--- /dev/null
+++ b/libs/mediaScan/src/Movie.cc
@@ -0,0 +1,67 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Movie.cc
+ * Created: 2. Juli 2012, 15
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <Movie.h>
+#include <stddef.h>
+#include <string.h>
+
+SupportedExtension cMovie::knownExtensions[] = {
+ { "asd", "video/x-ms-asf" },
+ { "asf", "video/x-ms-asf" },
+ { "avi", "video/x-msvideo" },
+ { "dv", "video/x-dv" },
+ { "flv", "video/x-flv" },
+ { "gl", "video/x-gl" },
+ { "iso", "application/x-iso9660-image" },
+ { "ogv", "video/ogg" },
+ { "mkv", "video/x-matroska" },
+ { "mov", "video/quicktime" },
+ { "mpg", "video/mpeg" },
+ { "mpeg", "video/mpeg" },
+ { "swf", "application/x-shockwave-flash" },
+ { NULL, NULL }
+};
+
+cMovie::cMovie(const cFile &File, const char *Mime, SupportedMediaType Type)
+ : cAbstractMedia(File, Mime, Type)
+{
+}
+
+cMovie::~cMovie()
+{
+}
+
+const char *cMovie::ContentType(const char* Extension)
+{
+ for (SupportedExtension *p = knownExtensions; p && p->extension; ++p) {
+ if (!strcasecmp(p->extension, Extension)) return p->mimeType;
+ }
+ return NULL;
+}
+
+bool cMovie::NeedsFurtherScan(void) const
+{
+//TODO: common meta data: width, height, interlaced
+ return true;
+}
diff --git a/libs/mediaScan/src/Picture.cc b/libs/mediaScan/src/Picture.cc
new file mode 100644
index 0000000..19a02a1
--- /dev/null
+++ b/libs/mediaScan/src/Picture.cc
@@ -0,0 +1,69 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Picture.cc
+ * Created: 2. Juli 2012, 15
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <Picture.h>
+#include <stddef.h>
+#include <string.h>
+
+SupportedExtension cPicture::knownExtensions[] = {
+ { "bmp", "image/x-windows-bmp" },
+ { "gif", "image/gif" },
+ { "jff", "image/jpeg" },
+ { "jfif", "image/jpeg" },
+ { "jif", "image/jpeg" },
+ { "jp2", "image/jp2" },
+ { "jpe", "image/jpeg" },
+ { "jpeg", "image/jpeg" },
+ { "jpg", "image/jpeg" },
+ { "jpm", "image/jpm" },
+ { "jpx", "image/jpx" },
+ { "pbm", "image/x-portable-bitmap" },
+ { "pct", "image/x-pict" },
+ { "pcx", "image/x-pcx" },
+ { "png", "image/png" },
+ { "pnm", "image/x-portable-anymap" },
+ { "ppm", "image/x-portable-pixmap" },
+ { "qti", "image/quicktime" },
+ { "ras", "image/x-cmu-raster" },
+ { "rgb", "image/x-rgb" },
+ { NULL, NULL }
+};
+
+cPicture::cPicture(const cFile &File, const char *Mime)
+: cAbstractMedia(File, Mime, Picture)
+{
+}
+
+cPicture::~cPicture()
+{
+}
+
+const char *cPicture::ContentType(const char* Extension)
+{
+ for (SupportedExtension *p = knownExtensions; p && p->extension; ++p) {
+ if (!strcasecmp(p->extension, Extension)) return p->mimeType;
+ }
+ return NULL;
+}
+
diff --git a/libs/mediaScan/src/VdrRecording.cc b/libs/mediaScan/src/VdrRecording.cc
new file mode 100644
index 0000000..03abccf
--- /dev/null
+++ b/libs/mediaScan/src/VdrRecording.cc
@@ -0,0 +1,103 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: VdrRecording.cc
+ * Created: 3. Juli 2012, 08
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: libfsScan: mediatypes and filesystem scanning
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+#include <VdrRecording.h>
+#include <StringBuilder.h>
+#include <File.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#define FILE_MASK "/%05d.ts"
+
+cVdrRecording::cVdrRecording(const cFile &File)
+ : cAbstractMultiFileMovie(File, "video/mpeg", VdrRecording)
+{
+ cStringBuilder sb;
+ cFile *parent = File.Parent();
+
+ sb.Append(parent->Name());
+ sb.Append(" (").Append(File.Name()).Append(")");
+ delete parent;
+ SetName(sb.toString());
+ bufSize = 10;
+}
+
+cVdrRecording::~cVdrRecording()
+{
+}
+
+void cVdrRecording::Refresh(void)
+{
+ size_t total = 0;
+ cFile *tmp;
+
+ if (!checkBuffer()) return;
+ movieFiles = 0;
+ for (int fileNo = 1;; ++fileNo) {
+ sprintf(buf, FILE_MASK, fileNo);
+ tmp = new cFile(KeyPath(), buf);
+
+ if (!tmp || !tmp->Exists()) {
+ movieFiles = fileNo - 1;
+ delete tmp;
+ break;
+ }
+ total += tmp->Size();
+ delete tmp;
+ }
+ SetSize(total);
+}
+
+const char *cVdrRecording::FirstFile(void)
+{
+ if (!checkBuffer()) return NULL;
+ curFileNo = 1;
+ sprintf(buf, FILE_MASK, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ rv = tmp->AbsolutePath();
+ delete tmp;
+ }
+ return rv;
+}
+
+const char *cVdrRecording::NextFile(void)
+{
+ if (++curFileNo < movieFiles) {
+ if (!checkBuffer()) return NULL;
+ sprintf(buf, FILE_MASK, curFileNo);
+ cFile *tmp = new cFile(KeyPath(), buf);
+ const char *rv = NULL;
+
+ if (tmp) {
+ rv = tmp->AbsolutePath();
+ delete tmp;
+
+ return rv;
+ }
+ }
+ return NULL;
+}