source: titan/plugins/imdbapi/imdbapi.h @ 16415

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

[titan] update mediadb stuff

File size: 6.1 KB
Line 
1#ifndef IMDBAPI_H
2#define IMDBAPI_H
3
4#define TMPIMDBAPIPIC "/tmp/tmpimdbapi.jpg"
5extern struct imdbapi* imdbapi;
6
7void freeimdbapi(struct imdbapi* node)
8{
9        if(node == NULL) return;
10
11        free(node->title); node->title = NULL;
12        free(node->year); node->year = NULL;
13        free(node->rated); node->rated = NULL;
14        free(node->released); node->released = NULL;
15        free(node->genre); node->genre = NULL;
16        free(node->director); node->director = NULL;
17        free(node->writer); node->writer = NULL;
18        free(node->actors); node->actors = NULL;
19        free(node->plot); node->plot = NULL;
20        free(node->poster); node->poster = NULL;
21        free(node->runtime); node->runtime = NULL;
22        free(node->rating); node->rating = NULL;
23        free(node->votes); node->votes = NULL;
24        free(node->id); node->id = NULL;
25        unlink(TMPIMDBAPIPIC);
26
27        free(node); node = NULL;
28}
29
30//flag 0 = title search
31//flag 1 = imdbid search
32//flag1 0 = save in tmp
33//flag1 1 = save in mediadbpath
34//flag2 0 = get pic
35//flag2 1 = don't get pic
36struct imdbapi* getimdbapi(char* title, int flag, int flag1, int flag2)
37{
38        struct imdbapi* imdbapi = NULL;
39        char* tmpstr = NULL;
40        char* tmpsearch = NULL;
41        char* savefile = NULL, *savethumb = NULL;
42        unsigned char* buf = NULL;
43        int channels = 0;
44        unsigned long width = 0, height = 0, rowbytes = 0;
45
46        if(flag == 0)
47                tmpsearch = ostrcat("?i=&t=", title, 0, 0);
48        else
49                tmpsearch = ostrcat("?i=", title, 0, 0);
50
51        tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
52
53        tmpstr = gethttp("www.imdbapi.com", tmpsearch, 80, NULL, NULL, NULL, 0);
54        free(tmpsearch); tmpsearch = NULL;
55
56        if(tmpstr != NULL)
57        {
58                imdbapi = (struct imdbapi*)malloc(sizeof(struct imdbapi));
59                if(imdbapi == NULL)
60                {
61                        err("no mem");
62                        free(tmpstr); tmpstr = NULL;
63                        return NULL;
64                }
65                memset(imdbapi, 0, sizeof(struct imdbapi));
66
67                imdbapi->title = getxmlentry(tmpstr, "\"Title\":");
68                imdbapi->year = getxmlentry(tmpstr, "\"Year\":");
69                imdbapi->rated = getxmlentry(tmpstr, "\"Rated\":");
70                imdbapi->released = getxmlentry(tmpstr, "\"Released\":");
71                imdbapi->genre = getxmlentry(tmpstr, "\"Genre\":");
72                imdbapi->director = getxmlentry(tmpstr, "\"Director\":");
73                imdbapi->writer = getxmlentry(tmpstr, "\"Writer\":");
74                imdbapi->actors = getxmlentry(tmpstr, "\"Actors\":");
75                imdbapi->plot = getxmlentry(tmpstr, "\"Plot\":");
76                imdbapi->poster = getxmlentry(tmpstr, "\"Poster\":");
77                imdbapi->runtime = getxmlentry(tmpstr, "\"Runtime\":");
78                imdbapi->rating = getxmlentry(tmpstr, "\"imdbapiRating\":");
79                imdbapi->votes = getxmlentry(tmpstr, "\"imdbapiVotes\":");
80                imdbapi->id = getxmlentry(tmpstr, "\"imdbapiID\":");
81
82                if(imdbapi->poster != NULL && flag2 == 0)
83                {
84                        char* ip = NULL, *pos = NULL, *path = NULL;
85                        ip = string_replace("http://", "", imdbapi->poster, 0);
86
87                        if(ip != NULL)
88                                pos = strchr(ip, '/');
89                        if(pos != NULL)
90                        {
91                                pos[0] = '\0';
92                                path = pos + 1;
93                        }
94
95                        if(flag1 == 1)
96                        {
97                                savefile = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
98                                savefile = ostrcat(savefile, imdbapi->id, 1, 0);
99                                savefile = ostrcat(savefile, "_poster.jpg", 1, 0);
100                                gethttp(ip, path, 80, savefile, NULL, NULL, 0);
101                                free(imdbapi->poster);
102                                imdbapi->poster = savefile;
103                                //create thumb
104                                savethumb = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
105                                savethumb = ostrcat(savethumb, imdbapi->id, 1, 0);
106                                savethumb = ostrcat(savethumb, "_thumb.jpg", 1, 0);
107                                buf = loadjpg(savefile, &width, &height, &rowbytes, &channels, 16);
108                                savejpg(savefile, 91, 140, buf);
109                                free(buf); buf = NULL;
110                                free(savethumb); savethumb = NULL;
111                        }
112                        else
113                        {
114                                gethttp(ip, path, 80, TMPIMDBAPIPIC, NULL, NULL, 0);
115                                free(imdbapi->poster);
116                                imdbapi->poster = ostrcat(TMPIMDBAPIPIC, NULL, 0, 0);
117                        }
118
119                        free(ip); ip = NULL;
120                }
121                else
122                {
123                        free(imdbapi->poster);
124                        imdbapi->poster = NULL;
125                }
126
127                free(tmpstr); tmpstr = NULL;
128                debug(10, "id: %s", imdbapi->id);
129                debug(10, "title: %s", imdbapi->title);
130                debug(10, "genre: %s", imdbapi->genre);
131                debug(10, "writer: %s", imdbapi->writer);
132                debug(10, "director: %s", imdbapi->director);
133                debug(10, "released: %s", imdbapi->released);
134                debug(10, "actors: %s", imdbapi->actors);
135                debug(10, "plot: %s", imdbapi->plot);
136                debug(10, "poster: %s", imdbapi->poster);
137                debug(10, "rating: %s", imdbapi->rating);
138                debug(10, "votes: %s", imdbapi->votes);
139                debug(10, "runtime: %s", imdbapi->runtime);                             
140        }
141
142        return imdbapi;
143}
144
145void screenimdbapi(char* title)
146{
147        int rcret = 0;
148        struct skin* imdbapiskin = getscreen("imdbapi");
149        struct skin* skin_plot = getscreennode(imdbapiskin, "plot");
150        struct skin* skin_title = getscreennode(imdbapiskin, "title");
151        struct skin* skin_director = getscreennode(imdbapiskin, "director");
152        struct skin* skin_writers = getscreennode(imdbapiskin, "writers");
153        struct skin* skin_genre = getscreennode(imdbapiskin, "genre");
154        struct skin* skin_releasetime = getscreennode(imdbapiskin, "releasetime");
155        struct skin* skin_cover = getscreennode(imdbapiskin, "cover");
156        struct skin* skin_actors = getscreennode(imdbapiskin, "actors");
157        struct imdbapi* node = NULL;
158        char* search = NULL;
159
160        setfbtransparent(255);
161        status.hangtime = 99999;
162
163        if(title == NULL) title = getepgakttitle(NULL);
164
165        node = getimdbapi(title, 0, 0, 0);
166start:
167        if(node != NULL)
168        {
169                changetext(skin_plot, node->plot);
170                changetext(skin_title, node->title);
171                changetext(skin_director, node->director);
172                changetext(skin_writers, node->writer);
173                changetext(skin_genre, node->genre);
174                changetext(skin_releasetime, node->released);
175                changetext(skin_actors, node->actors);
176                changepic(skin_cover, node->poster);
177        }
178
179        drawscreen(imdbapiskin, 0);
180
181        while(1)
182        {
183                rcret = waitrc(imdbapiskin, 0, 0);
184       
185                if(rcret == getrcconfigint("rcexit", NULL)) break;
186                if(rcret == getrcconfigint("rcok", NULL)) break;
187
188                if(rcret == getrcconfigint("rcred", NULL))
189        {
190                        search = textinput("Search", NULL);
191                        if(search != NULL)
192                        {
193                                freeimdbapi(node); node = NULL;
194                                node = getimdbapi(search, 0, 0, 0);
195                                free(search); search = NULL;
196                                goto start;
197                        }
198                        drawscreen(imdbapiskin, 0);
199                        continue;
200                }
201        }
202
203        freeimdbapi(node); node = NULL;
204        setosdtransparent(getskinconfigint("osdtransparent", NULL));
205        status.hangtime = getconfigint("hangtime", NULL);
206        clearscreen(imdbapiskin);
207}
208
209#endif
Note: See TracBrowser for help on using the repository browser.