forked from 3PO/epgd-plugin-tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvm.h
188 lines (146 loc) · 4.78 KB
/
tvm.h
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* tvm.h
*
* See the README file for copyright information
*
*/
#include "epgd.h"
#include <math.h>
#define TVM_VERSION "0.1.4"
//***************************************************************************
// Tvm2
//***************************************************************************
class Tvm2 : public Plugin
{
public:
Tvm2();
virtual ~Tvm2();
int init(cEpgd* aObject, int aUtf8);
int initDb();
int exitDb();
int atConfigItem(const char* Name, const char* Value);
const char* getSource() { return "tvm"; }
int getPicture(const char* imagename, const char* fileRef, MemoryStruct* data);
int processDay(int day, int fullupdate, Statistic* stat);
int cleanupAfter();
const char* userAgent() { return "Mozilla/4.0 (compatible; Clickfinder 5.3; Windows NT 5.2)"; }
int ready();
protected:
int processFile(const char* extid, MemoryStruct* data, const char* fileName, const char* fileRef);
int downloadImageFile(const char* extid);
int createXml(const char* extid, MemoryStruct* xmlData);
int zipValid(MemoryStruct* data);
xsltStylesheetPtr pxsltStylesheet;
cDbStatement* stmtMarkOldEvents;
cDbStatement* stmtSetUpdFlgByFileref;
cDbStatement* selectDistBySource;
cDbStatement* selectId;
cDbValue* valueFileRef;
// config
int timeout;
};
// TVM specific stuff
/*
Time is measured by TV Movie in TVM-ticks, which are linear with some unknown time being zero. I have
aligned manually two points on this time axis, which are epoch (in TVM-ticks) and unixTimeEpoch (in
UNIX time, seconds since 1970). The conversion factor is given by factor.
Gives the TV-Movie-ticks equivalent to the UNIX time ggiven in unixTimeEpoch.
*/
const uint64_t epoch = 4675708794760826425LL;
const double factor = 95443717 / 60.0; // Number of TVM-ticks in per second.
const unsigned int unixTimeEpoch = 1233270600;
//***************************************************************************
// Field
//***************************************************************************
class Field
{
public:
enum ContentType
{
ctInt = 3,
ctDateTime = 7,
ctString = 8,
ctTwoByte = 11
};
Field(FILE* file) { read(file); }
const string& getString() const { return stringContent; }
uint64_t getNumeric() const { return numeric; }
bool isNumeric() const { return type == ctInt || type == ctTwoByte; }
bool isString() const { return type == ctString || type == ctDateTime; }
string getXmlString()
{
string xml = "";
for (unsigned int i = 0; i < stringContent.size(); i++)
{
char c = stringContent[i];
if (c == '<')
{
if (stringContent.substr(i, 4) == "<br>")
{
xml += "\n\n";
i += 3;
}
else
xml += "<";
}
else if (c == '>')
xml += ">";
else if (c == '&')
xml += "&";
else if (c == '"')
xml += """;
else
xml += c;
}
return xml;
}
private:
void read(FILE* file)
{
type = (ContentType)readInt(file, 2);
switch (type)
{
case ctString: readString(file); break;
case ctInt: numeric = readInt(file, 4); break;
case ctDateTime:
{
char buffer[30];
numeric = readInt(file, 8);
unixTime = unixTimeEpoch + (int)round((numeric-epoch)/factor) - 1;
strftime(buffer, 30, "%Y-%m-%d %H:%M:%S", gmtime(&unixTime));
stringContent = buffer;
break;
}
case ctTwoByte:
{
numeric = readInt(file, 2);
if (numeric == 0xFFFF)
numeric = 1;
break;
}
}
}
void readString(FILE* file)
{
int length = readInt(file, 2);
for (int i = 0; i < length; i++)
{
int ch = fgetc(file);
stringContent.push_back(ch);
}
}
static uint64_t readInt(FILE* file, int bytes)
{
uint64_t numeric = 0;
for (int i = 0; i < bytes; i++)
{
int byte = fgetc(file);
numeric += (uint64_t)byte << (8*i);
}
return numeric;
}
ContentType type;
string stringContent;
uint64_t numeric;
time_t unixTime;
};