summaryrefslogtreecommitdiff
path: root/libs/mediaScan/src
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-30 15:51:05 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-30 15:51:05 (GMT)
commitad667186c0c45cfca9d3f153faec7ce35545b238 (patch)
treedb5ab8a2bb22c418bc8a233db3c4955ed16957c5 /libs/mediaScan/src
parent41922cdaf9c8db57c6b51f090eefe95b0008a0fb (diff)
downloadcmp-ad667186c0c45cfca9d3f153faec7ce35545b238.tar.gz
cmp-ad667186c0c45cfca9d3f153faec7ce35545b238.tar.bz2
created more readers
Diffstat (limited to 'libs/mediaScan/src')
-rw-r--r--libs/mediaScan/src/MediainfoReader.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/libs/mediaScan/src/MediainfoReader.cc b/libs/mediaScan/src/MediainfoReader.cc
new file mode 100644
index 0000000..cd1f3f6
--- /dev/null
+++ b/libs/mediaScan/src/MediainfoReader.cc
@@ -0,0 +1,69 @@
+/*
+ * File: MediainfoReader.cc
+ * Author: django
+ *
+ * Created on 30. Juli 2012, 15:03
+ */
+#include <MediainfoReader.h>
+#include <LineReader.h>
+#include <stddef.h>
+#include <pcrecpp.h>
+#include <vector>
+
+cMediainfoReader::cMediainfoReader(cLineReader *LineReader)
+ : reader(LineReader)
+{
+}
+
+cMediainfoReader::~cMediainfoReader()
+{
+ Close();
+}
+
+void cMediainfoReader::AddValuableKey(const char* Key)
+{
+ valuableKeys.push_back(Key);
+}
+
+void cMediainfoReader::Close(void)
+{
+ if (reader) {
+ delete reader;
+ reader = NULL;
+ }
+}
+
+bool cMediainfoReader::IsValuable(std::string &key)
+{
+ for (size_t i=0; i < valuableKeys.size(); ++i) {
+ if (!strcmp(key.c_str(), valuableKeys[i].c_str()))
+ return true;
+ }
+ return false;
+}
+
+cMediainfoReader::InfoEntry *cMediainfoReader::ReadEntry()
+{
+ if (!reader) return NULL;
+ const char *line = reader->ReadLine();
+ static pcrecpp::RE comment("^\\s*#.*$");
+ static pcrecpp::RE emptyLine("^\\s*$");
+ static pcrecpp::RE entry("^\\s*(.+?)\\s*:\\s*(.+?)\\s*$");
+ std::string name, value;
+ InfoEntry *rv = NULL;
+
+ while (line && (comment.FullMatch(line) || emptyLine.FullMatch(line)))
+ line = reader->ReadLine();
+ while (line && !entry.FullMatch(line, &name, &value))
+ line = reader->ReadLine();
+ while (line && entry.FullMatch(line, &name, &value)) {
+ if (!IsValuable(name)) {
+ line = reader->ReadLine();
+ continue;
+ }
+ rv = new InfoEntry(name, value);
+ break;
+ }
+ return rv;
+}
+