1 | #ifndef IMDBAPI_H |
---|
2 | #define IMDBAPI_H |
---|
3 | |
---|
4 | #define TMPIMDBAPIPIC "/tmp/tmpimdbapi.jpg" |
---|
5 | |
---|
6 | void freeimdbapi(struct imdbapi** node, int flag) |
---|
7 | { |
---|
8 | if(node == NULL || *node == NULL) return; |
---|
9 | |
---|
10 | free((*node)->title); (*node)->title = NULL; |
---|
11 | free((*node)->year); (*node)->year = NULL; |
---|
12 | free((*node)->rated); (*node)->rated = NULL; |
---|
13 | free((*node)->released); (*node)->released = NULL; |
---|
14 | free((*node)->genre); (*node)->genre = NULL; |
---|
15 | free((*node)->director); (*node)->director = NULL; |
---|
16 | free((*node)->writer); (*node)->writer = NULL; |
---|
17 | free((*node)->actors); (*node)->actors = NULL; |
---|
18 | free((*node)->plot); (*node)->plot = NULL; |
---|
19 | free((*node)->poster); (*node)->poster = NULL; |
---|
20 | free((*node)->runtime); (*node)->runtime = NULL; |
---|
21 | free((*node)->rating); (*node)->rating = NULL; |
---|
22 | free((*node)->votes); (*node)->votes = NULL; |
---|
23 | free((*node)->id); (*node)->id = NULL; |
---|
24 | unlink(TMPIMDBAPIPIC); |
---|
25 | |
---|
26 | free(*node); *node = NULL; |
---|
27 | } |
---|
28 | |
---|
29 | //flag 0 = title search |
---|
30 | //flag 1 = imdbid search |
---|
31 | //flag1 0 = save in tmp |
---|
32 | //flag1: 1 = save pic in mediadb path if pic not exist |
---|
33 | //flag2: 2 = save no pic |
---|
34 | struct imdbapi* getimdbapi(struct imdbapi** first, char* input, int flag, int flag1) |
---|
35 | { |
---|
36 | debug(133, "title: %s",input); |
---|
37 | debug(133, "flag: %d",flag); |
---|
38 | debug(133, "flag1: %d",flag1); |
---|
39 | |
---|
40 | // char* tmpstr = NULL, *ret = NULL, *tmpsearch = NULL, *savefile = NULL, *savethumb = NULL, *title = NULL; |
---|
41 | char* tmpstr = NULL, *ret = NULL, *tmpsearch = NULL, *savefile = NULL, *title = NULL; |
---|
42 | |
---|
43 | if(checkinternet() == 1) |
---|
44 | { |
---|
45 | debug(133, "Error, Internet Connection not found"); |
---|
46 | return NULL; |
---|
47 | } |
---|
48 | |
---|
49 | title = ostrcat(title, input, 1, 0); |
---|
50 | |
---|
51 | // unsigned char* buf = NULL; |
---|
52 | // int channels = 0; |
---|
53 | // unsigned long width = 0, height = 0, rowbytes = 0; |
---|
54 | |
---|
55 | if(flag == 0) |
---|
56 | tmpsearch = ostrcat("?i=&t=", title, 0, 0); |
---|
57 | else |
---|
58 | tmpsearch = ostrcat("?i=", title, 0, 0); |
---|
59 | |
---|
60 | tmpsearch = stringreplacechar(tmpsearch, ' ', '+'); |
---|
61 | debug(133, "search: http://www.imdbapi.com/%s", tmpsearch); |
---|
62 | |
---|
63 | tmpstr = gethttp("www.imdbapi.com", tmpsearch, 80, NULL, NULL, 5000, NULL, 0); |
---|
64 | debug(133, "tmpsearch: %s", tmpsearch); |
---|
65 | // debug(133, "tmpstr: %s", tmpstr); |
---|
66 | |
---|
67 | free(tmpsearch); tmpsearch = NULL; |
---|
68 | |
---|
69 | if(tmpstr != NULL && ostrstr(tmpstr, "Movie not found!") == NULL) |
---|
70 | { |
---|
71 | ret = getxmlentry(tmpstr, "\"Response\":"); |
---|
72 | if(ostrcmp(ret, "False") == 0) |
---|
73 | { |
---|
74 | free(ret); ret = NULL; |
---|
75 | free(tmpstr); tmpstr = NULL; |
---|
76 | return NULL; |
---|
77 | } |
---|
78 | free(ret); ret = NULL; |
---|
79 | |
---|
80 | *first = (struct imdbapi*)calloc(1, sizeof(struct imdbapi)); |
---|
81 | if(*first == NULL) |
---|
82 | { |
---|
83 | err("no mem"); |
---|
84 | free(tmpstr); tmpstr = NULL; |
---|
85 | return NULL; |
---|
86 | } |
---|
87 | |
---|
88 | (*first)->title = getxmlentry(tmpstr, "\"Title\":"); |
---|
89 | (*first)->year = getxmlentry(tmpstr, "\"Year\":"); |
---|
90 | (*first)->rated = getxmlentry(tmpstr, "\"Rated\":"); |
---|
91 | (*first)->released = getxmlentry(tmpstr, "\"Released\":"); |
---|
92 | (*first)->genre = getxmlentry(tmpstr, "\"Genre\":"); |
---|
93 | (*first)->director = getxmlentry(tmpstr, "\"Director\":"); |
---|
94 | (*first)->writer = getxmlentry(tmpstr, "\"Writer\":"); |
---|
95 | (*first)->actors = getxmlentry(tmpstr, "\"Actors\":"); |
---|
96 | (*first)->plot = getxmlentry(tmpstr, "\"Plot\":"); |
---|
97 | (*first)->poster = getxmlentry(tmpstr, "\"Poster\":"); |
---|
98 | (*first)->runtime = getxmlentry(tmpstr, "\"Runtime\":"); |
---|
99 | (*first)->rating = getxmlentry(tmpstr, "\"imdbRating\":"); |
---|
100 | (*first)->votes = getxmlentry(tmpstr, "\"imdbVotes\":"); |
---|
101 | (*first)->id = getxmlentry(tmpstr, "\"imdbID\":"); |
---|
102 | |
---|
103 | if((*first)->poster != NULL) |
---|
104 | { |
---|
105 | char* ip = NULL, *pos = NULL, *path = NULL; |
---|
106 | ip = string_replace("http://", "", (*first)->poster, 0); |
---|
107 | |
---|
108 | if(ip != NULL) |
---|
109 | pos = strchr(ip, '/'); |
---|
110 | if(pos != NULL) |
---|
111 | { |
---|
112 | pos[0] = '\0'; |
---|
113 | path = pos + 1; |
---|
114 | } |
---|
115 | |
---|
116 | if(flag1 == 1 && (*first)->id != NULL) |
---|
117 | { |
---|
118 | savefile = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); |
---|
119 | savefile = ostrcat(savefile, (*first)->id, 1, 0); |
---|
120 | savefile = ostrcat(savefile, "_poster.jpg", 1, 0); |
---|
121 | |
---|
122 | if(!file_exist(savefile)) |
---|
123 | gethttp(ip, path, 80, savefile, NULL, 5000, NULL, 0); |
---|
124 | free((*first)->poster); |
---|
125 | (*first)->poster = savefile; |
---|
126 | |
---|
127 | /* |
---|
128 | //create thumb |
---|
129 | savethumb = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); |
---|
130 | savethumb = ostrcat(savethumb, (*first)->id, 1, 0); |
---|
131 | savethumb = ostrcat(savethumb, "_thumb.jpg", 1, 0); |
---|
132 | if(file_exist(savefile) && !file_exist(savethumb)) |
---|
133 | { |
---|
134 | buf = loadjpg(savefile, &width, &height, &rowbytes, &channels, 16); |
---|
135 | buf = savejpg(savethumb, width, height, channels, 91, 140, 70, buf); |
---|
136 | } |
---|
137 | free(savethumb); savethumb = NULL; |
---|
138 | free(buf); buf = NULL; |
---|
139 | |
---|
140 | //create cover |
---|
141 | savethumb = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); |
---|
142 | savethumb = ostrcat(savethumb, (*first)->id, 1, 0); |
---|
143 | savethumb = ostrcat(savethumb, "_cover.jpg", 1, 0); |
---|
144 | if(file_exist(savefile) && !file_exist(savethumb)) |
---|
145 | { |
---|
146 | buf = loadjpg(savefile, &width, &height, &rowbytes, &channels, 16); |
---|
147 | buf = savejpg(savethumb, width, height, channels, 185, 264, 70, buf); |
---|
148 | } |
---|
149 | free(savethumb); savethumb = NULL; |
---|
150 | free(buf); buf = NULL; |
---|
151 | */ |
---|
152 | } |
---|
153 | else if(flag == 0) |
---|
154 | { |
---|
155 | gethttp(ip, path, 80, TMPIMDBAPIPIC, NULL, 5000, NULL, 0); |
---|
156 | free((*first)->poster); |
---|
157 | (*first)->poster = ostrcat(TMPIMDBAPIPIC, NULL, 0, 0); |
---|
158 | } |
---|
159 | |
---|
160 | free(ip); ip = NULL; |
---|
161 | } |
---|
162 | else |
---|
163 | { |
---|
164 | free((*first)->poster); |
---|
165 | (*first)->poster = NULL; |
---|
166 | } |
---|
167 | |
---|
168 | free(tmpstr); tmpstr = NULL; |
---|
169 | |
---|
170 | debug(133, "----------------------imdbapi start----------------------"); |
---|
171 | debug(133, "id: %s", (*first)->id); |
---|
172 | debug(133, "title: %s", (*first)->title); |
---|
173 | debug(133, "genre: %s", (*first)->genre); |
---|
174 | debug(133, "writer: %s", (*first)->writer); |
---|
175 | debug(133, "director: %s", (*first)->director); |
---|
176 | debug(133, "released: %s", (*first)->released); |
---|
177 | debug(133, "actors: %s", (*first)->actors); |
---|
178 | debug(133, "plot: %s", (*first)->plot); |
---|
179 | debug(133, "poster: %s", (*first)->poster); |
---|
180 | debug(133, "rating: %s", (*first)->rating); |
---|
181 | debug(133, "votes: %s", (*first)->votes); |
---|
182 | debug(133, "runtime: %s", (*first)->runtime); |
---|
183 | debug(133, "year: %s", (*first)->year); |
---|
184 | debug(133, "rated: %s", (*first)->rated); |
---|
185 | debug(133, "----------------------imdbapi end----------------------"); |
---|
186 | } |
---|
187 | |
---|
188 | return *first; |
---|
189 | } |
---|
190 | |
---|
191 | void screenimdbapi(char* title, char* dummy1, char* dummy2, char* path, char* file) |
---|
192 | { |
---|
193 | debug(133, "title: %s",title); |
---|
194 | debug(133, "path: %s",path); |
---|
195 | debug(133, "file: %s",file); |
---|
196 | char* searchstr = NULL, *tmpstr = NULL; |
---|
197 | |
---|
198 | if(checkinternet() == 1) |
---|
199 | { |
---|
200 | textbox(_("Message"), _("Error, Internet Connection not found"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1100, 500, 10, 0); |
---|
201 | return; |
---|
202 | } |
---|
203 | |
---|
204 | int rcret = 0; |
---|
205 | struct skin* imdbapiskin = getscreen("imdbapi"); |
---|
206 | struct skin* skin_plot = getscreennode(imdbapiskin, "plot"); |
---|
207 | struct skin* skin_title = getscreennode(imdbapiskin, "title"); |
---|
208 | struct skin* skin_director = getscreennode(imdbapiskin, "director"); |
---|
209 | struct skin* skin_writers = getscreennode(imdbapiskin, "writers"); |
---|
210 | struct skin* skin_genre = getscreennode(imdbapiskin, "genre"); |
---|
211 | struct skin* skin_releasetime = getscreennode(imdbapiskin, "releasetime"); |
---|
212 | struct skin* skin_cover = getscreennode(imdbapiskin, "cover"); |
---|
213 | struct skin* skin_actors = getscreennode(imdbapiskin, "actors"); |
---|
214 | struct skin* skin_b2 = getscreennode(imdbapiskin, "b2"); |
---|
215 | struct skin* load = getscreen("loading"); |
---|
216 | struct skin* blackscreen = getscreen("blackscreen"); |
---|
217 | |
---|
218 | struct imdbapi* node = NULL; |
---|
219 | char* search = NULL; |
---|
220 | |
---|
221 | if(path == NULL || file == NULL || !file_exist(getconfig("mediadbpath", NULL))) |
---|
222 | skin_b2->hidden = YES; |
---|
223 | else |
---|
224 | skin_b2->hidden = NO; |
---|
225 | |
---|
226 | // setfbtransparent(255); |
---|
227 | status.hangtime = 99999; |
---|
228 | |
---|
229 | if(title == NULL) |
---|
230 | searchstr = getepgakttitle(NULL); |
---|
231 | else |
---|
232 | { |
---|
233 | int isrec = 0, iscam = 0; |
---|
234 | tmpstr = createshortname(file, &isrec, &iscam, 1); |
---|
235 | if(tmpstr != NULL) |
---|
236 | searchstr = ostrcat(searchstr, tmpstr, 1, 0); |
---|
237 | else |
---|
238 | searchstr = ostrcat(searchstr, title, 1, 0); |
---|
239 | } |
---|
240 | |
---|
241 | debug(133, "searchstr: %s",searchstr); |
---|
242 | |
---|
243 | drawscreen(blackscreen, 0, 0); |
---|
244 | drawscreen(load, 0, 0); |
---|
245 | |
---|
246 | node = getimdbapi(&node, searchstr, 0, 0); |
---|
247 | clearscreen(load); |
---|
248 | clearscreen(blackscreen); |
---|
249 | |
---|
250 | start: |
---|
251 | if(node != NULL) |
---|
252 | { |
---|
253 | changetext(skin_plot, node->plot); |
---|
254 | changetext(skin_title, node->title); |
---|
255 | changetext(skin_director, node->director); |
---|
256 | changetext(skin_writers, node->writer); |
---|
257 | changetext(skin_genre, node->genre); |
---|
258 | changetext(skin_releasetime, node->released); |
---|
259 | changetext(skin_actors, node->actors); |
---|
260 | changepic(skin_cover, node->poster); |
---|
261 | skin_cover->hidden = NO; |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | changetext(skin_plot, "--plot--"); |
---|
266 | changetext(skin_title, "--title--"); |
---|
267 | changetext(skin_director, "--director--"); |
---|
268 | changetext(skin_writers, "--writers--"); |
---|
269 | changetext(skin_genre, "--genre--"); |
---|
270 | changetext(skin_releasetime, "--releasetime--"); |
---|
271 | changetext(skin_actors, "--actors--"); |
---|
272 | skin_cover->hidden = YES; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | drawscreen(imdbapiskin, 0, 0); |
---|
277 | |
---|
278 | while(1) |
---|
279 | { |
---|
280 | rcret = waitrc(imdbapiskin, 0, 0); |
---|
281 | |
---|
282 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
283 | if(rcret == getrcconfigint("rcok", NULL)) break; |
---|
284 | |
---|
285 | if(rcret == getrcconfigint("rcred", NULL)) |
---|
286 | { |
---|
287 | search = textinput("Search", searchstr); |
---|
288 | if(search != NULL) |
---|
289 | { |
---|
290 | freeimdbapi(&node, 0); node = NULL; |
---|
291 | drawscreen(blackscreen, 0, 0); |
---|
292 | drawscreen(load, 0, 0); |
---|
293 | node = getimdbapi(&node, search, 0, 0); |
---|
294 | clearscreen(load); |
---|
295 | clearscreen(blackscreen); |
---|
296 | free(search); search = NULL; |
---|
297 | goto start; |
---|
298 | } |
---|
299 | drawscreen(imdbapiskin, 0, 0); |
---|
300 | continue; |
---|
301 | } |
---|
302 | |
---|
303 | if(path != NULL && file != NULL && node != NULL && node->id != NULL && rcret == getrcconfigint("rcgreen", NULL)) |
---|
304 | { |
---|
305 | drawscreen(blackscreen, 0, 0); |
---|
306 | drawscreen(load, 0, 0); |
---|
307 | debug(133, "path: %s",path); |
---|
308 | debug(133, "file: %s",file); |
---|
309 | debug(133, "type: 2"); |
---|
310 | debug(133, "imdbid: %s",node->id); |
---|
311 | addconfigtmp("mediadbscantimeout", "0"); |
---|
312 | mediadbfindfilecb(path, file, 0, node->id, 3); |
---|
313 | delconfigtmp("mediadbscantimeout"); |
---|
314 | clearscreen(load); |
---|
315 | clearscreen(blackscreen); |
---|
316 | break; |
---|
317 | } |
---|
318 | } |
---|
319 | |
---|
320 | free(searchstr), searchstr = NULL; |
---|
321 | freeimdbapi(&node, 0); node = NULL; |
---|
322 | // setosdtransparent(getskinconfigint("osdtransparent", NULL)); |
---|
323 | status.hangtime = getconfigint("hangtime", NULL); |
---|
324 | clearscreen(imdbapiskin); |
---|
325 | } |
---|
326 | |
---|
327 | #endif |
---|