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
|
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "../../lib/curl.h"
#include "tvdbepisode.h"
using namespace std;
cTVDBEpisode::cTVDBEpisode(void) {
id = 0;
seriesID = 0;
number = 0;
season = 0;
combinedEpisode = 0;
combinedSeason = 0;
name = "";
firstAired = "";
guestStars = "";
overview = "";
rating = 0.0;
imageUrl = "";
width = 400;
height = 225;
imgFlag = 0;
seasonId = 0;
lastUpdated = 0;
}
cTVDBEpisode::cTVDBEpisode(int ID, string language, string apiKey, cTVDBMirrors *mirrors) {
this->language = language;
this->apiKey = apiKey;
this->mirrors = mirrors;
id = ID;
seriesID = 0;
number = 0;
season = 0;
combinedEpisode = 0;
combinedSeason = 0;
name = "";
firstAired = "";
guestStars = "";
overview = "";
rating = 0.0;
imageUrl = "";
width = 400;
height = 225;
imgFlag = 0;
seasonId = 0;
lastUpdated = 0;
}
void cTVDBEpisode::ReadEpisode(void) {
stringstream url;
url << mirrors->GetMirrorXML() << "/api/" << apiKey << "/episodes/" << id << "/" << language << ".xml";
string episodeXML;
if (curl.GetUrl(url.str().c_str(), &episodeXML)) {
ParseXML(episodeXML);
}
}
void cTVDBEpisode::ParseXML(string xml) {
xmlDoc *doc = xmlReadMemory(xml.c_str(), xml.size(), "noname.xml", NULL, 0);
if (doc == NULL)
return;
//Root Element has to be <Data>
xmlNode *node = NULL;
node = xmlDocGetRootElement(doc);
if (!(node && !xmlStrcmp(node->name, (const xmlChar *)"Data"))) {
xmlFreeDoc(doc);
return;
}
//Looping through episodes
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 *)"Episode")) {
ReadEpisodeFromXML(doc, cur_node->children, mirrors);
}
}
xmlFreeDoc(doc);
}
void cTVDBEpisode::ReadEpisodeFromXML(xmlDoc *myDoc, xmlNode *node, cTVDBMirrors *mirrors) {
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(myDoc, cur_node->xmlChildrenNode, 1);
if (!node_content)
continue;
if (!xmlStrcmp(cur_node->name, (const xmlChar *)"id")) {
id = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"EpisodeNumber")) {
number = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"seriesid")) {
seriesID = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"SeasonNumber")) {
season = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Combined_episodenumber")) {
combinedEpisode = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Combined_season")) {
combinedSeason = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"EpisodeName")) {
name = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"FirstAired")) {
firstAired = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"GuestStars")) {
guestStars = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Overview")) {
overview = (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"Rating")) {
rating = atof((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"filename")) {
imageUrl = mirrors->GetMirrorBanner() + (const char *)node_content;
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"thumb_width")) {
width = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"thumb_height")) {
height = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"EpImgFlag")) {
imgFlag = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"seasonid")) {
seasonId = atoi((const char *)node_content);
} else if (!xmlStrcmp(cur_node->name, (const xmlChar *)"lastupdated")) {
lastUpdated = atoi((const char *)node_content);
}
xmlFree(node_content);
}
}
}
void cTVDBEpisode::Dump() {
cout << "----------------------------------------" << endl;
cout << "Season " << season << ", Episode " << number << ", Name: " << name << ", ID: " << id << ", SeasonID " << seasonId << endl;
cout << "combinedSeason: " << combinedSeason << ", combinedEpisode: " << combinedEpisode << endl;
cout << "First Aired: " << firstAired << endl;
cout << "Guest Stars: " << guestStars << endl;
cout << "Overview: " << overview << endl;
cout << "Rating: " << rating << endl;
cout << "imageUrl: " << imageUrl << ", Size: " << width << " x " << height << ", Flag: " << imgFlag << endl;
cout << "Last Update: " << lastUpdated << endl;
}
|