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
|
#include "tvdbmedia.h"
using namespace std;
cTVDBSeriesMedia::cTVDBSeriesMedia(string language, cTVDBMirrors *mirrors) {
this->language = language;
fallbackLanguage = "en";
this->mirrors = mirrors;
}
cTVDBSeriesMedia::~cTVDBSeriesMedia() {
}
void cTVDBSeriesMedia::ParseXML(string xml, vector<cTVDBBanner*> *banners, vector<cTVDBFanart*> *fanarts, vector<cTVDBPoster*> *posters, vector<cTVDBSeasonPoster*> *seasonPosters) {
xmlDoc *doc = xmlReadMemory(xml.c_str(), xml.size(), "noname.xml", NULL, 0);
this->banners = banners;
this->fanarts = fanarts;
this->posters = posters;
this->seasonPosters = seasonPosters;
if (doc == NULL)
return;
//Root Element has to be <Banners>
xmlNode *node = NULL;
node = xmlDocGetRootElement(doc);
if (!(node && !xmlStrcmp(node->name, (const xmlChar *)"Banners"))) {
xmlFreeDoc(doc);
return;
}
//Looping through banners
node = node->children;
xmlNode *cur_node = NULL;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if ((cur_node->type == XML_ELEMENT_NODE) && !xmlStrcmp(cur_node->name, (const xmlChar *)"Banner")) {
ReadEntry(doc, cur_node->children);
}
}
xmlFreeDoc(doc);
}
void cTVDBSeriesMedia::ReadEntry(xmlDoc *doc, xmlNode *node) {
xmlNode *cur_node = NULL;
xmlChar *node_content;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
node_content = xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerType")) {
if (!xmlStrcmp(node_content, (const xmlChar *)"poster"))
ReadPoster(doc, node);
else if (!xmlStrcmp(node_content, (const xmlChar *)"fanart"))
ReadFanart(doc, node);
else if (!xmlStrcmp(node_content, (const xmlChar *)"series"))
ReadBanner(doc, node);
else if (!xmlStrcmp(node_content, (const xmlChar *)"season"))
ReadSeasonPoster(doc, node);
}
xmlFree(node_content);
}
}
}
void cTVDBSeriesMedia::ReadFanart(xmlDoc *doc, xmlNode *node) {
xmlNode *cur_node = NULL;
xmlChar *node_content;
cTVDBFanart *fanart = new cTVDBFanart();
//default size
fanart->width = 1920;
fanart->height = 1080;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
node_content = xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerPath")) {
fanart->url = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Language")) {
fanart->language = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Rating")) {
fanart->rating = atof((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"ThumbnailPath")) {
fanart->thumbUrl = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerType2")) {
string fanartSize = (const char *)node_content;
size_t posX = fanartSize.find("x");
fanart->width = atoi(fanartSize.substr(0, posX).c_str());
fanart->height = atoi(fanartSize.substr(posX+1).c_str());
}
xmlFree(node_content);
}
}
if ( (fanart->url.size() == 0) ||
((fanart->language.compare(language)) && (fanart->language.compare(fallbackLanguage)))) {
delete fanart;
return;
}
fanarts->push_back(fanart);
}
void cTVDBSeriesMedia::ReadPoster(xmlDoc *doc, xmlNode *node) {
xmlNode *cur_node = NULL;
xmlChar *node_content;
cTVDBPoster *poster = new cTVDBPoster();
//default size
poster->width = 400;
poster->height = 578;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
node_content = xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerPath")) {
poster->url = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Language")) {
poster->language = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Rating")) {
poster->rating = atof((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerType2")) {
string posterSize = (const char *)node_content;
size_t posX = posterSize.find("x");
poster->width = atoi(posterSize.substr(0, posX).c_str());
poster->height = atoi(posterSize.substr(posX+1).c_str());
}
xmlFree(node_content);
}
}
if ( (poster->url.size() == 0) ||
((poster->language.compare(language)) && (poster->language.compare(fallbackLanguage)))) {
delete poster;
return;
}
posters->push_back(poster);
}
void cTVDBSeriesMedia::ReadSeasonPoster(xmlDoc *doc, xmlNode *node) {
xmlNode *cur_node = NULL;
xmlChar *node_content;
cTVDBSeasonPoster *poster = new cTVDBSeasonPoster();
poster->width = 400;
poster->height = 578;
bool add = true;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
node_content = xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerPath")) {
poster->url = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Language")) {
poster->language = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Rating")) {
poster->rating = atof((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Season")) {
poster->season = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerType2")) {
string bt2 = (const char *)node_content;
if (!bt2.compare("seasonwide"))
add = false;
}
xmlFree(node_content);
}
}
if ( (poster->url.size() == 0) ||
(poster->season == 0) ||
(!add) ||
((poster->language.compare(language)) && (poster->language.compare(fallbackLanguage)))) {
delete poster;
return;
}
seasonPosters->push_back(poster);
}
void cTVDBSeriesMedia::ReadBanner(xmlDoc *doc, xmlNode *node) {
xmlNode *cur_node = NULL;
xmlChar *node_content;
cTVDBBanner *banner = new cTVDBBanner();
banner->width = 758;
banner->height = 140;
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
node_content = xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"BannerPath")) {
banner->url = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Language")) {
banner->language = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Rating")) {
banner->rating = atof((const char *)node_content);
}
xmlFree(node_content);
}
}
if ( (banner->url.size() == 0) ||
((banner->language.compare(language)) && (banner->language.compare(fallbackLanguage)))) {
delete banner;
return;
}
banners->push_back(banner);
}
|