summaryrefslogtreecommitdiff
path: root/parse.h
blob: 96b8f7b6617f6143d4f9cf65aedc3e12e8ae0cf9 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * parse.h: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef _PARSE_H
#define _PARSE_H

#include <vdr/tools.h>
#include <vdr/epg.h>
#include <libxml/parser.h>
#include <time.h>

#include "maps.h"

class cEPGExecutor;
class cEPGSource;

class cXMLTVEvent
{
private:
    char *title;
    char *shorttext;
    char *description;
    char *country;
    char *system;
    char *review;
    char *rating;
    char *origtitle;
    int year;
    time_t starttime;
    int duration;
    time_t vps;
    int season;
    int episode;
    tEventID eventid;
    cStringList credits;
    cStringList categories;
#if VDRVERSNUM >= 10711
    uchar parentalRating;
    uchar contents[MaxEventContents];
#endif
public:
    cXMLTVEvent();
    ~cXMLTVEvent();
    bool RemoveLastCharFromDescription();
    bool Add2Description(const char *Name, const char *Value);
    bool Add2Description(const char *Name, int Value);
    bool Add2Description(const char *Value);
    void Clear();
    void SetTitle(const char *Title);
    void SetOrigTitle(const char *OrigTitle);
    void SetShortText(const char *ShortText);
    void SetDescription(const char *Description);
    void AddCredits(const char *CreditType, const char *Credit, const char *Addendum=NULL);
    void AddCategory(const char *Category);
    void SetCountry(const char *Country);
    void SetReview(const char *Review);
    void SetRating(const char *System, const char *Rating);
    void SetSeason(int Season)
    {
        season=Season;
    }
    void SetEpisode(int Episode)
    {
        episode=Episode;
    }
    void SetYear(int Year)
    {
        year=Year;
    }
    void SetStartTime(time_t StartTime)
    {
        starttime=StartTime;
    }
    void SetDuration(int Duration)
    {
        duration=Duration;
    }
    void SetVps(time_t Vps)
    {
        vps=Vps;
    }
    void SetEventID(tEventID EventID)
    {
        eventid=EventID;
    }
    time_t Vps(void) const
    {
        return vps;
    }
    int Duration() const
    {
        return duration;
    }
    time_t StartTime() const
    {
        return starttime;
    }
    const char *Title(void) const
    {
        return title;
    }
    const char *ShortText(void) const
    {
        return shorttext;
    }
    const char *Description(void) const
    {
        return description;
    }
    const char *Country(void) const
    {
        return country;
    }
    int Year() const
    {
        return year;
    }
    const char *Review(void) const
    {
        return review;
    }
    const char *Rating(void) const
    {
        return rating;
    }
    const char *RatingSystem(void) const
    {
        return system;
    }
    const char *OrigTitle(void) const
    {
        return origtitle;
    }
    tEventID EventID(void) const
    {
        return eventid;
    }
    cStringList *Credits(void)
    {
        return &credits;
    }
    cStringList *Categories(void)
    {
        return &categories;
    }
    int Season(void)
    {
        return season;
    }
    int Episode(void)
    {
        return episode;
    }
};

class cParse
{
    struct split
    {
        char *pointers[256];
        int count;
    };

    enum
    {
        PARSE_NOERROR=0,
        PARSE_NOSCHEDULE,
        PARSE_NOCHANNEL,
        PARSE_XMLTVERR,
        PARSE_NOMAPPING,
        PARSE_NOCHANNELID,
        PARSE_EMPTYSCHEDULE
    };

private:
    cEPGSource *source;
    cEPGMappings *maps;
    cTEXTMappings *texts;
    cXMLTVEvent xevent;
    cCharSetConv *conv;
    char *epdir;
    char cbuf[80];
    char *RemoveNonASCII(const char *src);
    struct split split(char *in, char delim);
    u_long DoSum(u_long sum, const char *buf, int nBytes);
    cEvent *SearchEvent(cSchedule* schedule, cXMLTVEvent *xevent);
    time_t ConvertXMLTVTime2UnixTime(char *xmltvtime);
    bool FetchEvent(xmlNodePtr node);
    void FetchSeasonEpisode(cEvent *event);
    cEPGMapping *EPGMapping(const char *ChannelName);
    cTEXTMapping *TEXTMapping(const char *Name);
    bool PutEvent(cSchedule* schedule,cEvent *event,cXMLTVEvent *xevent, cEPGMapping *map);
    cEvent *GetEventBefore(cSchedule *schedule, time_t start);
public:
    cParse(cEPGSource *Source, cEPGMappings *Maps, cTEXTMappings *Texts);
    ~cParse();
    int Process(cEPGExecutor &myExecutor, char *buffer, int bufsize);
    static void InitLibXML();
    static void CleanupLibXML();
};

#endif