source: titan/plugins/imdb/imdb.h @ 16521

Last change on this file since 16521 was 16521, checked in by obi, 12 years ago

fix

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