diff options
author | geronimo <geronimo013@gmx.de> | 2012-08-01 17:29:31 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-08-01 17:29:31 +0200 |
commit | cca6e883c8141c3a67c3c5b232ce0c9b18e7fd59 (patch) | |
tree | 7149351cb466316771ab0ce0bd4ea64b2ba17aa1 /libs/mediaScan/src | |
parent | 76c51473ee29a9103201618c8dbbc11fe9b7149e (diff) | |
download | cmp-cca6e883c8141c3a67c3c5b232ce0c9b18e7fd59.tar.gz cmp-cca6e883c8141c3a67c3c5b232ce0c9b18e7fd59.tar.bz2 |
added mediatypes for interlaced video and selective configuration of deepscan
Diffstat (limited to 'libs/mediaScan/src')
-rw-r--r-- | libs/mediaScan/src/AbstractMedia.cc | 58 | ||||
-rw-r--r-- | libs/mediaScan/src/AbstractMultiFileMovie.cc | 8 | ||||
-rw-r--r-- | libs/mediaScan/src/Audio.cc | 10 | ||||
-rw-r--r-- | libs/mediaScan/src/DVDImage.cc | 17 | ||||
-rw-r--r-- | libs/mediaScan/src/FSMediaScanner.cc | 18 | ||||
-rw-r--r-- | libs/mediaScan/src/LegacyVdrRecording.cc | 17 | ||||
-rw-r--r-- | libs/mediaScan/src/MediaFactory.cc | 19 | ||||
-rw-r--r-- | libs/mediaScan/src/MediainfoReader.cc | 16 | ||||
-rw-r--r-- | libs/mediaScan/src/Movie.cc | 18 | ||||
-rw-r--r-- | libs/mediaScan/src/Picture.cc | 11 | ||||
-rw-r--r-- | libs/mediaScan/src/VdrRecording.cc | 17 |
11 files changed, 177 insertions, 32 deletions
diff --git a/libs/mediaScan/src/AbstractMedia.cc b/libs/mediaScan/src/AbstractMedia.cc index 98c72bb..2cc85c5 100644 --- a/libs/mediaScan/src/AbstractMedia.cc +++ b/libs/mediaScan/src/AbstractMedia.cc @@ -34,6 +34,8 @@ #include <fcntl.h> #include <errno.h> #include <unistd.h> +#include <tuple> +#include <iostream> cAbstractMedia::cAbstractMedia(const cFile &File, const char *Mime, SupportedMediaType Type) : fd(-1) @@ -54,6 +56,27 @@ cAbstractMedia::~cAbstractMedia() free(logicalPath); } +void cAbstractMedia::AddMeta(cMediainfoReader::InfoEntry* Entry) +{ + meta.push_back(Entry); +} + +void cAbstractMedia::Dump(void) const +{ + std::cout << MediaType2Text(mediaType) << " [" << mimeType << "] - ( " << Name() << " ) => " << logicalPath << std::endl; + std::cout << "\tkey-file: " << KeyFile() << std::endl; + for (size_t i=0; i < meta.size(); ++i) { + cMediainfoReader::InfoEntry *ie = meta[i]; + + std::cout << "\tmeta - [" << std::get<0>(*ie) << "] => " << std::get<1>(*ie) << std::endl; + } +} + +const char *cAbstractMedia::KeyFile(void) const +{ + return keyPath.AbsolutePath(); +} + const char *cAbstractMedia::Name(void) const { return keyPath.Name(); @@ -94,6 +117,19 @@ void cAbstractMedia::Reset(void) } } +void cAbstractMedia::SetMediaType(int NewType) +{ + switch (NewType) { + case IMovie: + case IDVDImage: + case ILegacyVdrRecording: + case IVdrRecording: + if (mediaType == (NewType - 1)) mediaType = (SupportedMediaType) NewType; + break; + default: break; + } +} + size_t cAbstractMedia::Size(void) const { return keyPath.Size(); @@ -101,15 +137,19 @@ size_t cAbstractMedia::Size(void) const 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); - } + switch (Type) { + case Audio: return TO_STRING(Audio); + case Movie: return TO_STRING(Movie); + case IMovie: return TO_STRING(IMovie); + case DVDImage: return TO_STRING(DVDImage); + case IDVDImage: return TO_STRING(IDVDImage); + case LegacyVdrRecording: return TO_STRING(LegacyVdrRecording); + case ILegacyVdrRecording: return TO_STRING(ILegacyVdrRecording); + case VdrRecording: return TO_STRING(VdrRecording); + case IVdrRecording: return TO_STRING(IVdrRecording); + case Picture: return TO_STRING(Picture); + default: return TO_STRING(Invalid); + } } bool cAbstractMedia::NeedsFurtherScan(void) const diff --git a/libs/mediaScan/src/AbstractMultiFileMovie.cc b/libs/mediaScan/src/AbstractMultiFileMovie.cc index 7ff8b10..ee7121c 100644 --- a/libs/mediaScan/src/AbstractMultiFileMovie.cc +++ b/libs/mediaScan/src/AbstractMultiFileMovie.cc @@ -45,7 +45,7 @@ cAbstractMultiFileMovie::~cAbstractMultiFileMovie() free(buf); } -bool cAbstractMultiFileMovie::checkBuffer() +bool cAbstractMultiFileMovie::checkBuffer(void) const { if (!buf && bufSize) { buf = (char *) malloc(bufSize); @@ -53,12 +53,18 @@ bool cAbstractMultiFileMovie::checkBuffer() return buf != NULL; } +const char *cAbstractMultiFileMovie::KeyFile(void) const +{ + return FirstFile(); +} + size_t cAbstractMultiFileMovie::ReadChunk(char* Buf, size_t bufSize) { long rv = 0; const char *path = NULL; if (fd < 1) { + curFileNo = 1; path = FirstFile(); fd = open(path, O_RDONLY | O_LARGEFILE); if (fd < 1) { diff --git a/libs/mediaScan/src/Audio.cc b/libs/mediaScan/src/Audio.cc index a17517f..fdaae7e 100644 --- a/libs/mediaScan/src/Audio.cc +++ b/libs/mediaScan/src/Audio.cc @@ -26,6 +26,8 @@ #include <stddef.h> #include <string.h> +static bool deepScanEnabled = false; + SupportedExtension cAudio::knownExtensions[] = { { "aac", "audio/aac" }, { "aif", "audio/x-aiff" }, @@ -55,6 +57,11 @@ cAudio::~cAudio() { } +void cAudio::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + const char *cAudio::ContentType(const char* Extension) { for (SupportedExtension *p = knownExtensions; p && p->extension; ++p) { @@ -65,6 +72,5 @@ const char *cAudio::ContentType(const char* Extension) bool cAudio::NeedsFurtherScan(void) const { -//TODO: common meta data: artist, title - return true; + return deepScanEnabled; } diff --git a/libs/mediaScan/src/DVDImage.cc b/libs/mediaScan/src/DVDImage.cc index 1df6d1e..0ddcdac 100644 --- a/libs/mediaScan/src/DVDImage.cc +++ b/libs/mediaScan/src/DVDImage.cc @@ -30,6 +30,8 @@ #include "File.h" #define FILE_MASK "VIDEO_TS/VTS_%02d_%d.VOB" +static bool deepScanEnabled = true; + cDVDImage::cDVDImage(const cFile &File) : cAbstractMultiFileMovie(File, "video/mpeg", DVDImage) { @@ -50,6 +52,16 @@ size_t cDVDImage::Size(void) const return cAbstractMedia::Size(); } +void cDVDImage::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + +bool cDVDImage::NeedsFurtherScan(void) const +{ + return deepScanEnabled; +} + void cDVDImage::Refresh(void) { size_t maxSize = 0; @@ -82,12 +94,11 @@ void cDVDImage::Refresh(void) SetSize(total); } -const char *cDVDImage::FirstFile(void) +const char *cDVDImage::FirstFile(void) const { if (!checkBuffer()) return NULL; - curFileNo = 1; - sprintf(buf, FILE_MASK, mainMovie, curFileNo); + sprintf(buf, FILE_MASK, mainMovie, 1); cFile *tmp = new cFile(KeyPath(), buf); const char *rv = NULL; diff --git a/libs/mediaScan/src/FSMediaScanner.cc b/libs/mediaScan/src/FSMediaScanner.cc index 2df5907..a635f17 100644 --- a/libs/mediaScan/src/FSMediaScanner.cc +++ b/libs/mediaScan/src/FSMediaScanner.cc @@ -35,6 +35,23 @@ #include <errno.h> #include <util.h> +static const char *MetaKeys[] = { + "Format" +// Audio +, "Duration" +, "Album" +, "Track name" +, "Performer" +, "Bit rate" +// Image +, "Width" +, "Height" +// Video +, "Display aspect ratio" +, "Scan type" +, NULL + }; + void freeMediaCallback(void *elem) { delete (cAbstractMedia *)elem; @@ -82,6 +99,7 @@ void cFSMediaScanner::Refresh() pool.clear(); categories.clear(); + cMediainfoReader::Setup(MetaKeys); mediaFactory->Scan4Media(pool); cAbstractMedia::SupportedMediaType ot = cAbstractMedia::Invalid; cAbstractMedia *m; diff --git a/libs/mediaScan/src/LegacyVdrRecording.cc b/libs/mediaScan/src/LegacyVdrRecording.cc index 3c74b6e..2b4d7af 100644 --- a/libs/mediaScan/src/LegacyVdrRecording.cc +++ b/libs/mediaScan/src/LegacyVdrRecording.cc @@ -31,6 +31,8 @@ #define FILE_MASK "%03d.vdr" +static bool deepScanEnabled = true; + cLegacyVdrRecording::cLegacyVdrRecording(const cFile &File) : cAbstractMultiFileMovie(File, "video/mpeg", LegacyVdrRecording) { @@ -48,6 +50,16 @@ cLegacyVdrRecording::~cLegacyVdrRecording() { } +void cLegacyVdrRecording::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + +bool cLegacyVdrRecording::NeedsFurtherScan(void) const +{ + return deepScanEnabled; +} + void cLegacyVdrRecording::Refresh(void) { size_t total = 0; @@ -70,11 +82,10 @@ void cLegacyVdrRecording::Refresh(void) SetSize(total); } -const char *cLegacyVdrRecording::FirstFile(void) +const char *cLegacyVdrRecording::FirstFile(void) const { if (!checkBuffer()) return NULL; - curFileNo = 1; - sprintf(buf, FILE_MASK, curFileNo); + sprintf(buf, FILE_MASK, 1); cFile *tmp = new cFile(KeyPath(), buf); const char *rv = NULL; diff --git a/libs/mediaScan/src/MediaFactory.cc b/libs/mediaScan/src/MediaFactory.cc index 0af2fae..1a61dc8 100644 --- a/libs/mediaScan/src/MediaFactory.cc +++ b/libs/mediaScan/src/MediaFactory.cc @@ -23,6 +23,9 @@ * -------------------------------------------------------------- */ #include <MediaFactory.h> +#include <MediainfoReader.h> +#include <LineReader.h> +#include <CommandReader.h> #include <Audio.h> #include <Movie.h> #include <Picture.h> @@ -70,7 +73,6 @@ int cMediaFactory::createMedia(void *opaque, cFile *Parent, const char *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; @@ -126,7 +128,10 @@ int cMediaFactory::CreateMedia(const cFile *Parent, const char *Name) } delete curFile; if (rv) { - if (config.WantExtendedScan() && rv->NeedsFurtherScan()) Scan4MetaData(rv); + if (config.WantExtendedScan() && rv->NeedsFurtherScan()) { + rv->Refresh(); + Scan4MetaData(rv); + } mediaPool->push_back(rv); return 0; } @@ -144,5 +149,13 @@ void cMediaFactory::Scan4Media(cManagedVector& pool) void cMediaFactory::Scan4MetaData(cAbstractMedia* media) { - //TODO: + cCommandReader *cr = new cCommandReader("/usr/bin/mediainfo"); + cMediainfoReader *mir = new cMediainfoReader(new cLineReader(cr)); + cMediainfoReader::InfoEntry *ie; + + cr->AddCommandParameter(media->KeyFile()); + while ((ie = mir->ReadEntry())) { + media->AddMeta(ie); + } + delete mir; } diff --git a/libs/mediaScan/src/MediainfoReader.cc b/libs/mediaScan/src/MediainfoReader.cc index 388c1c3..1668cbf 100644 --- a/libs/mediaScan/src/MediainfoReader.cc +++ b/libs/mediaScan/src/MediainfoReader.cc @@ -31,6 +31,8 @@ static pcrecpp::RE comment("^\\s*#.*$"); static pcrecpp::RE emptyLine("^\\s*$"); static pcrecpp::RE entry("^\\s*(.+?)\\s*:\\s*(.+?)\\s*$"); +std::vector<std::string> cMediainfoReader::valuableKeys; + cMediainfoReader::cMediainfoReader(cLineReader *LineReader) : reader(LineReader) @@ -42,11 +44,6 @@ cMediainfoReader::~cMediainfoReader() Close(); } -void cMediainfoReader::AddValuableKey(const char* Key) -{ - valuableKeys.push_back(Key); -} - void cMediainfoReader::Close(void) { if (reader) { @@ -80,7 +77,14 @@ cMediainfoReader::InfoEntry *cMediainfoReader::ReadEntry() } line = reader->ReadLine(); } while (line && !rv); - + return rv; } +void cMediainfoReader::Setup(const char* keys[]) +{ + valuableKeys.clear(); + for (const char **p = keys; p && *p; ++p) { + valuableKeys.push_back(*p); + } +}
\ No newline at end of file diff --git a/libs/mediaScan/src/Movie.cc b/libs/mediaScan/src/Movie.cc index 042b397..d161dfe 100644 --- a/libs/mediaScan/src/Movie.cc +++ b/libs/mediaScan/src/Movie.cc @@ -26,6 +26,8 @@ #include <stddef.h> #include <string.h> +static bool deepScanEnabled = true; + SupportedExtension cMovie::knownExtensions[] = { { "asd", "video/x-ms-asf" }, { "asf", "video/x-ms-asf" }, @@ -60,8 +62,20 @@ const char *cMovie::ContentType(const char* Extension) return NULL; } +void cMovie::AddMeta(cMediainfoReader::InfoEntry *Entry) +{ + if (!strcmp("Scan type", std::get<0>(*Entry).c_str())) { + if (!strcmp("Interlaced", std::get<1>(*Entry).c_str())) SetMediaType(MediaType() + 1); + } + cAbstractMedia::AddMeta(Entry); +} + +void cMovie::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + bool cMovie::NeedsFurtherScan(void) const { -//TODO: common meta data: width, height, interlaced - return true; + return deepScanEnabled; } diff --git a/libs/mediaScan/src/Picture.cc b/libs/mediaScan/src/Picture.cc index 5253a78..0401401 100644 --- a/libs/mediaScan/src/Picture.cc +++ b/libs/mediaScan/src/Picture.cc @@ -26,6 +26,8 @@ #include <stddef.h> #include <string.h> +static bool deepScanEnabled = false; + SupportedExtension cPicture::knownExtensions[] = { { "bmp", "image/x-windows-bmp" }, { "gif", "image/gif" }, @@ -67,3 +69,12 @@ const char *cPicture::ContentType(const char* Extension) return NULL; } +void cPicture::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + +bool cPicture::NeedsFurtherScan(void) const +{ + return deepScanEnabled; +} diff --git a/libs/mediaScan/src/VdrRecording.cc b/libs/mediaScan/src/VdrRecording.cc index 10b6476..bf1eaab 100644 --- a/libs/mediaScan/src/VdrRecording.cc +++ b/libs/mediaScan/src/VdrRecording.cc @@ -30,6 +30,8 @@ #include <stdio.h> #define FILE_MASK "/%05d.ts" +static bool deepScanEnabled = true; + cVdrRecording::cVdrRecording(const cFile &File) : cAbstractMultiFileMovie(File, "video/mpeg", VdrRecording) { @@ -47,6 +49,16 @@ cVdrRecording::~cVdrRecording() { } +void cVdrRecording::EnableDeepScan(bool DoScan) +{ + deepScanEnabled = DoScan; +} + +bool cVdrRecording::NeedsFurtherScan(void) const +{ + return deepScanEnabled; +} + void cVdrRecording::Refresh(void) { size_t total = 0; @@ -69,11 +81,10 @@ void cVdrRecording::Refresh(void) SetSize(total); } -const char *cVdrRecording::FirstFile(void) +const char *cVdrRecording::FirstFile(void) const { if (!checkBuffer()) return NULL; - curFileNo = 1; - sprintf(buf, FILE_MASK, curFileNo); + sprintf(buf, FILE_MASK, 1); cFile *tmp = new cFile(KeyPath(), buf); const char *rv = NULL; |