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 if (!parseRecordings(basename))
22 m_filesize = fileSize(basename);
27 long long eDVBMetaParser::fileSize(const std::string &basename)
29 long long filesize = 0;
33 if (!stat64(basename.c_str(), &s))
34 filesize = (long long) s.st_size;
35 /* handling for old splitted recordings (enigma 1) */
39 snprintf(buf, 255, "%s.%03d", basename.c_str(), slice++);
40 if (stat64(buf, &s) < 0)
42 filesize += (long long) s.st_size;
47 int eDVBMetaParser::parseMeta(const std::string &tsname)
49 /* if it's a PVR channel, recover service id. */
50 std::string filename = tsname + ".meta";
52 FILE *f = fopen(filename.c_str(), "r");
63 if (!fgets(line, 1024, f))
65 if (*line && line[strlen(line)-1] == '\n')
66 line[strlen(line)-1] = 0;
68 if (*line && line[strlen(line)-1] == '\r')
69 line[strlen(line)-1] = 0;
74 m_ref = eServiceReferenceDVB(line);
83 m_time_create = atoi(line);
89 m_length = atoi(line); //movielength in pts
92 m_filesize = atoll(line);
95 m_service_data = line;
107 int eDVBMetaParser::parseRecordings(const std::string &filename)
109 std::string::size_type slash = filename.rfind('/');
110 if (slash == std::string::npos)
113 std::string recordings = filename.substr(0, slash) + "/recordings.epl";
115 FILE *f = fopen(recordings.c_str(), "r");
118 // eDebug("no recordings.epl found: %s: %m", recordings.c_str());
122 std::string description;
123 eServiceReferenceDVB ref;
125 // eDebug("parsing recordings.epl..");
130 if (!fgets(line, 1024, f))
134 line[strlen(line)-1] = 0;
136 if (strlen(line) && line[strlen(line)-1] == '\r')
137 line[strlen(line)-1] = 0;
139 if (!strncmp(line, "#SERVICE: ", 10))
140 ref = eServiceReferenceDVB(line + 10);
141 if (!strncmp(line, "#DESCRIPTION: ", 14))
142 description = line + 14;
143 if ((line[0] == '/') && (ref.path.substr(ref.path.find_last_of('/')) == filename.substr(filename.find_last_of('/'))))
145 // eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
147 m_name = description;
151 m_filesize = fileSize(filename);
155 updateMeta(filename.c_str());
163 int eDVBMetaParser::updateMeta(const std::string &tsname)
165 /* write meta file only if we have valid data. Note that we might convert recordings.epl data to .meta, which is fine. */
168 std::string filename = tsname + ".meta";
169 eServiceReference ref = m_ref;
172 FILE *f = fopen(filename.c_str(), "w");
175 fprintf(f, "%s\n%s\n%s\n%d\n%s\n%d\n%lld\n%s\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() );