1 #include <lib/dvb/metaparser.h>
2 #include <lib/base/eerror.h>
5 eDVBMetaParser::eDVBMetaParser()
14 int eDVBMetaParser::parseFile(const std::string &basename)
16 /* first, try parsing the .meta file */
17 if (!parseMeta(basename))
20 /* otherwise, use recordings.epl */
21 if (!parseRecordings(basename))
23 m_filesize = fileSize(basename);
28 long long eDVBMetaParser::fileSize(const std::string &basename)
30 long long filesize = 0;
34 if (!stat64(basename.c_str(), &s))
35 filesize = (long long) s.st_size;
36 /* handling for old splitted recordings (enigma 1) */
40 snprintf(buf, 255, "%s.%03d", basename.c_str(), slice++);
41 if (stat64(buf, &s) < 0)
43 filesize += (long long) s.st_size;
48 int eDVBMetaParser::parseMeta(const std::string &tsname)
50 /* if it's a PVR channel, recover service id. */
51 std::string filename = tsname + ".meta";
53 FILE *f = fopen(filename.c_str(), "r");
64 if (!fgets(line, 1024, f))
66 if (*line && line[strlen(line)-1] == '\n')
67 line[strlen(line)-1] = 0;
69 if (*line && line[strlen(line)-1] == '\r')
70 line[strlen(line)-1] = 0;
75 m_ref = eServiceReferenceDVB(line);
84 m_time_create = atoi(line);
90 m_length = atoi(line); //movielength in pts
93 m_filesize = atoll(line);
96 m_service_data = line;
99 m_scrambled = atoi(line);
111 int eDVBMetaParser::parseRecordings(const std::string &filename)
113 std::string::size_type slash = filename.rfind('/');
114 if (slash == std::string::npos)
117 std::string recordings = filename.substr(0, slash) + "/recordings.epl";
119 FILE *f = fopen(recordings.c_str(), "r");
122 // eDebug("no recordings.epl found: %s: %m", recordings.c_str());
126 std::string description;
127 eServiceReferenceDVB ref;
129 // eDebug("parsing recordings.epl..");
134 if (!fgets(line, 1024, f))
138 line[strlen(line)-1] = 0;
140 if (strlen(line) && line[strlen(line)-1] == '\r')
141 line[strlen(line)-1] = 0;
143 if (!strncmp(line, "#SERVICE: ", 10))
144 ref = eServiceReferenceDVB(line + 10);
145 if (!strncmp(line, "#DESCRIPTION: ", 14))
146 description = line + 14;
147 if ((line[0] == '/') && (ref.path.substr(ref.path.find_last_of('/')) == filename.substr(filename.find_last_of('/'))))
149 // eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
151 m_name = description;
155 m_filesize = fileSize(filename);
159 updateMeta(filename.c_str());
167 int eDVBMetaParser::updateMeta(const std::string &tsname)
169 /* write meta file only if we have valid data. Note that we might convert recordings.epl data to .meta, which is fine. */
172 std::string filename = tsname + ".meta";
173 eServiceReference ref = m_ref;
176 FILE *f = fopen(filename.c_str(), "w");
179 fprintf(f, "%s\n%s\n%s\n%d\n%s\n%d\n%lld\n%s\n%d\n", ref.toString().c_str(), m_name.c_str(), m_description.c_str(), m_time_create, m_tags.c_str(), m_length, m_filesize, m_service_data.c_str(), m_scrambled);