1 | #ifndef IMDB_H |
---|
2 | #define IMDB_H |
---|
3 | |
---|
4 | #define TMPIMDBPIC1 "/tmp/tmpimdb1.jpg" |
---|
5 | #define TMPIMDBPIC2 "/tmp/tmpimdb2.jpg" |
---|
6 | |
---|
7 | extern struct imdb* imdb; |
---|
8 | |
---|
9 | void freeimdb(struct imdb* node) |
---|
10 | { |
---|
11 | if(node == NULL) return; |
---|
12 | |
---|
13 | free(node->title); node->title = NULL; |
---|
14 | free(node->year); node->year = NULL; |
---|
15 | free(node->rated); node->rated = NULL; |
---|
16 | free(node->released); node->released = NULL; |
---|
17 | free(node->genre); node->genre = NULL; |
---|
18 | free(node->director); node->director = NULL; |
---|
19 | free(node->writer); node->writer = NULL; |
---|
20 | free(node->actors); node->actors = NULL; |
---|
21 | free(node->plot); node->plot = NULL; |
---|
22 | free(node->poster); node->poster = NULL; |
---|
23 | free(node->runtime); node->runtime = NULL; |
---|
24 | free(node->rating); node->rating = NULL; |
---|
25 | free(node->votes); node->votes = NULL; |
---|
26 | free(node->id); node->id = NULL; |
---|
27 | |
---|
28 | unlink(TMPIMDBPIC1); |
---|
29 | unlink(TMPIMDBPIC2); |
---|
30 | |
---|
31 | free(node); node = NULL; |
---|
32 | } |
---|
33 | |
---|
34 | // flag 0 = title search |
---|
35 | // flag 1 = iimdbid search |
---|
36 | // flag 2 = iimdbid search and save |
---|
37 | |
---|
38 | struct imdb* getimdb(char* title, int flag, int flag1, int flag2) |
---|
39 | { |
---|
40 | struct imdb* imdb = NULL; |
---|
41 | char* tmpstr = NULL; |
---|
42 | char* tmpsearch = NULL; |
---|
43 | char* savefile = NULL; |
---|
44 | char* pageposter = NULL; |
---|
45 | |
---|
46 | start: |
---|
47 | tmpsearch = ostrcat("find?s=tt;q=", NULL, 0, 0); |
---|
48 | if(flag == 0) |
---|
49 | tmpsearch = ostrcat(tmpsearch, title, 1, 0); |
---|
50 | else |
---|
51 | tmpsearch = ostrcat(tmpsearch, "/title/tt", 1, 0); |
---|
52 | tmpsearch = stringreplacechar(tmpsearch, ' ', '+'); |
---|
53 | |
---|
54 | tmpstr = gethttp("www.imdb.de", tmpsearch, 80, NULL, NULL, NULL, 0); |
---|
55 | |
---|
56 | debug(133, "tmpsearch: %s", tmpsearch); |
---|
57 | // debug(133, "tmpstr: %s", tmpstr); |
---|
58 | |
---|
59 | free(tmpsearch); tmpsearch = NULL; |
---|
60 | |
---|
61 | if(tmpstr != NULL) |
---|
62 | { |
---|
63 | imdb = (struct imdb*)calloc(1, sizeof(struct imdb)); |
---|
64 | if(imdb == NULL) |
---|
65 | { |
---|
66 | err("no mem"); |
---|
67 | free(tmpstr); tmpstr = NULL; |
---|
68 | return NULL; |
---|
69 | } |
---|
70 | |
---|
71 | imdb->id = string_resub("<a href=\"/title/tt","/",tmpstr); |
---|
72 | |
---|
73 | // todo - use Meistgesuchte Titel (default) |
---|
74 | // Meistgesuchte Titel |
---|
75 | // Titel (näherungsweise Übereinstimmung) |
---|
76 | // Titel (genaue Übereinstimmung) |
---|
77 | |
---|
78 | if(flag1 == 0 && ostrstr(tmpstr, "<title>IMDb Titelsuche</title>") != NULL && ostrstr(tmpstr, "<p><b>Meistgesuchte Titel</b>") == NULL) |
---|
79 | { |
---|
80 | tmpstr = string_resub("<p><b>Titel","</td></tr></table> </p>",tmpstr); |
---|
81 | |
---|
82 | while(ostrstr(tmpstr, "</td><td valign=\"top\"><a href=\"/title/") != NULL) |
---|
83 | { |
---|
84 | tmpstr = string_replace("</td><td valign=\"top\"><a href=\"/title/", "\n\n", tmpstr, 0); |
---|
85 | } |
---|
86 | |
---|
87 | struct menulist* mlist = NULL, *mbox = NULL; |
---|
88 | char* tmpstr1 = NULL; |
---|
89 | |
---|
90 | int count = 0; |
---|
91 | struct splitstr* ret = NULL; |
---|
92 | ret = strsplit(tmpstr, "\n", &count); |
---|
93 | |
---|
94 | int max = count; |
---|
95 | int i = 0; |
---|
96 | for( i = 0; i < max; i++) |
---|
97 | { |
---|
98 | tmpstr1 = string_resub("link=/title", "</a>", (&ret[i])->part); |
---|
99 | struct regex* x = regexstruct("/tt([0-9]{7})", tmpstr1); |
---|
100 | struct regex* y = regexstruct(";\">(.*)", tmpstr1); |
---|
101 | if(x != NULL && y != NULL) |
---|
102 | { |
---|
103 | x->match2 = string_decode(x->match2,1); |
---|
104 | y->match2 = string_decode(y->match2,1); |
---|
105 | addmenulist(&mlist, y->match2, x->match2, NULL, 0, 0); |
---|
106 | debug(133, "x->match2(%d): %s\n", i, x->match2); |
---|
107 | debug(133, "y->match2(%d): %s\n", i, y->match2); |
---|
108 | } |
---|
109 | freeregexstruct(x); x= NULL; |
---|
110 | freeregexstruct(y); y= NULL; |
---|
111 | |
---|
112 | free(tmpstr1),tmpstr1 = NULL; |
---|
113 | } |
---|
114 | free(ret); ret = NULL; |
---|
115 | |
---|
116 | mbox = menulistbox(mlist, NULL, NULL, NULL, NULL, 1, 0); |
---|
117 | if(mbox != NULL) |
---|
118 | { |
---|
119 | free(title), title = NULL; |
---|
120 | free(tmpstr), tmpstr = NULL; |
---|
121 | |
---|
122 | debug(133, "mbox->name %s", mbox->name); |
---|
123 | debug(133, "mbox->text %s", mbox->text); |
---|
124 | |
---|
125 | title = ostrcat(mbox->text, NULL, 0, 0); |
---|
126 | flag = 1; |
---|
127 | goto start; |
---|
128 | } |
---|
129 | } |
---|
130 | free(tmpstr), tmpstr = NULL; |
---|
131 | } |
---|
132 | |
---|
133 | if(imdb != NULL) |
---|
134 | { |
---|
135 | tmpsearch = ostrcat("/title/tt", NULL, 0, 0); |
---|
136 | tmpsearch = ostrcat(tmpsearch, imdb->id, 1, 0); |
---|
137 | |
---|
138 | tmpstr = gethttp("www.imdb.de", tmpsearch, 80, NULL, NULL, NULL, 0); |
---|
139 | |
---|
140 | debug(133, "tmpsearch: %s", tmpsearch); |
---|
141 | // debug(133, "tmpstr: %s", tmpstr); |
---|
142 | |
---|
143 | free(tmpsearch); tmpsearch = NULL; |
---|
144 | } |
---|
145 | |
---|
146 | if(tmpstr != NULL) |
---|
147 | { |
---|
148 | if(ostrstr(tmpstr, "<title>") != NULL) |
---|
149 | { |
---|
150 | imdb->title = string_resub("<title>","</title>",tmpstr); |
---|
151 | imdb->title = string_decode(imdb->title,1); |
---|
152 | string_strip_whitechars(imdb->title); |
---|
153 | strstrip(imdb->title); |
---|
154 | } |
---|
155 | |
---|
156 | if(ostrstr(tmpstr, "<h5>Genre:</h5>") != NULL) |
---|
157 | { |
---|
158 | imdb->genre = string_resub("<h5>Genre:</h5>","</div>",tmpstr); |
---|
159 | imdb->genre = string_decode(imdb->genre,1); |
---|
160 | string_striptags(imdb->genre); |
---|
161 | string_strip_whitechars(imdb->genre); |
---|
162 | strstrip(imdb->genre); |
---|
163 | } |
---|
164 | |
---|
165 | if(ostrstr(tmpstr, "<h5>Drehbuchautor") != NULL) |
---|
166 | { |
---|
167 | imdb->writer = string_resub("<h5>Drehbuchautor","</div>",tmpstr); |
---|
168 | imdb->writer = string_resub("<div class=\"info-content\">","</div>",imdb->writer); |
---|
169 | imdb->writer = string_resub(";\">","</a>",imdb->writer); |
---|
170 | imdb->writer = string_decode(imdb->writer,1); |
---|
171 | string_striptags(imdb->writer); |
---|
172 | string_strip_whitechars(imdb->writer); |
---|
173 | strstrip(imdb->writer); |
---|
174 | } |
---|
175 | |
---|
176 | if(ostrstr(tmpstr, "Regisseur:") != NULL) |
---|
177 | { |
---|
178 | imdb->director = string_resub("Regisseur:","</div>",tmpstr); |
---|
179 | imdb->director = string_resub(";\">","</a><br/>",imdb->director); |
---|
180 | imdb->director = string_decode(imdb->director,1); |
---|
181 | string_striptags(imdb->director); |
---|
182 | string_strip_whitechars(imdb->director); |
---|
183 | strstrip(imdb->director); |
---|
184 | } |
---|
185 | |
---|
186 | if(ostrstr(tmpstr, "<h5>Premierendatum:</h5>") != NULL) |
---|
187 | { |
---|
188 | imdb->released = string_resub("<h5>Premierendatum:</h5>","<a class=",tmpstr); |
---|
189 | imdb->released = string_resub("<div class=\"info-content\">","<a class=",imdb->released); |
---|
190 | imdb->released = string_decode(imdb->released,1); |
---|
191 | string_striptags(imdb->released); |
---|
192 | string_strip_whitechars(imdb->released); |
---|
193 | strstrip(imdb->released); |
---|
194 | } |
---|
195 | |
---|
196 | if(ostrstr(tmpstr, "<h3>Besetzung</h3>") != NULL) |
---|
197 | { |
---|
198 | imdb->actors = string_resub("<h3>Besetzung</h3> ","</td></tr></table>",tmpstr); |
---|
199 | imdb->actors = string_resub("<div class=\"info-content block\"><table class=\"cast\">","</a></td></tr>",imdb->actors); |
---|
200 | imdb->actors = string_replace("...", "als", imdb->actors, 0); |
---|
201 | imdb->actors = string_decode(imdb->actors,1); |
---|
202 | string_striptags(imdb->actors); |
---|
203 | string_strip_whitechars(imdb->actors); |
---|
204 | strstrip(imdb->actors); |
---|
205 | } |
---|
206 | |
---|
207 | if(ostrstr(tmpstr, "<a name=\"poster\" href=\"") != NULL) |
---|
208 | { |
---|
209 | imdb->thumb = string_resub("<a name=\"poster\" href=\"", "\" /></a>",tmpstr); |
---|
210 | imdb->thumb = string_resub("src=\"","\" /></a>",imdb->thumb); |
---|
211 | } |
---|
212 | |
---|
213 | if(ostrstr(tmpstr, "/media/rm") != NULL) |
---|
214 | { |
---|
215 | pageposter = string_resub("/media/rm","/",tmpstr); |
---|
216 | strstrip(pageposter); |
---|
217 | } |
---|
218 | free(tmpstr), tmpstr = NULL; |
---|
219 | } |
---|
220 | |
---|
221 | if(pageposter != NULL) |
---|
222 | { |
---|
223 | tmpsearch = ostrcat("/media/rm", pageposter, 0, 0); |
---|
224 | tmpsearch = ostrcat(tmpsearch, "/tt", 1, 0); |
---|
225 | tmpsearch = ostrcat(tmpsearch, imdb->id, 1, 0); |
---|
226 | tmpsearch = ostrcat(tmpsearch, "/", 1, 0); |
---|
227 | |
---|
228 | tmpstr = gethttp("www.imdb.de", tmpsearch, 80, NULL, NULL, NULL, 0); |
---|
229 | |
---|
230 | debug(133, "tmpsearch: %s", tmpsearch); |
---|
231 | // debug(133, "tmpstr: %s", tmpstr); |
---|
232 | |
---|
233 | free(tmpsearch); tmpsearch = NULL; |
---|
234 | if(tmpstr != NULL) |
---|
235 | { |
---|
236 | if(ostrstr(tmpstr, "image_src") != NULL) |
---|
237 | { |
---|
238 | imdb->poster = string_resub("<link rel=\"image_src\" href=\"","\"",tmpstr); |
---|
239 | strstrip(imdb->poster); |
---|
240 | } |
---|
241 | free(tmpstr), tmpstr = NULL; |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | if(imdb != NULL) |
---|
246 | { |
---|
247 | tmpsearch = ostrcat("/title/tt", NULL, 0, 0); |
---|
248 | tmpsearch = ostrcat(tmpsearch, imdb->id, 1, 0); |
---|
249 | tmpsearch = ostrcat(tmpsearch, "/plotsummary", 1, 0); |
---|
250 | |
---|
251 | tmpstr = gethttp("www.imdb.de", tmpsearch, 80, NULL, NULL, NULL, 0); |
---|
252 | |
---|
253 | debug(133, "tmpsearch: %s", tmpsearch); |
---|
254 | // debug(133, "tmpstr: %s", tmpstr); |
---|
255 | |
---|
256 | free(tmpsearch); tmpsearch = NULL; |
---|
257 | } |
---|
258 | |
---|
259 | if(tmpstr != NULL) |
---|
260 | { |
---|
261 | if(ostrstr(tmpstr, "swiki.2.1") != NULL) |
---|
262 | { |
---|
263 | imdb->plot = string_resub("<div id=\"swiki.2.1\">","</div>",tmpstr); |
---|
264 | imdb->plot = string_decode(imdb->plot,1); |
---|
265 | string_striptags(imdb->plot); |
---|
266 | string_strip_whitechars(imdb->plot); |
---|
267 | strstrip(imdb->plot); |
---|
268 | } |
---|
269 | free(tmpstr), tmpstr = NULL; |
---|
270 | } |
---|
271 | |
---|
272 | if(flag2 == 0 && imdb->id != NULL) |
---|
273 | { |
---|
274 | if(imdb->poster != NULL) |
---|
275 | { |
---|
276 | char* ip = NULL, *pos = NULL, *path = NULL; |
---|
277 | ip = string_replace("http://", "", imdb->poster, 0); |
---|
278 | |
---|
279 | if(ip != NULL) |
---|
280 | pos = strchr(ip, '/'); |
---|
281 | if(pos != NULL) |
---|
282 | { |
---|
283 | pos[0] = '\0'; |
---|
284 | path = pos + 1; |
---|
285 | } |
---|
286 | |
---|
287 | if(flag1 == 1) |
---|
288 | { |
---|
289 | savefile = ostrcat(getconfig("mediadbpath", NULL), "/tt", 0, 0); |
---|
290 | savefile = ostrcat(savefile, imdb->id, 1, 0); |
---|
291 | savefile = ostrcat(savefile, "_poster.jpg", 1, 0); |
---|
292 | gethttp(ip, path, 80, savefile, NULL, NULL, 0); |
---|
293 | free(imdb->poster); |
---|
294 | imdb->poster = savefile; |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | gethttp(ip, path, 80, TMPIMDBPIC1, NULL, NULL, 0); |
---|
299 | free(imdb->poster); |
---|
300 | imdb->poster = ostrcat(TMPIMDBPIC1, NULL, 0, 0); |
---|
301 | } |
---|
302 | |
---|
303 | free(ip); ip = NULL; |
---|
304 | } |
---|
305 | if(imdb->thumb != NULL) |
---|
306 | { |
---|
307 | char* ip = NULL, *pos = NULL, *path = NULL; |
---|
308 | ip = string_replace("http://", "", imdb->thumb, 0); |
---|
309 | |
---|
310 | if(ip != NULL) |
---|
311 | pos = strchr(ip, '/'); |
---|
312 | if(pos != NULL) |
---|
313 | { |
---|
314 | pos[0] = '\0'; |
---|
315 | path = pos + 1; |
---|
316 | } |
---|
317 | |
---|
318 | if(flag1 == 1) |
---|
319 | { |
---|
320 | savefile = ostrcat(getconfig("mediadbpath", NULL), "/tt", 0, 0); |
---|
321 | savefile = ostrcat(savefile, imdb->id, 1, 0); |
---|
322 | savefile = ostrcat(savefile, "_thumb.jpg", 1, 0); |
---|
323 | gethttp(ip, path, 80, savefile, NULL, NULL, 0); |
---|
324 | free(imdb->thumb); |
---|
325 | imdb->thumb = savefile; |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | gethttp(ip, path, 80, TMPIMDBPIC2, NULL, NULL, 0); |
---|
330 | free(imdb->thumb); |
---|
331 | imdb->thumb = ostrcat(TMPIMDBPIC2, NULL, 0, 0); |
---|
332 | } |
---|
333 | |
---|
334 | free(ip); ip = NULL; |
---|
335 | } |
---|
336 | } |
---|
337 | else |
---|
338 | { |
---|
339 | if(imdb->thumb == NULL) |
---|
340 | { |
---|
341 | free(imdb->thumb); |
---|
342 | imdb->thumb = NULL; |
---|
343 | } |
---|
344 | if(imdb->poster == NULL) |
---|
345 | { |
---|
346 | free(imdb->poster); |
---|
347 | imdb->poster = NULL; |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | imdb->id = ostrcat("tt", imdb->id, 0, 1); |
---|
352 | |
---|
353 | free(tmpstr); tmpstr = NULL; |
---|
354 | |
---|
355 | debug(133, "id: %s", imdb->id); |
---|
356 | debug(133, "title: %s", imdb->title); |
---|
357 | debug(133, "genre: %s", imdb->genre); |
---|
358 | debug(133, "writer: %s", imdb->writer); |
---|
359 | debug(133, "director: %s", imdb->director); |
---|
360 | debug(133, "released: %s", imdb->released); |
---|
361 | debug(133, "actors: %s", imdb->actors); |
---|
362 | debug(133, "plot: %s", imdb->plot); |
---|
363 | debug(133, "poster: %s", imdb->poster); |
---|
364 | debug(133, "thumb: %s", imdb->thumb); |
---|
365 | |
---|
366 | return imdb; |
---|
367 | } |
---|
368 | |
---|
369 | void screenimdb(char* title) |
---|
370 | { |
---|
371 | int rcret = 0; |
---|
372 | struct skin* imdbskin = getscreen("imdb"); |
---|
373 | struct skin* skin_plot = getscreennode(imdbskin, "plot"); |
---|
374 | struct skin* skin_title = getscreennode(imdbskin, "title"); |
---|
375 | struct skin* skin_director = getscreennode(imdbskin, "director"); |
---|
376 | struct skin* skin_writers = getscreennode(imdbskin, "writers"); |
---|
377 | struct skin* skin_genre = getscreennode(imdbskin, "genre"); |
---|
378 | struct skin* skin_releasetime = getscreennode(imdbskin, "releasetime"); |
---|
379 | struct skin* skin_cover = getscreennode(imdbskin, "cover"); |
---|
380 | struct skin* skin_actors = getscreennode(imdbskin, "actors"); |
---|
381 | struct imdb* node = NULL; |
---|
382 | char* search = NULL; |
---|
383 | |
---|
384 | setfbtransparent(255); |
---|
385 | status.hangtime = 99999; |
---|
386 | |
---|
387 | if(title == NULL) title = getepgakttitle(NULL); |
---|
388 | |
---|
389 | node = getimdb(title, 0, 0, 0); |
---|
390 | start: |
---|
391 | if(node != NULL) |
---|
392 | { |
---|
393 | changetext(skin_plot, node->plot); |
---|
394 | changetext(skin_title, node->title); |
---|
395 | changetext(skin_director, node->director); |
---|
396 | changetext(skin_writers, node->writer); |
---|
397 | changetext(skin_genre, node->genre); |
---|
398 | changetext(skin_releasetime, node->released); |
---|
399 | changetext(skin_actors, node->actors); |
---|
400 | changepic(skin_cover, node->poster); |
---|
401 | } |
---|
402 | |
---|
403 | drawscreen(imdbskin, 0); |
---|
404 | |
---|
405 | while(1) |
---|
406 | { |
---|
407 | rcret = waitrc(imdbskin, 0, 0); |
---|
408 | |
---|
409 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
410 | if(rcret == getrcconfigint("rcok", NULL)) break; |
---|
411 | |
---|
412 | if(rcret == getrcconfigint("rcred", NULL)) |
---|
413 | { |
---|
414 | search = textinput("Search", NULL); |
---|
415 | if(search != NULL) |
---|
416 | { |
---|
417 | freeimdb(node); node = NULL; |
---|
418 | node = getimdb(search, 0, 0, 0); |
---|
419 | free(search); search = NULL; |
---|
420 | goto start; |
---|
421 | } |
---|
422 | drawscreen(imdbskin, 0); |
---|
423 | continue; |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | freeimdb(node); node = NULL; |
---|
428 | setosdtransparent(getskinconfigint("osdtransparent", NULL)); |
---|
429 | status.hangtime = getconfigint("hangtime", NULL); |
---|
430 | clearscreen(imdbskin); |
---|
431 | } |
---|
432 | |
---|
433 | #endif |
---|