- split out meta parser
[enigma2.git] / lib / dvb / metaparser.cpp
diff --git a/lib/dvb/metaparser.cpp b/lib/dvb/metaparser.cpp
new file mode 100644 (file)
index 0000000..8c1f0cf
--- /dev/null
@@ -0,0 +1,44 @@
+#include <lib/dvb/metaparser.h>
+#include <errno.h>
+
+int eDVBMetaParser::parseFile(const std::string &tsname)
+{
+               /* if it's a PVR channel, recover service id. */
+       std::string filename = tsname + ".meta";
+               
+       FILE *f = fopen(filename.c_str(), "r");
+       if (!f)
+               return -ENOENT;
+
+       int linecnt = 0;
+       
+       while (1)
+       {
+               char line[1024];
+               if (!fgets(line, 1024, f))
+                       break;
+               if (*line && line[strlen(line)-1] == '\n')
+                       line[strlen(line)-1] = 0;
+
+               if (*line && line[strlen(line)-1] == '\r')
+                       line[strlen(line)-1] = 0;
+
+               switch (linecnt)
+               {
+               case 0:
+                       m_ref = (eServiceReferenceDVB&)eServiceReference(line);
+                       break;
+               case 1:
+                       m_name = line;
+                       break;
+               case 2:
+                       m_description = line;
+                       break;
+               default:
+                       break;
+               }
+               ++linecnt;
+       }
+       fclose(f);
+       return 0;
+}