diff options
Diffstat (limited to 'libs/mediaScan/src')
-rw-r--r-- | libs/mediaScan/src/AbstractMedia.cc | 18 | ||||
-rw-r--r-- | libs/mediaScan/src/Audio.cc | 49 | ||||
-rw-r--r-- | libs/mediaScan/src/Movie.cc | 20 |
3 files changed, 85 insertions, 2 deletions
diff --git a/libs/mediaScan/src/AbstractMedia.cc b/libs/mediaScan/src/AbstractMedia.cc index 2cc85c5..40b94ea 100644 --- a/libs/mediaScan/src/AbstractMedia.cc +++ b/libs/mediaScan/src/AbstractMedia.cc @@ -36,9 +36,14 @@ #include <unistd.h> #include <tuple> #include <iostream> +#include <string> cAbstractMedia::cAbstractMedia(const cFile &File, const char *Mime, SupportedMediaType Type) : fd(-1) + , format(NULL) + , width(0) + , height(0) + , aspect(0) , mediaType(Type) , mimeType(Mime ? strdup(Mime) : NULL) , uri(NULL) @@ -54,10 +59,18 @@ cAbstractMedia::~cAbstractMedia() free(mimeType); free(uri); free(logicalPath); + free(format); } void cAbstractMedia::AddMeta(cMediainfoReader::InfoEntry* Entry) { + if (!Entry) return; + std::string name = std::get<0>(*Entry); + std::string value = std::get<1>(*Entry); + + if (!strcmp("Format", name.c_str()) && !format) SetFormat(value.c_str()); + else if (!strcmp("Width", name.c_str())) width = parseInt(value); + else if (!strcmp("Height", name.c_str())) height = parseInt(value); meta.push_back(Entry); } @@ -117,6 +130,11 @@ void cAbstractMedia::Reset(void) } } +void cAbstractMedia::SetFormat(const char *Format) +{ + format = strdup(Format); +} + void cAbstractMedia::SetMediaType(int NewType) { switch (NewType) { diff --git a/libs/mediaScan/src/Audio.cc b/libs/mediaScan/src/Audio.cc index fdaae7e..9420db6 100644 --- a/libs/mediaScan/src/Audio.cc +++ b/libs/mediaScan/src/Audio.cc @@ -23,8 +23,10 @@ * -------------------------------------------------------------- */ #include <Audio.h> +#include <StringBuilder.h> #include <stddef.h> #include <string.h> +#include <util.h> static bool deepScanEnabled = false; @@ -50,11 +52,23 @@ SupportedExtension cAudio::knownExtensions[] = { cAudio::cAudio(const cFile &File, const char *Mime) : cAbstractMedia(File, Mime, Audio) + , name(NULL) { } cAudio::~cAudio() { + free(name); +} + +void cAudio::AddMeta(cMediainfoReader::InfoEntry* Entry) +{ + if (!Entry) return; + std::string name = std::get<0>(*Entry); + std::string value = std::get<1>(*Entry); + + if (!strcmp("Bit rate", name.c_str())) width = parseInt(value); + cAbstractMedia::AddMeta(Entry); } void cAudio::EnableDeepScan(bool DoScan) @@ -70,6 +84,41 @@ const char *cAudio::ContentType(const char* Extension) return NULL; } +const char *cAudio::Name(void) const +{ + if (!name) { + cMediainfoReader::InfoEntry *performer = NULL, *album = NULL, *track = NULL; + + for (size_t i=0; i < meta.size(); ++i) { + cMediainfoReader::InfoEntry *ie = meta[i]; + std::string name = std::get<0>(*ie); + + if (!strcmp("Album", name.c_str())) album = ie; + else if (!strcmp("Performer", name.c_str())) performer = ie; + else if (!strcmp("Track name", name.c_str())) track = ie; + } + + if (track) { + std::string tmp = std::get<1>(*track); + cStringBuilder sb(tmp.c_str()); + + if (performer) { + tmp = std::get<1>(*performer); + sb.Append(" / ").Append(tmp.c_str()); + } + if (album) { + tmp = std::get<1>(*album); + sb.Append(" (").Append(tmp.c_str()).Append(")"); + } + name = sb.toString(); + } + else { + name = strdup(cAbstractMedia::Name()); + } + } + return name; +} + bool cAudio::NeedsFurtherScan(void) const { return deepScanEnabled; diff --git a/libs/mediaScan/src/Movie.cc b/libs/mediaScan/src/Movie.cc index d161dfe..51d1ff9 100644 --- a/libs/mediaScan/src/Movie.cc +++ b/libs/mediaScan/src/Movie.cc @@ -25,6 +25,7 @@ #include <Movie.h> #include <stddef.h> #include <string.h> +#include <util.h> static bool deepScanEnabled = true; @@ -64,8 +65,16 @@ const char *cMovie::ContentType(const char* Extension) 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); + if (!Entry) return; + std::string name = std::get<0>(*Entry); + std::string value = std::get<1>(*Entry); + + if (!strcmp("Scan type", name.c_str())) { + if (!strcmp("Interlaced", value.c_str())) SetMediaType(MediaType() + 1); + } + else if (!strcmp("Aspect", name.c_str())) { + aspect = parseAspect(value); + if (height > 0 && width > 0) width = height * aspect; } cAbstractMedia::AddMeta(Entry); } @@ -79,3 +88,10 @@ bool cMovie::NeedsFurtherScan(void) const { return deepScanEnabled; } + +void cMovie::SetFormat(const char* Format) { + if (!strcmp("Matroska", Format) || !strcmp("Flash Video", Format) + || !strcmp("MPEG-PS", Format) || !strcmp("MPEG-TS", Format) || !strcmp("MPEG-PES", Format)) + return; // skip containers + cAbstractMedia::SetFormat(Format); +}
\ No newline at end of file |