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

Last change on this file since 25041 was 25041, checked in by obi, 10 years ago

[tmdb] add api 3 support

File size: 27.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, *tmpstr2 = NULL, *tmpstr3 = 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/*
195        tmpsearch = ostrcat("2.1/", NULL, 0, 0);
196        if(flag == 0)
197                tmpsearch = ostrcat(tmpsearch, "Movie.search", 1, 0);
198        else
199                tmpsearch = ostrcat(tmpsearch, "Movie.imdbLookup", 1, 0);
200               
201        tmpsearch = ostrcat(tmpsearch, "/", 1, 0);
202        tmpsearch = ostrcat(tmpsearch, "de", 1, 0);
203        tmpsearch = ostrcat(tmpsearch, "/xml/", 1, 0);
204        tmpsearch = ostrcat(tmpsearch, "7bcd34bb47bc65d20a49b6b446a32866", 1, 0);
205        tmpsearch = ostrcat(tmpsearch, "/", 1, 0);
206        tmpsearch = ostrcat(tmpsearch, title, 1, 0);
207        tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
208*/
209
210        if(flag == 1)
211        {
212                tmpsearch = ostrcat("3/movie/", NULL, 0, 0);
213                tmpsearch = ostrcat(tmpsearch, title, 1, 0);
214        }
215        else
216                tmpsearch = ostrcat("3/movie/tt0083944", NULL, 0, 0);
217
218        tmpsearch = ostrcat(tmpsearch, "?api_key=351217450d7c7865ca39c74a7e3a0a4b&language=de", 1, 0);
219
220        debug(133, "search: http://api.themoviedb.org/%s", tmpsearch);
221        tmpstr = gethttp("api.themoviedb.org", tmpsearch, 80, NULL, NULL, 5000, NULL, 0);
222//      writesys("/var/usr/local/share/titan/plugins/tmdb/tmpstr", tmpstr, 1);
223       
224        debug(133, "tmpsearch: %s", tmpsearch);
225        debug(133, "tmpstr: %s", tmpstr);
226                               
227        free(tmpsearch); tmpsearch = NULL;
228
229        logdir = ostrcat(getconfig("mediadbpath", NULL), "/.mediadbdebug", 0, 0);
230        if(!file_exist(logdir))
231                mkdir(logdir, 0777);
232        logfile = ostrcat(logdir, "/imdb-scan.log", 0, 0);
233        timen = ostrcat(oitoa(time(NULL)), NULL, 1, 0);
234
235        tmpjpg = ostrcat("/tmp/backdrop.resize.", timen, 0, 0);
236        tmpjpg = ostrcat(tmpjpg, ".jpg", 1, 0);
237
238        tmpmpg = ostrcat("/tmp/backdrop.resize.", timen, 0, 0);
239        tmpmpg = ostrcat(tmpmpg, ".mpg", 1, 0);
240
241        tmpmeta = ostrcat("/tmp/mediadb.", timen, 0, 0);
242        tmpmeta = ostrcat(tmpmeta, ".meta", 1, 0);
243
244        if(getconfigint("mediadbdebug", NULL) == 1)
245                filedebug(logfile, "#############\nTitle: %s\n#############", title);
246
247        free(tmpsearch); tmpsearch = NULL;
248        char* ret = NULL;
249
250        if(tmpstr != NULL && ostrstr(tmpstr, "Invalid id - The pre-requisite id is invalid or not found") == NULL)
251        {
252                ret = getxmlentry(tmpstr, "\"Response\":");
253                if(ostrcmp(ret, "False") == 0)
254                {
255                        free(ret); ret = NULL;
256                        free(tmpstr); tmpstr = NULL;
257                        return NULL;
258                }
259                free(ret); ret = NULL;
260
261                tnode = addtmdb(first, 1, tnode);
262                if(tnode == NULL)
263                {
264                        err("no mem");
265                        free(tmpstr); tmpstr = NULL;
266                        return *first;
267                }
268                count++;
269
270                tmpstr1 = ostrcat(tmpstr, NULL, 0, 0);
271                int count = 0;
272                int incount = 0;
273                int i = 0;
274                struct splitstr* ret1 = NULL;
275                ret1 = strsplit(tmpstr1, ",", &count);
276                if(ret1 != NULL)
277                {
278                        int max = count;
279                        for(i = 0; i < max; i++)
280                        {
281                                if(ostrstr(ret1[i].part, "\"backdrop_path\"") != NULL)
282                                {
283                                        tmpstr2 = string_resub("\"backdrop_path\":\"", "\"", ret1[i].part, 0);
284                                        tmpstr3 = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w1280", tmpstr2, 0, 0);
285                                        tnode->backdrop = ostrcat(tnode->backdrop, tmpstr3, 1, 0);
286                                        tnode->backdrop = ostrcat(tnode->backdrop, "\n", 1, 0);
287       
288                                        mvicount++;
289                                }
290                        }
291                }
292                free(tmpstr2), tmpstr2 = NULL;                         
293                free(tmpstr3), tmpstr3 = NULL; 
294                free(ret1), ret1 = NULL;
295       
296                tmpstr1 = getxmlentry(tmpstr, "\"genres\":");
297                tmpstr2 = string_resub("[", "]", tmpstr1, 0);
298                count = 0;
299                incount = 0;
300                i = 0;
301                struct splitstr* ret2 = NULL;
302                ret2 = strsplit(tmpstr2, ",", &count);
303                if(ret1 != NULL)
304                {
305                        int max = count;
306                        for(i = 0; i < max; i++)
307                        {       
308                                if(ostrstr(ret1[i].part, "\"name\"") != NULL)
309                                {
310                                        tmpstr3 = string_resub("\"name\":\"", "\"", ret2[i].part, 0);
311                                        if(tnode->genre != NULL)
312                                                tnode->genre = ostrcat(tnode->genre, ",", 1, 0);                                               
313                                        tnode->genre = ostrcat(tnode->genre, tmpstr3, 1, 0);
314                                }
315                        }
316                }
317                free(tmpstr2), tmpstr2 = NULL;                         
318                free(tmpstr3), tmpstr3 = NULL;
319                free(ret2), ret2 = NULL;                               
320               
321                tnode->title = getxmlentry(tmpstr, "\"title\":");
322
323                tmpstr2 = getxmlentry(tmpstr, "\"spoken_languages\":");
324                tnode->language = string_resub("\"name\":\"", "\"", tmpstr2, 0);
325                free(tmpstr2), tmpstr2 = NULL;
326
327                tnode->type = string_resub("\"adult\":", ",", tmpstr, 0);
328                tnode->orgname = getxmlentry(tmpstr, "\"original_title\":");
329                tnode->score = string_resub("\"popularity\":", ",", tmpstr, 0);
330                tnode->rating = string_resub("\"vote_average\":", ",", tmpstr, 0);
331                tnode->votes = string_resub("\"vote_count\":", "}", tmpstr, 0);
332                tnode->released = getxmlentry(tmpstr, "\"release_date\":");
333                tnode->runtime = string_resub("\"runtime\":", ",", tmpstr, 0);
334                tnode->plot = getxmlentry(tmpstr, "\"overview\":");
335                tnode->year = getxmlentry(tmpstr, "\"Year\":");
336
337                tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":");
338                tnode->thumb = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w300", tmpstr2, 0, 0);
339                free(tmpstr2), tmpstr2 = NULL;
340
341                tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":");
342                tnode->cover = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w300", tmpstr2, 0, 0);
343                free(tmpstr2), tmpstr2 = NULL;
344
345                tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":");
346                tnode->postermid = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500", tmpstr2, 0, 0);
347                free(tmpstr2), tmpstr2 = NULL;
348                       
349                tnode->year = getxmlentry(tmpstr, "\"release_date\":");
350                tnode->imdbid = getxmlentry(tmpstr, "\"imdb_id\":");
351                tnode->id = string_resub(",\"id\":", ",", tmpstr, 0);
352
353                if(getconfigint("mediadbdebug", NULL) == 1 && tnode->backdrop == NULL)
354                {
355                        log = ostrcat(logdir, "/tmdb_", 0, 0);
356                        if(tnode->imdbid != NULL)
357                                log = ostrcat(log, tnode->imdbid, 1, 0);
358                        else
359                                log = ostrcat(log, timen, 1, 0);
360                       
361                        log = ostrcat(log, "_html", 1, 0);
362                        writesys(log, tmpstr1, 1);
363                        free(log), log = NULL;
364                       
365                        log = ostrcat(logdir, "/tmdb_", 0, 0);
366                        if(tnode->imdbid != NULL)
367                                log = ostrcat(log, tnode->imdbid, 1, 0);
368                        else
369                                log = ostrcat(log, timen, 1, 0);
370
371                        log = ostrcat(log, "_link", 1, 0);
372                        writesys(log, tnode->backdrop, 1);
373                        free(log), log = NULL;
374                }
375                       
376                if((flag1 == 0 && count == 1) || flag1 == 1 || flag1 == 2)
377                {
378                        savefile = savetmdbpic(tnode->imdbid, tnode->thumb, TMPTMDBPIC1, "_thumb.jpg", flag1);
379                        free(tnode->thumb);
380                        tnode->thumb = savefile;
381
382                        savefile = savetmdbpic(tnode->imdbid, tnode->cover, TMPTMDBPIC2, "_cover.jpg", flag1);
383                        free(tnode->cover);
384                        tnode->cover = savefile;
385
386                        savefile = savetmdbpic(tnode->imdbid, tnode->postermid, TMPTMDBPIC3, "_postermid.jpg", flag1);
387                        posterurl = ostrcat(posterurl, tnode->postermid, 1, 0);
388                        free(tnode->postermid);
389                        tnode->postermid = savefile;
390
391                        if(mvicount == 0)
392                        {
393                                savefile = savetmdbpic(tnode->imdbid, tnode->backdrop, TMPTMDBPIC4, "_backdrop1.jpg", flag1);
394                                free(tnode->backdrop);
395                                tnode->backdrop = savefile;                                     
396                        }
397                }
398                                       
399                if((flag1 == 1 || flag1 == 2) && tnode->backdrop != NULL && tnode->imdbid != NULL)
400                {
401                        debug(133, "load backdrop flag1: %d", flag1);
402                        char* tmppath = NULL;
403                        mvicount = 0;
404                        char* tmpstr2 = NULL;
405                        tmpstr2 = ostrcat(tnode->backdrop, NULL, 0, 0);
406                        struct splitstr* ret1 = NULL;
407                        int rcount = 0;
408                        int i = 0;
409                        ret1 = strsplit(tmpstr2, "\n", &rcount);
410
411                        for(i = 0; i < rcount; i++)
412                        {
413                                mvicount++;
414                                debug(133, "load %s\n",(&ret1[i])->part);
415
416                                if(!ostrncmp("http://", (&ret1[i])->part, 7))
417                                {
418                                        tmppath = ostrcat("_backdrop", oitoa(mvicount), 0, 1);
419                                        tmppath = ostrcat(tmppath, ".jpg", 1, 0);
420
421                                        savefile = savetmdbpic(tnode->imdbid, (&ret1[i])->part, TMPTMDBPIC4, tmppath, flag1);
422                                        if(file_exist(savefile))
423                                        {
424                                                free(tnode->backdrop);
425                                                tnode->backdrop = savefile;
426
427                                                free(tnode->mvi);
428                                                tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
429                                                tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0);
430                                                tnode->mvi = ostrcat(tnode->mvi, "_backdrop", 1, 0);
431                                                tnode->mvi = ostrcat(tnode->mvi, oitoa(mvicount), 1, 1);
432                                                tnode->mvi = ostrcat(tnode->mvi, ".mvi", 1, 0);
433                                               
434                                                if((!file_exist(tnode->mvi)) || (flag1 == 2))
435                                                {
436                                                        off64_t filesize = getfilesize(tnode->backdrop);
437                                                        debug(133, "filesize %lld", filesize);
438                                                       
439                                                        if(filesize < 1500000)
440                                                        {
441                                                                char* cmd = NULL;
442                                                                cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0);
443                                                                cmd = ostrcat(cmd, tnode->backdrop, 1, 0);
444                                                                cmd = ostrcat(cmd, " > ", 1, 0);
445                                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
446                                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
447                               
448                                                                debug(133, "cmd %s", cmd);
449                                                                system(cmd);
450                                                                free(cmd); cmd = NULL;
451
452                                                                cmd = ostrcat(cmd, "cat ", 1, 0);
453                                                                cmd = ostrcat(cmd, tmpmeta, 1, 0);
454                                                                cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0);
455                                                                char* size = string_newline(command(cmd));
456                                                                free(cmd), cmd = NULL; 
457                                                                debug(133, "size %s", size);
458                                                                if(size != NULL)
459                                                                {
460                                                                        debug(133, "size %d", atoi(size));
461                                                                        int picsize = atoi(size);
462                                                                        unlink(tmpmeta);
463
464                                                                        if(picsize < 2000)
465                                                                        {
466                                                                                debug(133, "size ok %d", picsize);
467                                                                                cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0);
468                                                                                cmd = ostrcat(cmd, tmpjpg, 1, 0);
469                                                                                cmd = ostrcat(cmd, " -copy none ", 1, 0);
470                                                                                cmd = ostrcat(cmd, tnode->backdrop, 1, 0);
471                                                                                                               
472                                                                                debug(133, "cmd %s", cmd);
473                                                                                system(cmd);
474                                                                                free(cmd); cmd = NULL;
475                                                                                if(file_exist(tmpjpg))
476                                                                                {
477                                                                                        free(cmd), cmd = NULL;
478                                                                                        cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0);
479                                                                                        cmd = ostrcat(cmd, tmpjpg, 1, 0);
480                                                                                        cmd = ostrcat(cmd, " ", 1, 0);
481                                                                                        cmd = ostrcat(cmd, tmpmpg, 1, 0);
482
483                                                                                        if(getconfigint("mediadbdebug", NULL) == 1)
484                                                                                        {
485                                                                                                filedebug(logfile, "#############\nbackdrop: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
486                                                                                                cmd = ostrcat(cmd, " >> ", 1, 0);
487                                                                                                cmd = ostrcat(cmd, logfile, 1, 0);
488                                                                                                cmd = ostrcat(cmd, " 2>&1", 1, 0);
489                                                                                        }
490                                                                                        else
491                                                                                        {
492                                                                                                cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0);
493                                                                                        }
494                                                                                        debug(133, "cmd %s", cmd);
495                                                                                        system(cmd);
496                                                                                        free(cmd); cmd = NULL;
497                                                                                       
498                                                                                        if(file_exist(tmpmpg))
499                                                                                        {
500                                                                                                cmd = ostrcat(cmd, "mv -f ", 1, 0);
501                                                                                                cmd = ostrcat(cmd, tmpmpg, 1, 0);
502                                                                                                cmd = ostrcat(cmd, " ", 1, 0);
503                                                                                                cmd = ostrcat(cmd, tnode->mvi, 1, 0);
504                                                                                                debug(133, "cmd %s", cmd);
505                                                                                                system(cmd);
506                                                                                                free(cmd); cmd = NULL;
507                                                                                               
508                                                                                                if(getconfigint("mediadbdebug", NULL) == 1)
509                                                                                                        writesysint("/proc/sys/vm/drop_caches", 3, 0);
510                                                                                               
511                                                                                                if(mvicount == getconfigint("mediadbbackdrop", NULL))
512                                                                                                        break;
513                                                                                        }
514                                                                                        else
515                                                                                                mvicount--;
516                                                                                }
517                                                                        }
518                                                                        else
519                                                                        {
520                                                                                debug(133, "ERROR Backdrop size to big skipped %d", picsize);
521
522                                                                                if(getconfigint("mediadbdebug", NULL) == 1)
523                                                                                        filedebug(logfile, "#############\nERROR Backdrop size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
524                                                                                mvicount--;
525                                                                        }
526                                                                }
527                                                                else
528                                                                {
529                                                                        debug(133, "ERROR Backdrop size is NULL skipped %s", size);
530
531                                                                        if(getconfigint("mediadbdebug", NULL) == 1)
532                                                                                filedebug(logfile, "#############\nERROR Backdrop size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part);
533
534                                                                        mvicount--;
535                                                                }
536                                                                free(size), size = NULL;
537                                                                unlink(tmpmeta);
538                                                                unlink(tmpjpg);
539                                                                unlink(tmpmpg);
540                                                        }
541                                                        else
542                                                        {
543                                                                debug(133, "ERROR Backdrop filesize to BIG skipped %lld", filesize);
544               
545                                                                if(getconfigint("mediadbdebug", NULL) == 1)
546                                                                        filedebug(logfile, "#############\nERROR Backdrop filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->backdrop, filesize, (&ret1[i])->part);
547                                                        }
548                                                }                                                               
549
550                                                free(tmppath), tmppath = NULL;
551                                        }
552                                        else
553                                                mvicount--;
554                                }
555                                else
556                                {
557                                        log = ostrcat(logdir, "/tmdb_", 0, 0);
558                                        if(tnode->imdbid != NULL)
559                                                log = ostrcat(log, tnode->imdbid, 1, 0);
560                                        else
561                                                log = ostrcat(log, timen, 1, 0);
562                                       
563                                        log = ostrcat(log, "_html", 1, 0);
564                                       
565                                        char* cmd = NULL;
566                                        cmd = command("free");
567                                        log = ostrcat(log, "_error_link", 1, 0);
568                                        cmd = ostrcat(cmd, "\nlink: ", 1, 0);
569                                        cmd = ostrcat(cmd, (&ret1[i])->part, 1, 0);
570                                        writesys(log, cmd, 1);
571                                        free(cmd), cmd = NULL;
572                                        free(log), log = NULL;
573                                        mvicount--;
574                                }
575
576                                if(file_exist(tnode->mvi))
577                                        unlink(tnode->backdrop);
578                        }
579                        free(ret1), ret1 = NULL;                               
580                        free(tmpstr2), tmpstr2 = NULL;
581                }
582                else if((flag1 == 1 || flag1 == 2) && tnode->postermid != NULL && tnode->imdbid != NULL)
583                {
584                        debug(133, "load postermid flag1: %d", flag1);
585
586                        free(tnode->mvi);
587                        tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0);
588                        tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0);
589                        tnode->mvi = ostrcat(tnode->mvi, "_backdrop1.mvi", 1, 0);
590                       
591                        if((!file_exist(tnode->mvi)) || (flag1 == 2))
592                        {
593
594                                off64_t filesize = getfilesize(tnode->backdrop);
595                                debug(133, "filesize %lld", filesize);
596                               
597                                if(filesize < 1500000)
598                                {
599                                        char* cmd = NULL;
600                                        cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0);
601                                        cmd = ostrcat(cmd, tnode->postermid, 1, 0);
602                                        cmd = ostrcat(cmd, " > ", 1, 0);
603                                        cmd = ostrcat(cmd, tmpmeta, 1, 0);
604                                        cmd = ostrcat(cmd, " 2>&1", 1, 0);
605       
606                                        debug(133, "cmd %s", cmd);
607                                        system(cmd);
608                                        free(cmd); cmd = NULL;
609
610                                        cmd = ostrcat(cmd, "cat ", 1, 0);
611                                        cmd = ostrcat(cmd, tmpmeta, 1, 0);
612                                        cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0);
613                                        char* size = string_newline(command(cmd));
614                                        free(cmd), cmd = NULL;
615                                        debug(133, "size %s", size);
616                                        if(size != NULL)
617                                        {
618                                                debug(133, "size %d", atoi(size));
619                                                int picsize = atoi(size);
620       
621                                                if(picsize < 2000)
622                                                {
623                                                        debug(133, "size ok %d", picsize);
624                                                        cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0);
625                                                        cmd = ostrcat(cmd, tmpjpg, 1, 0);
626                                                        cmd = ostrcat(cmd, " -copy none ", 1, 0);
627                                                        cmd = ostrcat(cmd, tnode->postermid, 1, 0);
628                       
629                                                        debug(133, "cmd %s", cmd);
630                                                        system(cmd);
631                                                        free(cmd); cmd = NULL;
632                                                                                       
633                                                        if(file_exist(tmpjpg))
634                                                        {
635                                                                free(cmd), cmd = NULL;
636                                                                cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0);
637                                                                cmd = ostrcat(cmd, tmpjpg, 1, 0);
638                                                                cmd = ostrcat(cmd, " ", 1, 0);
639                                                                cmd = ostrcat(cmd, tmpmpg, 1, 0);
640
641                                                                if(getconfigint("mediadbdebug", NULL) == 1)
642                                                                {
643                                                                        filedebug(logfile, "#############\npostermid: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);   
644                                                                        cmd = ostrcat(cmd, " >> ", 1, 0);
645                                                                        cmd = ostrcat(cmd, logfile, 1, 0);
646                                                                        cmd = ostrcat(cmd, " 2>&1", 1, 0);
647                                                                }
648                                                                else
649                                                                {
650                                                                        cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0);
651                                                                }
652
653                                                                debug(133, "cmd %s", cmd);
654                                                                system(cmd);
655                                                                free(cmd); cmd = NULL;
656                                                                if(file_exist(tmpmpg))
657                                                                {                                       
658                                                                        cmd = ostrcat(cmd, "mv -f ", 1, 0);
659                                                                        cmd = ostrcat(cmd, tmpmpg, 1, 0);
660                                                                        cmd = ostrcat(cmd, " ", 1, 0);
661                                                                        cmd = ostrcat(cmd, tnode->mvi, 1, 0);
662                                                                        debug(133, "cmd %s", cmd);
663                                                                        system(cmd);
664                                                                        free(cmd); cmd = NULL;
665                                                                       
666                                                                        writesysint("/proc/sys/vm/drop_caches", 3, 0);
667                                                                }
668                                                        }
669                                                        free(cmd), cmd = NULL;
670                                                }
671                                                else
672                                                {
673                                                        debug(133, "ERROR Postermid size to big skipped %d", picsize);
674
675                                                        if(getconfigint("mediadbdebug", NULL) == 1)
676                                                                filedebug(logfile, "#############\nERROR Postermid size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);
677                                                }
678                                        }
679                                        else
680                                        {
681                                                debug(133, "ERROR Postermid size is NULL skipped %s", size);
682
683                                                if(getconfigint("mediadbdebug", NULL) == 1)
684                                                        filedebug(logfile, "#############\nERROR Postermid size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);
685                                        }
686                                        free(size), size = NULL;
687                                        unlink(tmpmeta);
688                                        unlink(tmpjpg);
689                                        unlink(tmpmpg);
690                                }
691                                else
692                                {
693                                        debug(133, "ERROR Postermid filesize to BIG skipped %lld", filesize);
694
695                                        if(getconfigint("mediadbdebug", NULL) == 1)
696                                                filedebug(logfile, "#############\nERROR Postermid filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->postermid, filesize, posterurl);     
697                                }
698                        }
699                }
700
701
702                debug(133, "mvi=%s (mvicount=%d)", tnode->mvi,flag1);
703                debug(133, "backdrop=%s (mvicount=%d)", tnode->backdrop,flag1);
704
705                if(file_exist(tnode->mvi))
706                        unlink(tnode->backdrop);
707
708                if(mvicount > 0)
709                {
710                        free(tnode->mvi);
711                        tnode->mvi = ostrcat(oitoa(mvicount), NULL, 1, 0);
712                }
713                else
714                {
715                        free(tnode->mvi);
716                        tnode->mvi = ostrcat("1", NULL, 0, 0);
717                }
718                debug(133, "change mvi=%s (mvicount=%d)", tnode->mvi,flag1);
719                       
720                free(tmpstr); tmpstr = NULL;
721
722                debug(133, "----------------------tmdb start----------------------");
723                debug(133, "title: %s", tnode->title);
724                debug(133, "language: %s", tnode->language);
725                debug(133, "type: %s", tnode->type);
726                debug(133, "orgname: %s", tnode->orgname);
727                debug(133, "score: %s", tnode->score);
728                debug(133, "rating: %s", tnode->rating);
729                debug(133, "released: %s", tnode->released);
730                debug(133, "genre: %s", tnode->genre);
731                debug(133, "runtime: %s", tnode->runtime);
732                debug(133, "plot: %s", tnode->plot);
733                debug(133, "thumb: %s", tnode->thumb);
734                debug(133, "cover: %s", tnode->cover);
735                debug(133, "postermid: %s", tnode->postermid);
736                debug(133, "backdrop: %s", tnode->backdrop);
737                debug(133, "mvi: %s", tnode->mvi);
738                debug(133, "rating: %s", tnode->rating);
739                debug(133, "votes: %s", tnode->votes);
740                debug(133, "id: %s", tnode->id);       
741                debug(133, "imdbid: %s", tnode->imdbid);
742                debug(133, "----------------------tmdb end----------------------");
743        }
744
745        return *first;
746}
747
748//flag 0: only view
749//flag 1: can return tmdb node
750struct tmdb* screentmdb(char* title, char* skinname, int flag, char* path, char* file)
751{
752        debug(133, "title: %s",title);
753        debug(133, "path: %s",path);
754        debug(133, "file: %s",file);   
755        char* searchstr = NULL, *tmpstr = NULL;
756
757        if(checkinternet() == 1)
758        {
759                textbox(_("Message"), _("Error, Internet Connection not found"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1100, 500, 10, 0);
760                return NULL;
761        }
762
763        int rcret = 0;
764        struct skin* tmdbskin = NULL;
765
766        if(skinname != NULL)
767                tmdbskin = getscreen(skinname);
768        else
769                tmdbskin = getscreen("tmdb");
770
771        struct skin* skin_plot = getscreennode(tmdbskin, "plot");
772        struct skin* skin_title = getscreennode(tmdbskin, "title");
773        struct skin* skin_orgname = getscreennode(tmdbskin, "orgname");
774        struct skin* skin_rating = getscreennode(tmdbskin, "rating");
775        struct skin* skin_genre = getscreennode(tmdbskin, "genre");
776        struct skin* skin_released = getscreennode(tmdbskin, "released");
777        struct skin* skin_cover = getscreennode(tmdbskin, "cover");
778        struct skin* skin_votes = getscreennode(tmdbskin, "votes");
779        struct skin* skin_b3 = getscreennode(tmdbskin, "b3");
780        struct skin* load = getscreen("loading");
781        struct skin* blackscreen = getscreen("blackscreen");
782       
783        struct tmdb* node = NULL, *retnode = NULL;
784        char* search = NULL;
785
786//      setfbtransparent(255);
787        status.hangtime = 99999;
788
789//      if(flag == 0)
790//              skin_b3->hidden = YES;
791//      else
792//              skin_b3->hidden = NO;
793
794        if(path == NULL || file == NULL || !file_exist(getconfig("mediadbpath", NULL)))
795                skin_b3->hidden = YES;
796        else
797                skin_b3->hidden = NO;
798                               
799        if(title == NULL)
800                searchstr = getepgakttitle(NULL);
801        else
802        {
803                int isrec = 0, iscam = 0;
804                tmpstr = createshortname(file, &isrec, &iscam, 1);
805                if(tmpstr != NULL)
806                        searchstr = ostrcat(searchstr, tmpstr, 1, 0);
807                else
808                        searchstr = ostrcat(searchstr, title, 1, 0);
809        }
810
811        debug(133, "searchstr: %s",searchstr);
812
813        drawscreen(blackscreen, 0, 0);
814        drawscreen(load, 0, 0);
815
816        node = gettmdb(&node, searchstr, 0, 0);
817        clearscreen(load);
818        clearscreen(blackscreen);
819
820start:
821        if(node != NULL)
822        {
823                changetext(skin_plot, node->plot);
824                changetext(skin_title, node->title);
825                changetext(skin_orgname, node->orgname);
826                changetext(skin_rating, node->rating);
827                changetext(skin_genre, node->genre);
828                changetext(skin_released, node->released);
829                char* tmpstr = NULL;
830                tmpstr = ostrcat("( ", node->votes, 0, 0);
831                tmpstr = ostrcat(tmpstr, " votes)", 1, 0);             
832                changetext(skin_votes, tmpstr);
833                free(tmpstr), tmpstr = NULL;
834                changepic(skin_cover, TMPTMDBPIC3);
835                skin_cover->hidden = NO;
836        }
837        else
838        {
839                changetext(skin_plot, "--plot--");
840                changetext(skin_title, "--title--");
841                changetext(skin_orgname, "--orgname--");
842                changetext(skin_rating, "--rating--");
843                changetext(skin_genre, "--genre--");
844                changetext(skin_released, "--releasetime--");
845                changetext(skin_votes, "( --votes-- )");               
846                skin_cover->hidden = YES;
847        }
848
849        drawscreen(tmdbskin, 0, 0);
850
851        while(1)
852        {
853                rcret = waitrc(tmdbskin, 0, 0);
854       
855                if(rcret == getrcconfigint("rcexit", NULL)) break;
856                if(rcret == getrcconfigint("rcok", NULL)) break;
857
858                if(rcret == getrcconfigint("rcred", NULL))
859                {
860                        search = textinput("Search", searchstr);
861                        if(search != NULL)
862                        {
863                                freetmdb(&node, 0), node = NULL;
864                                drawscreen(blackscreen, 0, 0);
865                                drawscreen(load, 0, 0);
866                                node = gettmdb(&node, search, 0, 0);
867                                clearscreen(load);
868                                clearscreen(blackscreen);
869                                free(search), search = NULL;
870                                goto start;
871                        }
872                        drawscreen(tmdbskin, 0, 0);
873                        continue;
874                }
875                if(rcret == getrcconfigint("rcgreen", NULL))
876                {
877                        struct tmdb* tnode = node;
878                        struct menulist* mlist = NULL, *mbox = NULL;
879
880                        while(tnode != NULL)
881                        {
882                                addmenulist(&mlist, tnode->title, tnode->imdbid, NULL, 0, 0);
883                                tnode = tnode->next;
884                        }
885
886                        mbox = menulistbox(mlist, NULL, NULL, NULL, NULL, 0, 0);
887                        if(mbox != NULL)
888                        {
889                                search = ostrcat(mbox->text, NULL, 0, 0);
890                                if(search != NULL)
891                                {
892                                        freetmdb(&node, 0); node = NULL;
893                                        drawscreen(blackscreen, 0, 0);
894                                        drawscreen(load, 0, 0);
895                                        node = gettmdb(&node, search, 1, 0);
896                                        clearscreen(load);
897                                        clearscreen(blackscreen);
898                                        free(search), search = NULL;
899                                        freemenulist(mlist, 1); mlist = NULL, mbox = NULL;
900                                        goto start;
901                                }
902                        }
903                        freemenulist(mlist, 1); mlist = NULL, mbox = NULL;
904                        drawscreen(tmdbskin, 0, 0);
905                        continue;
906                }
907                if(rcret == getrcconfigint("rcyellow", NULL) && flag == 1)
908                {
909                        retnode = node;
910                        break;
911                }
912
913                if(rcret == getrcconfigint("rcyellow", NULL) && path != NULL && file != NULL && node != NULL && node->imdbid != NULL && flag == 2)
914                {
915                        drawscreen(blackscreen, 0, 0);
916                        drawscreen(load, 0, 0);
917                        debug(133, "path: %s",path);
918                        debug(133, "file: %s",file);
919                        debug(133, "type: 2");
920                        debug(133, "node->imdbid: %s",node->imdbid);
921                        if(ostrncmp("tt", node->imdbid, 2))
922                                textbox(_("Message"), _("Error, found result without imdbid we can't this save in MediaDB"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 10, 0);
923                        else
924                        {
925                                addconfigtmp("mediadbscantimeout", "0");
926                                mediadbfindfilecb(path, file, 0, node->imdbid, 2);
927                                delconfigtmp("mediadbscantimeout");                     
928                        }
929                        clearscreen(load);
930                        clearscreen(blackscreen);
931                        break;
932                }
933        }
934
935        if(retnode == NULL)
936        {
937                freetmdb(&node, 0);
938                node = NULL;
939        }
940
941        free(searchstr), searchstr = NULL;
942//      setosdtransparent(getskinconfigint("osdtransparent", NULL));
943        status.hangtime = getconfigint("hangtime", NULL);
944        clearscreen(tmdbskin);
945
946        return retnode;
947}
948
949#endif
Note: See TracBrowser for help on using the repository browser.