source: titan/plugins/tmdb/tmdb.h @ 20034

Last change on this file since 20034 was 20034, checked in by obi, 11 years ago

fix mediadb

File size: 29.1 KB
Line 
1#ifndef TMDB_H
2#define TMDB_H
3
4#define TMPTMDBPIC1 "/tmp/tmptmdb1.jpg"
5#define TMPTMDBPIC2 "/tmp/tmptmdb2.jpg"
6#define TMPTMDBPIC3 "/tmp/tmptmdb3.jpg"
7#define TMPTMDBPIC4 "/tmp/tmptmdb4.jpg"
8#define TMPTMDBPIC5 "/tmp/tmptmdb5.mvi"
9
10struct tmdb* addtmdb(struct tmdb** first, int count, struct tmdb* last)
11{
12        //debug(1000, "in");
13        struct tmdb *newnode = NULL, *prev = NULL, *node = *first;
14
15        newnode = (struct tmdb*)calloc(1, sizeof(struct tmdb));
16        if(newnode == NULL)
17        {
18                err("no memory");
19                return NULL;
20        }
21
22        if(last == NULL)
23        {
24                while(node != NULL)
25                {
26                        prev = node;
27                        node = node->next;
28                }
29        }
30        else
31        {
32                prev = last;
33                node = last->next;
34        }
35
36        if(prev == NULL)
37                *first = newnode;
38        else
39        {
40                prev->next = newnode;
41                newnode->prev = prev;
42        }
43        newnode->next = node;
44        if(node != NULL) node->prev = newnode;
45
46        //debug(1000, "out");
47        return newnode;
48}
49
50int deltmdb(struct tmdb** first, struct tmdb* tnode, int flag)
51{
52        debug(1000, "in");
53        int ret = 1;
54
55        struct tmdb *node = *first, *prev = *first;
56
57        while(node != NULL)
58        {
59                if(node == tnode)
60                {
61                        ret = 0;
62                        if(node == *first)
63                        {
64                                *first = node->next;
65                                if(*first != NULL)
66                                        (*first)->prev = NULL;
67                        }
68                        else
69                        {
70                                prev->next = node->next;
71                                if(node->next != NULL)
72                                        node->next->prev = prev;
73                        }
74
75                        free(node->title); node->title = NULL;
76                        free(node->year); node->year = NULL;
77                        free(node->rated); node->rated = NULL;
78                        free(node->released); node->released = NULL;
79                        free(node->genre); node->genre = NULL;
80                        free(node->runtime); node->runtime = NULL;
81                        free(node->plot); node->plot = NULL;
82                        free(node->postermid); node->postermid = NULL;
83                        free(node->rating); node->rating = NULL;
84                        free(node->votes); node->votes = NULL;
85                        free(node->id); node->id = NULL;
86                        free(node->orgname); node->orgname = NULL;
87                        free(node->imdbid); node->imdbid = NULL;
88                        free(node->backdrop); node->backdrop = NULL;
89                        free(node->language); node->language = NULL;
90                        free(node->type); node->type = NULL;
91                        free(node->score); node->score = NULL;
92                        free(node->cover); node->cover = NULL;
93                        free(node->thumb); node->thumb = NULL;
94                        free(node->mvi); node->mvi = NULL;
95
96                        free(node);
97                        node = NULL;
98
99                        break;
100                }
101
102                prev = node;
103                node = node->next;
104        }
105
106        debug(1000, "out");
107        return ret;
108}
109
110void freetmdb(struct tmdb** first, int flag)
111{
112        debug(1000, "in");
113        struct tmdb *node = *first, *prev = *first;
114
115        while(node != NULL)
116        {
117                prev = node;
118                node = node->next;
119                if(prev != NULL)
120                        deltmdb(first, prev, flag);
121        }
122
123        unlink(TMPTMDBPIC1);
124        unlink(TMPTMDBPIC2);
125        unlink(TMPTMDBPIC3);
126        unlink(TMPTMDBPIC4);
127        unlink(TMPTMDBPIC5);
128
129        debug(1000, "out");
130}
131
132char* savetmdbpic(char* imdbid, char* url, char* tmppic, char* pic, int flag1)
133{
134        char* ip = NULL, *pos = NULL, *path = NULL, *ret = NULL;
135        char* savefile = NULL;
136
137        debug(133, "url: %s", url);
138       
139        if(imdbid == NULL || url == NULL) return NULL;
140        ip = string_replace("http://", "", url, 0);
141
142        if(ip != NULL)
143                pos = strchr(ip, '/');
144        if(pos != NULL)
145        {
146                pos[0] = '\0';
147                path = pos + 1;
148        }
149
150        if(flag1 == 1)
151        {
152                savefile = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
153                savefile = ostrcat(savefile, imdbid, 1, 0);
154                savefile = ostrcat(savefile, pic, 1, 0);
155                if(!file_exist(savefile))
156                        gethttp(ip, path, 80, savefile, NULL, 5000, NULL, 0);
157                ret = savefile;
158        }
159        else
160        {
161                gethttp(ip, path, 80, tmppic, NULL, 5000, NULL, 0);
162                ret = ostrcat(tmppic, NULL, 0, 0);
163        }
164
165        free(ip); ip = NULL;
166        return ret;
167}
168
169//flag: 0 = title search
170//flag: 1 = imdbid search
171//flag1: 0 = save pic in tmp
172//flag1: 1 = save pic in mediadb path if pic not exist
173//flag1: 2 = save pic in mediadb path
174//flag2: 2 = save no pic
175struct tmdb* gettmdb(struct tmdb** first, char* input, int flag, int flag1)
176{
177        debug(133, "title: %s",input);
178        debug(133, "flag: %d",flag);
179        debug(133, "flag1: %d",flag1);
180
181        if(checkinternet() == 1)
182        {
183                debug(133, "Error, Internet Connection not found");
184                return NULL;
185        }
186               
187        struct tmdb* tnode = NULL;
188        char* tmpstr = NULL, *tmpstr1 = NULL, *logdir = NULL, *logfile = NULL, *tmpsearch = NULL, *savefile = NULL, *timen = NULL, *log = NULL, *posterurl = NULL, *title = NULL, *tmpjpg = NULL, *tmpmpg = NULL, *tmpmeta = NULL;
189
190        title = ostrcat(title, input, 1, 0);
191
192        int count = 0;
193        int mvicount = 0;       
194        tmpsearch = ostrcat("2.1/", NULL, 0, 0);
195        if(flag == 0)
196                tmpsearch = ostrcat(tmpsearch, "Movie.search", 1, 0);
197        else
198                tmpsearch = ostrcat(tmpsearch, "Movie.imdbLookup", 1, 0);
199               
200        tmpsearch = ostrcat(tmpsearch, "/", 1, 0);
201        tmpsearch = ostrcat(tmpsearch, "de", 1, 0);
202        tmpsearch = ostrcat(tmpsearch, "/xml/", 1, 0);
203        tmpsearch = ostrcat(tmpsearch, "7bcd34bb47bc65d20a49b6b446a32866", 1, 0);
204        tmpsearch = ostrcat(tmpsearch, "/", 1, 0);
205        tmpsearch = ostrcat(tmpsearch, title, 1, 0);
206        tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
207
208        debug(133, "search: http://api.themoviedb.org/%s", tmpsearch);
209        tmpstr = gethttp("api.themoviedb.org", tmpsearch, 80, NULL, NULL, 5000, NULL, 0);
210       
211        debug(133, "tmpsearch: %s", tmpsearch);
212//      debug(133, "tmpstr: %s", tmpstr);
213                               
214        free(tmpsearch); tmpsearch = NULL;
215
216        logdir = ostrcat(getconfig("mediadbpath", NULL), "/.mediadbdebug", 0, 0);
217        if(!file_exist(logdir))
218                mkdir(logdir, 0777);
219        logfile = ostrcat(logdir, "/imdb-scan.log", 0, 0);
220        timen = ostrcat(oitoa(time(NULL)), NULL, 1, 0);
221
222        tmpjpg = ostrcat("/tmp/backdrop.resize.", timen, 0, 0);
223        tmpjpg = ostrcat(tmpjpg, ".jpg", 1, 0);
224
225        tmpmpg = ostrcat("/tmp/backdrop.resize.", timen, 0, 0);
226        tmpmpg = ostrcat(tmpmpg, ".mpg", 1, 0);
227
228        tmpmeta = ostrcat("/tmp/mediadb.", timen, 0, 0);
229        tmpmeta = ostrcat(tmpmeta, ".meta", 1, 0);
230
231        if(getconfigint("mediadbdebug", NULL) == 1)
232                filedebug(logfile, "#############\nTitle: %s\n#############", title);
233
234        if(tmpstr != NULL)
235        {
236                if(ostrstr(tmpstr, "<movies>Nothing found.</movies>") != NULL)
237                {
238      debug(133, "<movies>Nothing found.</movies>");
239                        free(tmpstr); tmpstr = NULL;
240                        return NULL;
241                }
242
243                tmpstr1 = ostrstr(tmpstr, "<movie>");
244
245                while(tmpstr1 != NULL)
246                {
247                        tnode = addtmdb(first, 1, tnode);
248                        if(tnode == NULL)
249                        {
250                                err("no mem");
251                                free(tmpstr); tmpstr = NULL;
252                                return *first;
253                        }
254                        count++;
255
256                        if(ostrstr(tmpstr1, "<name>") != NULL)
257                                tnode->title = string_resub("<name>", "</name>", tmpstr1, 0);
258
259                        if(ostrstr(tmpstr1, "<language>") != NULL)
260                                tnode->language = string_resub("<language>", "</language>", tmpstr1, 0);
261
262                        if(ostrstr(tmpstr1, "<type>") != NULL)
263                                tnode->type = string_resub("<type>", "</type>", tmpstr1, 0);
264
265                        if(ostrstr(tmpstr1, "<original_name>") != NULL)
266                                tnode->orgname = string_resub("<original_name>", "</original_name>", tmpstr1, 0);
267
268                        if(ostrstr(tmpstr1, "<score>") != NULL)
269                                tnode->score = string_resub("<score>", "</score>", tmpstr1, 0);
270
271                        if(ostrstr(tmpstr1, "<rated>") != NULL)
272                                tnode->rated = string_resub("<rated>", "</rated>", tmpstr1, 0);
273
274                        if(ostrstr(tmpstr1, "<released>") != NULL)
275                                tnode->released = string_resub("<released>", "</released>", tmpstr1, 0);
276
277                        if(ostrstr(tmpstr1, "<categories>") != NULL)
278                        {
279                                char* tmpcat = string_resub("<categories>", "</categories>", tmpstr1, 0);
280                                char* ptmpcat = ostrstr(tmpcat, "<category ");
281                                while(ptmpcat != NULL)
282                                {
283                                        tnode->genre = ostrcat(tnode->genre, string_resub("<category type=\"genre\" name=\"", "\" url=", ptmpcat, 0), 1, 1);
284                                        ptmpcat += 5;
285                                        ptmpcat = ostrstr(ptmpcat, "<category ");
286
287                                        if(ptmpcat != NULL)
288                                                tnode->genre = ostrcat(tnode->genre, ", ", 1, 0);
289                                }
290                                free(tmpcat); tmpcat = NULL;
291                        }
292
293                        if(ostrstr(tmpstr1, "<runtime>") != NULL)
294                                tnode->runtime = string_resub("<runtime>", "</runtime>", tmpstr1, 0);
295
296                        if(ostrstr(tmpstr1, "<overview>") != NULL)
297                                tnode->plot = string_resub("<overview>", "</overview>", tmpstr1, 0);
298
299                        if(ostrstr(tmpstr1, "size=\"thumb\"") != NULL)
300                                tnode->thumb = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"thumb\".*", tmpstr1);
301
302                        if(ostrstr(tmpstr1, "size=\"cover\"") != NULL)
303                                tnode->cover = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"cover\".*", tmpstr1);
304
305                        if(ostrstr(tmpstr1, "<images>") != NULL)
306                        {
307                                char* tmpcat = string_resub("<images>", "</images>", tmpstr1, 0);
308                                if(tmpcat != NULL)
309                                        tnode->postermid = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"mid\".*", tmpcat);
310                                free(tmpcat); tmpcat = NULL;
311                        }
312                       
313                        if(tnode->postermid == NULL && ostrstr(tmpstr1, "size=\"mid\"") != NULL)
314                                tnode->postermid = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"mid\".*", tmpstr1);
315
316                        if(ostrstr(tmpstr1, "<images>") != NULL)
317                        {
318                                char* tmpcat = string_resub("<images>", "</images>", tmpstr1, 0);
319                                char* ptmpcat = ostrstr(tmpcat, "<image ");
320
321                                while(ptmpcat != NULL)
322                                {
323                                        tnode->backdrop = ostrcat(tnode->backdrop, string_resub("<image type=\"backdrop\" url=\"", "\" size=", ptmpcat, 0), 1, 1);
324                                        ptmpcat += 5;
325                                        ptmpcat = ostrstr(ptmpcat, "<image ");
326
327                                        if(ptmpcat != NULL)
328                                        {
329                                                mvicount++;
330                                                tnode->backdrop = ostrcat(tnode->backdrop, "\n", 1, 0);
331                                        }
332                                }
333                                free(tmpcat); tmpcat = NULL;
334                        }
335
336                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL)
337                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\" width=\"1920\" height=\"1080\".*", tmpstr1);
338                               
339                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL)
340                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\" width=\"1280\" height=\"720\".*", tmpstr1);
341
342                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w1280\"") != NULL)
343                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w1280/.*)\" size=\"w1280\" width=\"1280\" height=\"720\".*", tmpstr1);
344
345                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w780\"") != NULL)
346                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w780/.*)\" size=\"poster\" width=\"780\" height=\"439\".*", tmpstr1);
347
348                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL)
349                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\".*", tmpstr1);
350
351                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w1280\"") != NULL)
352                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w1280/.*)\" size=\"w1280\".*", tmpstr1);
353
354                        if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"poster\"") != NULL)
355                                tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/poster/.*)\" size=\"poster\".*", tmpstr1);
356
357                        if(ostrstr(tmpstr1, "<imdb_id>") != NULL)
358                                tnode->imdbid = string_resub("<imdb_id>", "</imdb_id>", tmpstr1, 0);
359
360                        if(getconfigint("mediadbdebug", NULL) == 1 && tnode->backdrop == NULL)
361                        {
362                                log = ostrcat(logdir, "/tmdb_", 0, 0);
363                                if(tnode->imdbid != NULL)
364                                        log = ostrcat(log, tnode->imdbid, 1, 0);
365                                else
366                                        log = ostrcat(log, timen, 1, 0);
367                               
368                                log = ostrcat(log, "_html", 1, 0);
369                                writesys(log, tmpstr1, 1);
370                                free(log), log = NULL;
371                               
372                                log = ostrcat(logdir, "/tmdb_", 0, 0);
373                                if(tnode->imdbid != NULL)
374                                        log = ostrcat(log, tnode->imdbid, 1, 0);
375                                else
376                                        log = ostrcat(log, timen, 1, 0);
377
378                                log = ostrcat(log, "_link", 1, 0);
379                                writesys(log, tnode->backdrop, 1);
380                                free(log), log = NULL;
381                        }
382
383                        if(ostrstr(tmpstr1, "<rating>") != NULL)
384                                tnode->rating = string_resub("<rating>", "</rating>", tmpstr1, 0);
385
386                        if(ostrstr(tmpstr1, "<votes>") != NULL)
387                                tnode->votes = string_resub("<votes>", "</votes>", tmpstr1, 0);
388
389                        if(ostrstr(tmpstr1, "<id>") != NULL)
390                                tnode->id = string_resub("<id>", "</id>", tmpstr1, 0);
391
392                        if((flag1 == 0 && count == 1) || flag1 == 1 || flag1 == 2)
393                        {
394                                savefile = savetmdbpic(tnode->imdbid, tnode->thumb, TMPTMDBPIC1, "_thumb.jpg", flag1);
395                                free(tnode->thumb);
396                                tnode->thumb = savefile;
397
398                                savefile = savetmdbpic(tnode->imdbid, tnode->cover, TMPTMDBPIC2, "_cover.jpg", flag1);
399                                free(tnode->cover);
400                                tnode->cover = savefile;
401
402                                savefile = savetmdbpic(tnode->imdbid, tnode->postermid, TMPTMDBPIC3, "_postermid.jpg", flag1);
403                                posterurl = ostrcat(posterurl, tnode->postermid, 1, 0);
404                                free(tnode->postermid);
405                                tnode->postermid = savefile;
406
407                                if(mvicount == 0)
408                                {
409                                        savefile = savetmdbpic(tnode->imdbid, tnode->backdrop, TMPTMDBPIC4, "_backdrop1.jpg", flag1);
410                                        free(tnode->backdrop);
411                                        tnode->backdrop = savefile;                                     
412                                }
413                        }
414                                                       
415                        if((flag1 == 1 || flag1 == 2) && tnode->backdrop != NULL && tnode->imdbid != NULL)
416                        {
417                                debug(133, "load backdrop flag1: %d", flag1);
418                                char* tmppath = NULL;
419                                mvicount = 0;
420                                char* tmpstr2 = NULL;
421                                tmpstr2 = ostrcat(tnode->backdrop, NULL, 0, 0);
422                                struct splitstr* ret1 = NULL;
423                                int rcount = 0;
424                                int i = 0;
425                                ret1 = strsplit(tmpstr2, "\n", &rcount);
426                                for(i = 0; i < rcount; i++)
427                                {
428                                        if(ostrstr((&ret1[i])->part, "/original/") != NULL)
429                                        {
430                                                mvicount++;
431                                                debug(133, "load %s\n",(&ret1[i])->part);
432
433                                                if(!ostrncmp("http://", (&ret1[i])->part, 7))
434                                                {
435                                                        tmppath = ostrcat("_backdrop", oitoa(mvicount), 0, 1);
436                                                        tmppath = ostrcat(tmppath, ".jpg", 1, 0);
437
438                                                        savefile = savetmdbpic(tnode->imdbid, (&ret1[i])->part, TMPTMDBPIC4, tmppath, flag1);
439                                                        if(file_exist(savefile))
440                                                        {
441                                                                free(tnode->backdrop);
442                                                                tnode->backdrop = savefile;
443               
444                                                                free(tnode->mvi);
445                                                                tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
446                                                                tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0);
447                                                                tnode->mvi = ostrcat(tnode->mvi, "_backdrop", 1, 0);
448                                                                tnode->mvi = ostrcat(tnode->mvi, oitoa(mvicount), 1, 1);
449                                                                tnode->mvi = ostrcat(tnode->mvi, ".mvi", 1, 0);
450                                                               
451                                                                if((!file_exist(tnode->mvi)) || (flag1 == 2))
452                                                                {
453
454                                                                        off64_t filesize = getfilesize(tnode->backdrop);
455                                                                        debug(133, "filesize %lld", filesize);
456                                                                       
457                                                                        if(filesize < 1500000)
458                                                                        {
459                                                                                char* cmd = NULL;
460                                                                                cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0);
461                                                                                cmd = ostrcat(cmd, tnode->backdrop, 1, 0);
462                                                                                cmd = ostrcat(cmd, " > ", 1, 0);
463                                                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
464                                                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
465                                               
466                                                                                debug(133, "cmd %s", cmd);
467                                                                                system(cmd);
468                                                                                free(cmd); cmd = NULL;
469
470                                                                                cmd = ostrcat(cmd, "cat ", 1, 0);
471                                                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
472                                                                                cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0);
473                                                                                char* size = string_newline(command(cmd));
474                                                                                free(cmd), cmd = NULL; 
475                                                                                debug(133, "size %s", size);
476                                                                                if(size != NULL)
477                                                                                {
478                                                                                        debug(133, "size %d", atoi(size));
479                                                                                        int picsize = atoi(size);
480                                                                                        unlink(tmpmeta);
481               
482                                                                                        if(picsize < 2000)
483                                                                                        {
484                                                                                                debug(133, "size ok %d", picsize);
485                                                                                                cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0);
486                                                                                                cmd = ostrcat(cmd, tmpjpg, 1, 0);
487                                                                                                cmd = ostrcat(cmd, " -copy none ", 1, 0);
488                                                                                                cmd = ostrcat(cmd, tnode->backdrop, 1, 0);
489                                                                                                                               
490                                                                                                debug(133, "cmd %s", cmd);
491                                                                                                system(cmd);
492                                                                                                free(cmd); cmd = NULL;
493                                                                                                if(file_exist(tmpjpg))
494                                                                                                {
495                                                                                                        free(cmd), cmd = NULL;
496                                                                                                        cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0);
497                                                                                                        cmd = ostrcat(cmd, tmpjpg, 1, 0);
498                                                                                                        cmd = ostrcat(cmd, " ", 1, 0);
499                                                                                                        cmd = ostrcat(cmd, tmpmpg, 1, 0);
500
501                                                                                                        if(getconfigint("mediadbdebug", NULL) == 1)
502                                                                                                        {
503                                                                                                                filedebug(logfile, "#############\nbackdrop: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
504                                                                                                                cmd = ostrcat(cmd, " >> ", 1, 0);
505                                                                                                                cmd = ostrcat(cmd, logfile, 1, 0);
506                                                                                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
507                                                                                                        }
508                                                                                                        else
509                                                                                                        {
510                                                                                                                cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0);
511                                                                                                        }
512                                                                                                        debug(133, "cmd %s", cmd);
513                                                                                                        system(cmd);
514                                                                                                        free(cmd); cmd = NULL;
515                                                                                                       
516                                                                                                        if(file_exist(tmpmpg))
517                                                                                                        {
518                                                                                                                cmd = ostrcat(cmd, "mv -f ", 1, 0);
519                                                                                                                cmd = ostrcat(cmd, tmpmpg, 1, 0);
520                                                                                                                cmd = ostrcat(cmd, " ", 1, 0);
521                                                                                                                cmd = ostrcat(cmd, tnode->mvi, 1, 0);
522                                                                                                                debug(133, "cmd %s", cmd);
523                                                                                                                system(cmd);
524                                                                                                                free(cmd); cmd = NULL;
525                                                                                                               
526                                                                                                                if(getconfigint("mediadbdebug", NULL) == 1)
527                                                                                                                        writesysint("/proc/sys/vm/drop_caches", 3, 0);
528                                                                                                               
529                                                                                                                if(mvicount == getconfigint("mediadbbackdrop", NULL))
530                                                                                                                        break;
531                                                                                                        }
532                                                                                                        else
533                                                                                                                mvicount--;
534                                                                                                }
535                                                                                        }
536                                                                                        else
537                                                                                        {
538                                                                                                debug(133, "ERROR Backdrop size to big skipped %d", picsize);
539
540                                                                                                if(getconfigint("mediadbdebug", NULL) == 1)
541                                                                                                        filedebug(logfile, "#############\nERROR Backdrop size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
542                                                                                                mvicount--;
543                                                                                        }
544                                                                                }
545                                                                                else
546                                                                                {
547                                                                                        debug(133, "ERROR Backdrop size is NULL skipped %s", size);
548
549                                                                                        if(getconfigint("mediadbdebug", NULL) == 1)
550                                                                                                filedebug(logfile, "#############\nERROR Backdrop size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
551
552                                                                                        mvicount--;
553                                                                                }
554                                                                                free(size), size = NULL;
555                                                                                unlink(tmpmeta);
556                                                                                unlink(tmpjpg);
557                                                                                unlink(tmpmpg);
558                                                                        }
559                                                                        else
560                                                                        {
561                                                                                debug(133, "ERROR Backdrop filesize to BIG skipped %lld", filesize);
562                               
563                                                                                if(getconfigint("mediadbdebug", NULL) == 1)
564                                                                                        filedebug(logfile, "#############\nERROR Backdrop filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->backdrop, filesize, (&ret1[i])->part);
565                                                                        }
566                                                                }                                                               
567
568                                                                free(tmppath), tmppath = NULL;
569                                                        }
570                                                        else
571                                                                mvicount--;
572                                                }
573                                                else
574                                                {
575                                                        log = ostrcat(logdir, "/tmdb_", 0, 0);
576                                                        if(tnode->imdbid != NULL)
577                                                                log = ostrcat(log, tnode->imdbid, 1, 0);
578                                                        else
579                                                                log = ostrcat(log, timen, 1, 0);
580                                                       
581                                                        log = ostrcat(log, "_html", 1, 0);
582                                                       
583                                                        char* cmd = NULL;
584                                                        cmd = command("free");
585                                                        log = ostrcat(log, "_error_link", 1, 0);
586                                                        cmd = ostrcat(cmd, "\nlink: ", 1, 0);
587                                                        cmd = ostrcat(cmd, (&ret1[i])->part, 1, 0);
588                                                        writesys(log, cmd, 1);
589                                                        free(cmd), cmd = NULL;
590                                                        free(log), log = NULL;
591                                                        mvicount--;
592                                                }
593
594                                                if(file_exist(tnode->mvi))
595                                                        unlink(tnode->backdrop);
596                                        }
597                                }
598                                free(ret1), ret1 = NULL;                               
599                                free(tmpstr2), tmpstr2 = NULL;
600                        }
601                        else if((flag1 == 1 || flag1 == 2) && tnode->postermid != NULL && tnode->imdbid != NULL)
602                        {
603                                debug(133, "load postermid flag1: %d", flag1);
604
605                                free(tnode->mvi);
606                                tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
607                                tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0);
608                                tnode->mvi = ostrcat(tnode->mvi, "_backdrop1.mvi", 1, 0);
609                               
610                                if((!file_exist(tnode->mvi)) || (flag1 == 2))
611                                {
612
613                                        off64_t filesize = getfilesize(tnode->backdrop);
614                                        debug(133, "filesize %lld", filesize);
615                                       
616                                        if(filesize < 1500000)
617                                        {
618                                                char* cmd = NULL;
619                                                cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0);
620                                                cmd = ostrcat(cmd, tnode->postermid, 1, 0);
621                                                cmd = ostrcat(cmd, " > ", 1, 0);
622                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
623                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
624               
625                                                debug(133, "cmd %s", cmd);
626                                                system(cmd);
627                                                free(cmd); cmd = NULL;
628
629                                                cmd = ostrcat(cmd, "cat ", 1, 0);
630                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
631                                                cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0);
632                                                char* size = string_newline(command(cmd));
633                                                free(cmd), cmd = NULL;
634                                                debug(133, "size %s", size);
635                                                if(size != NULL)
636                                                {
637                                                        debug(133, "size %d", atoi(size));
638                                                        int picsize = atoi(size);
639               
640                                                        if(picsize < 2000)
641                                                        {
642                                                                debug(133, "size ok %d", picsize);
643                                                                cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0);
644                                                                cmd = ostrcat(cmd, tmpjpg, 1, 0);
645                                                                cmd = ostrcat(cmd, " -copy none ", 1, 0);
646                                                                cmd = ostrcat(cmd, tnode->postermid, 1, 0);
647                               
648                                                                debug(133, "cmd %s", cmd);
649                                                                system(cmd);
650                                                                free(cmd); cmd = NULL;
651                                                                                               
652                                                                if(file_exist(tmpjpg))
653                                                                {
654                                                                        free(cmd), cmd = NULL;
655                                                                        cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0);
656                                                                        cmd = ostrcat(cmd, tmpjpg, 1, 0);
657                                                                        cmd = ostrcat(cmd, " ", 1, 0);
658                                                                        cmd = ostrcat(cmd, tmpmpg, 1, 0);
659
660                                                                        if(getconfigint("mediadbdebug", NULL) == 1)
661                                                                        {
662                                                                                filedebug(logfile, "#############\npostermid: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);   
663                                                                                cmd = ostrcat(cmd, " >> ", 1, 0);
664                                                                                cmd = ostrcat(cmd, logfile, 1, 0);
665                                                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
666                                                                        }
667                                                                        else
668                                                                        {
669                                                                                cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0);
670                                                                        }
671
672                                                                        debug(133, "cmd %s", cmd);
673                                                                        system(cmd);
674                                                                        free(cmd); cmd = NULL;
675                                                                        if(file_exist(tmpmpg))
676                                                                        {                                       
677                                                                                cmd = ostrcat(cmd, "mv -f ", 1, 0);
678                                                                                cmd = ostrcat(cmd, tmpmpg, 1, 0);
679                                                                                cmd = ostrcat(cmd, " ", 1, 0);
680                                                                                cmd = ostrcat(cmd, tnode->mvi, 1, 0);
681                                                                                debug(133, "cmd %s", cmd);
682                                                                                system(cmd);
683                                                                                free(cmd); cmd = NULL;
684                                                                               
685                                                                                writesysint("/proc/sys/vm/drop_caches", 3, 0);
686                                                                        }
687                                                                }
688                                                                free(cmd), cmd = NULL;
689                                                        }
690                                                        else
691                                                        {
692                                                                debug(133, "ERROR Postermid size to big skipped %d", picsize);
693
694                                                                if(getconfigint("mediadbdebug", NULL) == 1)
695                                                                        filedebug(logfile, "#############\nERROR Postermid size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);
696                                                        }
697                                                }
698                                                else
699                                                {
700                                                        debug(133, "ERROR Postermid size is NULL skipped %s", size);
701
702                                                        if(getconfigint("mediadbdebug", NULL) == 1)
703                                                                filedebug(logfile, "#############\nERROR Postermid size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);
704                                                }
705                                                free(size), size = NULL;
706                                                unlink(tmpmeta);
707                                                unlink(tmpjpg);
708                                                unlink(tmpmpg);
709                                        }
710                                        else
711                                        {
712                                                debug(133, "ERROR Postermid filesize to BIG skipped %lld", filesize);
713
714                                                if(getconfigint("mediadbdebug", NULL) == 1)
715                                                        filedebug(logfile, "#############\nERROR Postermid filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->postermid, filesize, posterurl);     
716                                        }
717                                }
718                        }
719
720                        debug(133, "mvi=%s (mvicount=%d)", tnode->mvi,flag1);
721                        debug(133, "backdrop=%s (mvicount=%d)", tnode->backdrop,flag1);
722
723                        if(file_exist(tnode->mvi))
724                                unlink(tnode->backdrop);
725
726                        if(mvicount > 0)
727                        {
728                                free(tnode->mvi);
729                                tnode->mvi = ostrcat(oitoa(mvicount), NULL, 1, 0);
730                        }
731                        else
732                        {
733                                free(tnode->mvi);
734                                tnode->mvi = ostrcat("1", NULL, 0, 0);
735                        }
736                        debug(133, "change mvi=%s (mvicount=%d)", tnode->mvi,flag1);
737
738                        tmpstr1 += 5;
739                        tmpstr1 = ostrstr(tmpstr1, "<movie>");
740
741                        free(posterurl), posterurl = NULL;
742                        free(logdir), logdir = NULL;
743                        free(logfile), logfile = NULL;
744
745                        debug(133, "----------------------tmdb start----------------------");
746                        debug(133, "title: %s", tnode->title);
747                        debug(133, "language: %s", tnode->language);
748                        debug(133, "type: %s", tnode->type);
749                        debug(133, "orgname: %s", tnode->orgname);
750                        debug(133, "score: %s", tnode->score);
751                        debug(133, "rating: %s", tnode->rating);
752                        debug(133, "released: %s", tnode->released);
753                        debug(133, "genre: %s", tnode->genre);
754                        debug(133, "runtime: %s", tnode->runtime);
755                        debug(133, "plot: %s", tnode->plot);
756                        debug(133, "thumb: %s", tnode->thumb);
757                        debug(133, "cover: %s", tnode->cover);
758                        debug(133, "postermid: %s", tnode->postermid);
759                        debug(133, "backdrop: %s", tnode->backdrop);
760                        debug(133, "mvi: %s", tnode->mvi);
761                        debug(133, "rating: %s", tnode->rating);
762                        debug(133, "votes: %s", tnode->votes);
763                        debug(133, "id: %s", tnode->id);       
764                        debug(133, "imdbid: %s", tnode->imdbid);
765                        debug(133, "----------------------tmdb end----------------------");
766                }
767        }
768
769        free(tmpstr); tmpstr = NULL;
770        return *first;
771}
772
773//flag 0: only view
774//flag 1: can return tmdb node
775struct tmdb* screentmdb(char* title, char* skinname, int flag, char* path, char* file)
776{
777        debug(133, "title: %s",title);
778        debug(133, "path: %s",path);
779        debug(133, "file: %s",file);   
780        char* searchstr = NULL, *tmpstr = NULL;
781
782        if(checkinternet() == 1)
783        {
784                textbox(_("Message"), _("Error, Internet Connection not found"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1100, 500, 10, 0);
785                return NULL;
786        }
787
788        int rcret = 0;
789        struct skin* tmdbskin = NULL;
790
791        if(skinname != NULL)
792                tmdbskin = getscreen(skinname);
793        else
794                tmdbskin = getscreen("tmdb");
795
796        struct skin* skin_plot = getscreennode(tmdbskin, "plot");
797        struct skin* skin_title = getscreennode(tmdbskin, "title");
798        struct skin* skin_orgname = getscreennode(tmdbskin, "orgname");
799        struct skin* skin_rating = getscreennode(tmdbskin, "rating");
800        struct skin* skin_genre = getscreennode(tmdbskin, "genre");
801        struct skin* skin_released = getscreennode(tmdbskin, "released");
802        struct skin* skin_cover = getscreennode(tmdbskin, "cover");
803        struct skin* skin_votes = getscreennode(tmdbskin, "votes");
804        struct skin* skin_b3 = getscreennode(tmdbskin, "b3");
805        struct skin* load = getscreen("loading");
806        struct skin* blackscreen = getscreen("blackscreen");
807       
808        struct tmdb* node = NULL, *retnode = NULL;
809        char* search = NULL;
810
811//      setfbtransparent(255);
812        status.hangtime = 99999;
813
814//      if(flag == 0)
815//              skin_b3->hidden = YES;
816//      else
817//              skin_b3->hidden = NO;
818
819        if(path == NULL || file == NULL || !file_exist(getconfig("mediadbpath", NULL)))
820                skin_b3->hidden = YES;
821        else
822                skin_b3->hidden = NO;
823                               
824        if(title == NULL)
825                searchstr = getepgakttitle(NULL);
826        else
827        {
828                int isrec = 0, iscam = 0;
829                tmpstr = createshortname(file, &isrec, &iscam, 1);
830                if(tmpstr != NULL)
831                        searchstr = ostrcat(searchstr, tmpstr, 1, 0);
832                else
833                        searchstr = ostrcat(searchstr, title, 1, 0);
834        }
835
836        debug(133, "searchstr: %s",searchstr);
837
838        drawscreen(blackscreen, 0, 0);
839        drawscreen(load, 0, 0);
840
841        node = gettmdb(&node, searchstr, 0, 0);
842        clearscreen(load);
843        clearscreen(blackscreen);
844
845start:
846        if(node != NULL)
847        {
848                changetext(skin_plot, node->plot);
849                changetext(skin_title, node->title);
850                changetext(skin_orgname, node->orgname);
851                changetext(skin_rating, node->rating);
852                changetext(skin_genre, node->genre);
853                changetext(skin_released, node->released);
854                char* tmpstr = NULL;
855                tmpstr = ostrcat("( ", node->votes, 0, 0);
856                tmpstr = ostrcat(tmpstr, " votes)", 1, 0);             
857                changetext(skin_votes, tmpstr);
858                free(tmpstr), tmpstr = NULL;
859                changepic(skin_cover, TMPTMDBPIC3);
860                skin_cover->hidden = NO;
861        }
862        else
863        {
864                changetext(skin_plot, "--plot--");
865                changetext(skin_title, "--title--");
866                changetext(skin_orgname, "--orgname--");
867                changetext(skin_rating, "--rating--");
868                changetext(skin_genre, "--genre--");
869                changetext(skin_released, "--releasetime--");
870                changetext(skin_votes, "( --votes-- )");               
871                skin_cover->hidden = YES;
872        }
873
874        drawscreen(tmdbskin, 0, 0);
875
876        while(1)
877        {
878                rcret = waitrc(tmdbskin, 0, 0);
879       
880                if(rcret == getrcconfigint("rcexit", NULL)) break;
881                if(rcret == getrcconfigint("rcok", NULL)) break;
882
883                if(rcret == getrcconfigint("rcred", NULL))
884                {
885                        search = textinput("Search", searchstr);
886                        if(search != NULL)
887                        {
888                                freetmdb(&node, 0), node = NULL;
889                                drawscreen(blackscreen, 0, 0);
890                                drawscreen(load, 0, 0);
891                                node = gettmdb(&node, search, 0, 0);
892                                clearscreen(load);
893                                clearscreen(blackscreen);
894                                free(search), search = NULL;
895                                goto start;
896                        }
897                        drawscreen(tmdbskin, 0, 0);
898                        continue;
899                }
900                if(rcret == getrcconfigint("rcgreen", NULL))
901                {
902                        struct tmdb* tnode = node;
903                        struct menulist* mlist = NULL, *mbox = NULL;
904
905                        while(tnode != NULL)
906                        {
907                                addmenulist(&mlist, tnode->title, tnode->imdbid, NULL, 0, 0);
908                                tnode = tnode->next;
909                        }
910
911                        mbox = menulistbox(mlist, NULL, NULL, NULL, NULL, 0, 0);
912                        if(mbox != NULL)
913                        {
914                                search = ostrcat(mbox->text, NULL, 0, 0);
915                                if(search != NULL)
916                                {
917                                        freetmdb(&node, 0); node = NULL;
918                                        drawscreen(blackscreen, 0, 0);
919                                        drawscreen(load, 0, 0);
920                                        node = gettmdb(&node, search, 1, 0);
921                                        clearscreen(load);
922                                        clearscreen(blackscreen);
923                                        free(search), search = NULL;
924                                        freemenulist(mlist, 1); mlist = NULL, mbox = NULL;
925                                        goto start;
926                                }
927                        }
928                        freemenulist(mlist, 1); mlist = NULL, mbox = NULL;
929                        drawscreen(tmdbskin, 0, 0);
930                        continue;
931                }
932                if(rcret == getrcconfigint("rcyellow", NULL) && flag == 1)
933                {
934                        retnode = node;
935                        break;
936                }
937
938                if(rcret == getrcconfigint("rcyellow", NULL) && path != NULL && file != NULL && node != NULL && node->imdbid != NULL && flag == 2)
939                {
940                        drawscreen(blackscreen, 0, 0);
941                        drawscreen(load, 0, 0);
942                        debug(133, "path: %s",path);
943                        debug(133, "file: %s",file);
944                        debug(133, "type: 2");
945                        debug(133, "node->imdbid: %s",node->imdbid);
946                        addconfigtmp("mediadbscantimeout", "0");
947                        mediadbfindfilecb(path, file, 0, node->imdbid, 2);
948                        delconfigtmp("mediadbscantimeout");                     
949                        clearscreen(load);
950                        clearscreen(blackscreen);
951                        break;
952                }
953        }
954
955        if(retnode == NULL)
956        {
957                freetmdb(&node, 0);
958                node = NULL;
959        }
960
961        free(searchstr), searchstr = NULL;
962//      setosdtransparent(getskinconfigint("osdtransparent", NULL));
963        status.hangtime = getconfigint("hangtime", NULL);
964        clearscreen(tmdbskin);
965
966        return retnode;
967}
968
969#endif
Note: See TracBrowser for help on using the repository browser.