1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#include <lib/dvb/metaparser.h>
#include <lib/base/eerror.h>
#include <errno.h>
eDVBMetaParser::eDVBMetaParser()
{
m_time_create = 0;
}
int eDVBMetaParser::parseFile(const std::string &basename)
{
/* first, try parsing the .meta file */
if (!parseMeta(basename))
return 0;
/* otherwise, use recordings.epl */
return parseRecordings(basename);
}
int eDVBMetaParser::parseMeta(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;
m_time_create = 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(line);
break;
case 1:
m_name = line;
break;
case 2:
m_description = line;
break;
case 3:
m_time_create = atoi(line);
break;
default:
break;
}
++linecnt;
}
fclose(f);
return 0;
}
int eDVBMetaParser::parseRecordings(const std::string &filename)
{
std::string::size_type slash = filename.rfind('/');
if (slash == std::string::npos)
return -1;
std::string recordings = filename.substr(0, slash) + "/recordings.epl";
FILE *f = fopen(recordings.c_str(), "r");
if (!f)
{
// eDebug("no recordings.epl found: %s: %m", recordings.c_str());
return -1;
}
std::string description;
eServiceReferenceDVB ref;
// eDebug("parsing recordings.epl..");
while (1)
{
char line[1024];
if (!fgets(line, 1024, f))
break;
if (strlen(line))
line[strlen(line)-1] = 0;
if (strlen(line) && line[strlen(line)-1] == '\r')
line[strlen(line)-1] = 0;
if (!strncmp(line, "#SERVICE: ", 10))
ref = eServiceReferenceDVB(line + 10);
if (!strncmp(line, "#DESCRIPTION: ", 14))
description = line + 14;
if ((line[0] == '/') && (ref.path == filename))
{
// eDebug("hit! ref %s descr %s", m_ref.toString().c_str(), m_name.c_str());
m_ref = ref;
m_name = description;
m_description = "";
m_time_create = 0;
fclose(f);
return 0;
}
}
fclose(f);
return -1;
}
|