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