1 #include <lib/dvb/metaparser.h>
2 #include <lib/base/eerror.h>
5 eDVBMetaParser::eDVBMetaParser()
13 int eDVBMetaParser::parseFile(const std::string &basename)
15 /* first, try parsing the .meta file */
16 if (!parseMeta(basename))
19 /* otherwise, use recordings.epl */
20 return parseRecordings(basename);
23 int eDVBMetaParser::parseMeta(const std::string &tsname)
25 /* if it's a PVR channel, recover service id. */
26 std::string filename = tsname + ".meta";
28 FILE *f = fopen(filename.c_str(), "r");
39 if (!fgets(line, 1024, f))
41 if (*line && line[strlen(line)-1] == '\n')
42 line[strlen(line)-1] = 0;
44 if (*line && line[strlen(line)-1] == '\r')
45 line[strlen(line)-1] = 0;
50 m_ref = eServiceReferenceDVB(line);
59 m_time_create = atoi(line);
65 m_length = atoi(line); //movielength in pts
68 m_filesize = atoll(line);
80 int eDVBMetaParser::parseRecordings(const std::string &filename)
82 std::string::size_type slash = filename.rfind('/');
83 if (slash == std::string::npos)
86 std::string recordings = filename.substr(0, slash) + "/recordings.epl";
88 FILE *f = fopen(recordings.c_str(), "r");
91 // eDebug("no recordings.epl found: %s: %m", recordings.c_str());
95 std::string description;
96 eServiceReferenceDVB ref;
98 // eDebug("parsing recordings.epl..");
103 if (!fgets(line, 1024, f))
107 line[strlen(line)-1] = 0;
109 if (strlen(line) && line[strlen(line)-1] == '\r')
110 line[strlen(line)-1] = 0;
112 if (!strncmp(line, "#SERVICE: ", 10))
113 ref = eServiceReferenceDVB(line + 10);
114 if (!strncmp(line, "#DESCRIPTION: ", 14))
115 description = line + 14;
116 if ((line[0] == '/') && (ref.path.substr(ref.path.find_last_of('/')) == filename.substr(filename.find_last_of('/'))))
118 // eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
120 m_name = description;
128 updateMeta(filename.c_str());
136 int eDVBMetaParser::updateMeta(const std::string &tsname)
138 /* write meta file only if we have valid data. Note that we might convert recordings.epl data to .meta, which is fine. */
141 std::string filename = tsname + ".meta";
142 eServiceReference ref = m_ref;
145 FILE *f = fopen(filename.c_str(), "w");
148 fprintf(f, "%s\n%s\n%s\n%d\n%s\n%d\n%lld\n", ref.toString().c_str(), m_name.c_str(), m_description.c_str(), m_time_create, m_tags.c_str(), m_length, m_filesize );