source: titan/plugins/tithek/tithek.h @ 19884

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

[titan] update download stuff step1

File size: 45.4 KB
Line 
1#ifndef TITHEK_H
2#define TITHEK_H
3
4#define TITHEKPATH "/tmp/tithek"
5int tithekdownloadrun = 0;
6int tithekdownloadcount = 0;
7int tithekrun = 0;
8int tithekexit = 0;
9
10//flag 0        - menu
11//flag 1        - menu pay hidden tithek_pay=0/1 0=hidden
12//flag 2        - http (default streamurl)
13//flag 4        - youtube
14//flag 5        - rtl2now
15//flag 6        - superrtlnow
16//flag 7        - rtlnow
17//flag 8        - voxnow
18//flag 9        - youtube suche 10
19//flag 10       - youtube suche 25
20//flag 11       - youtube suche 50
21//flag 12       - myvideo
22//flag 13       - myvideo search 50
23//flag 14       - kinox putlocker/sockshare
24//flag 15       - kinox filenuke
25//flag 16       - superrtlnow pay
26//flag 17       - rtlnow pay
27//flag 18       - voxnow pay
28//flag 19       - rtl2now pay
29//flag 20       - kinox StreamCloud
30//flag 21       - kinox search
31//flag 22       - kinox hoster
32//flag 23       - kinox hoster serie
33//flag 24       - kinox flashx
34//flag 25       - kinox vidstream
35//flag 26       - kinox xvidstage
36//flag 27       - kinox nowvideo
37//flag 50       - beeg
38//flag 66   - coming soon dummy
39//flag 1000 - menu pincode
40//flag 9999 - menu hidden codecpack
41
42struct tithek
43{
44        char* title;
45        char* link;
46        char* pic;
47        char* localname;
48        char* menutitle;       
49        int flag;
50        struct tithek* prev;
51        struct tithek* next;
52};
53struct tithek *tithek = NULL;
54
55
56void freetithekcontent(struct tithek* node)
57{
58        if(node == NULL) return;
59
60        free(node->title); node->title = NULL;
61        node->link = NULL;
62        node->pic = NULL;
63        node->localname = NULL;
64        node->menutitle = NULL;
65        node->flag = 0;
66}
67
68int addtithekcontent(struct tithek* node, char *line, int len, int count, int pay)
69{
70        int ret = 0, i = 0, skip = 0;
71        char* tmpstr = NULL, *flag = NULL, *cmd = NULL;
72
73        if(node == NULL) return 1;
74
75        if(len > 0) tmpstr = malloc(len + 1);
76        if(tmpstr != NULL)
77        {
78                memcpy(tmpstr, line, len);
79                tmpstr[len] = '\0';
80
81                node->title = tmpstr;
82
83                while(tmpstr[0] != '\0')
84                {
85                        if(tmpstr[0] == '#')
86                        {
87                                tmpstr[0] = '\0';
88                                tmpstr++;
89                                switch(ret)
90                                {
91                                        case 0: node->link = tmpstr; break;
92                                        case 1: node->pic = tmpstr; break;
93                                        case 2: node->localname = tmpstr; break;
94                                        case 3: node->menutitle = tmpstr; break;
95                                        case 4: flag = tmpstr; break;
96                                }
97
98                                ret++;
99                        }
100                        else
101                                tmpstr++;
102                }
103        }
104
105        if(ret != 5)
106        {
107                if(count > 0)
108                {
109                        err("tithek line %d not ok (ret=%d)", count, ret);
110                }
111                else
112                {
113                        err("add tithek (ret=%d)", ret);
114                }
115                freetithekcontent(node);
116                return 1;
117        }
118
119        if(flag != NULL) node->flag = atoi(flag);
120
121        if(node->flag == 9999 && !file_exist("/var/swap/etc/.codecpack"))
122                skip = 1;
123        else if(node->flag == 16 && pay == 0)
124                skip = 1;
125        else if(node->flag == 17 && pay == 0)
126                skip = 1;
127        else if(node->flag == 18 && pay == 0)
128                skip = 1;
129        else if(node->flag == 19 && pay == 0)
130                skip = 1;
131        else if(node->flag == 1 && pay == 0)
132                skip = 1;
133        else if(node->flag == 9999)
134        {
135                char* tmp = NULL;
136
137                //cmd = ostrcat(cmd, "wget -s http://", 1, 0);
138                cmd = ostrcat(cmd, "kin", 1, 0);
139                cmd = ostrcat(cmd, "ox", 1, 0);
140                cmd = ostrcat(cmd, ".", 1, 0);
141                cmd = ostrcat(cmd, "to", 1, 0);
142
143                //if(system(cmd) != 0)
144                for(i = 0; i < 3; i++)
145                {
146                        free(tmp); tmp = NULL;
147                        tmp = gethttp(cmd, "/", 80, NULL, NULL, 10000, NULL, 0);
148                        if(tmp != NULL) break;
149                }
150                if(tmp == NULL)
151                        skip = 1;
152
153                free(tmp); tmp = NULL;
154                free(cmd), cmd = NULL;
155        }
156
157        if(skip == 1)
158        {
159                freetithekcontent(node);
160                return 1;
161        }
162
163        return 0;
164}
165
166struct tithek* addtithek(char *line, int len, int count, struct tithek* last, int pay)
167{
168        //debug(1000, "in");
169        struct tithek *newnode = NULL, *prev = NULL, *node = NULL;
170        int ret = 0;
171
172        if(line == NULL) return NULL;
173
174        newnode = (struct tithek*)calloc(1, sizeof(struct tithek));
175        if(newnode == NULL)
176        {
177                err("no memory");
178                return NULL;
179        }
180
181        ret = addtithekcontent(newnode, line, len, count, pay);
182        if(ret == 1)
183        {
184                free(newnode);
185                return NULL;
186        }
187
188        node = tithek;
189
190        if(last == NULL)
191        {
192                while(node != NULL)
193                {
194                        prev = node;
195                        node = node->next;
196                }
197        }
198        else
199        {
200                prev = last;
201                node = last->next;
202        }
203
204        if(prev == NULL)
205                tithek = newnode;
206        else
207        {
208                prev->next = newnode;
209                newnode->prev = prev;
210        }
211        newnode->next = node;
212        if(node != NULL) node->prev = newnode;
213
214        //debug(1000, "out");
215        return newnode;
216}
217
218struct tithek* createtithek(struct tithek* update, char* title, char* link, char* pic, char* localname, char* menutitle, int flag)
219{
220        int pay = 0;
221        struct tithek* tnode = NULL;
222        char* tmpstr = NULL;
223       
224        pay = getconfigint("tithek_pay", NULL);
225
226        title = stringreplacechar(title, '#', ' ');
227        link = stringreplacechar(link, '#', ' ');
228        pic = stringreplacechar(pic, '#', ' ');
229        localname = stringreplacechar(localname, '#', ' ');
230        menutitle = stringreplacechar(menutitle, '#', ' ');
231       
232        tmpstr = ostrcat(tmpstr, title, 1, 0);
233        tmpstr = ostrcat(tmpstr, "#", 1, 0);
234        tmpstr = ostrcat(tmpstr, link, 1, 0);
235        tmpstr = ostrcat(tmpstr, "#", 1, 0);
236        tmpstr = ostrcat(tmpstr, pic, 1, 0);
237        tmpstr = ostrcat(tmpstr, "#", 1, 0);
238        tmpstr = ostrcat(tmpstr, localname, 1, 0);
239        tmpstr = ostrcat(tmpstr, "#", 1, 0);
240        tmpstr = ostrcat(tmpstr, menutitle, 1, 0);
241        tmpstr = ostrcat(tmpstr, "#", 1, 0);
242        tmpstr = ostrcat(tmpstr, oitoa(flag), 1, 1);
243
244        tmpstr = string_replace_all("\n", "", tmpstr, 1);
245        tmpstr = string_replace_all("\r", "", tmpstr, 1);
246
247        if(update != NULL)
248        {
249                freetithekcontent(update);
250                addtithekcontent(update, tmpstr, strlen(tmpstr), 1, pay);
251                tnode = update;
252        }
253        else
254                tnode = addtithek(tmpstr, strlen(tmpstr), 1, NULL, pay);
255
256        free(tmpstr);
257
258        return tnode;
259}
260
261/*
262struct tithek* addtithek(char *line, int count, struct tithek* last)
263{
264        //debug(1000, "in");
265        struct tithek *newnode = NULL, *prev = NULL, *node = tithek;
266        char *link = NULL, *pic = NULL, *title = NULL, *localname = NULL, *menutitle = NULL, *cmd = NULL;
267        int ret = 0, skip = 0, i = 0;
268
269        if(line == NULL) return NULL;
270
271        newnode = (struct tithek*)calloc(1, sizeof(struct tithek));
272        if(newnode == NULL)
273        {
274                err("no memory");
275                return NULL;
276        }
277
278        link = malloc(MINMALLOC);
279        if(link == NULL)
280        {
281                err("no memory");
282                free(newnode);
283                return NULL;
284        }
285
286        pic = malloc(MINMALLOC);
287        if(pic == NULL)
288        {
289                err("no memory");
290                free(newnode);
291                free(link);
292                return NULL;
293        }
294
295        title = malloc(MINMALLOC);
296        if(title == NULL)
297        {
298                err("no memory");
299                free(newnode);
300                free(link);
301                free(pic);
302                return NULL;
303        }
304
305        localname = malloc(MINMALLOC);
306        if(localname == NULL)
307        {
308                err("no memory");
309                free(newnode);
310                free(link);
311                free(pic);
312                free(title);
313                return NULL;
314        }
315
316        menutitle = malloc(MINMALLOC);
317        if(menutitle == NULL)
318        {
319                err("no memory");
320                free(newnode);
321                free(link);
322                free(pic);
323                free(title);
324                free(localname);               
325                return NULL;
326        }
327
328        int pay = getconfigint("tithek_pay", NULL);
329
330        ret = sscanf(line, "%[^#]#%[^#]#%[^#]#%[^#]#%[^#]#%d", title, link, pic, localname, menutitle, &newnode->flag);
331                               
332        if(newnode->flag == 9999 && !file_exist("/var/swap/etc/.codecpack"))
333                skip = 1;
334        else if(newnode->flag == 16 && pay == 0)
335                skip = 1;
336        else if(newnode->flag == 17 && pay == 0)
337                skip = 1;
338        else if(newnode->flag == 18 && pay == 0)
339                skip = 1;
340        else if(newnode->flag == 19 && pay == 0)
341                skip = 1;
342        else if(newnode->flag == 1 && pay == 0)
343                skip = 1;
344        else if(newnode->flag == 9999)
345        {
346                char* tmp = NULL;
347
348                //cmd = ostrcat(cmd, "wget -s http://", 1, 0);
349                cmd = ostrcat(cmd, "kin", 1, 0);
350                cmd = ostrcat(cmd, "ox", 1, 0);
351                cmd = ostrcat(cmd, ".", 1, 0);
352                cmd = ostrcat(cmd, "to", 1, 0);
353
354                //if(system(cmd) != 0)
355                for(i = 0; i < 3; i++)
356                {
357                        free(tmp); tmp = NULL;
358                        tmp = gethttp(cmd, "/", 80, NULL, NULL, 10000, NULL, 0);
359                        if(tmp != NULL) break;
360                }
361                if(tmp == NULL)
362                        skip = 1;
363
364                free(tmp); tmp = NULL;
365                free(cmd), cmd = NULL;
366        }
367
368        if(skip == 1)
369        {
370                free(link);
371                free(pic);
372                free(title);
373                free(localname);
374                free(menutitle);
375                free(newnode);
376                return NULL;
377        }
378
379        if(ret != 6)
380        {
381                if(count > 0)
382                {
383                        err("tithek line %d not ok or double", count);
384                }
385                else
386                {
387                        err("add tithek");
388                }
389                free(link);
390                free(pic);
391                free(title);
392                free(localname);
393                free(menutitle);
394                free(newnode);
395                return NULL;
396        }
397
398        newnode->link = ostrshrink(link);
399        newnode->pic = ostrshrink(pic);
400        newnode->title = ostrshrink(title);
401        newnode->localname = ostrshrink(localname);
402        newnode->menutitle = ostrshrink(menutitle);
403
404        if(last == NULL)
405        {
406                while(node != NULL)
407                {
408                        prev = node;
409                        node = node->next;
410                }
411        }
412        else
413        {
414                prev = last;
415                node = last->next;
416        }
417
418        if(prev == NULL)
419                tithek = newnode;
420        else
421        {
422                prev->next = newnode;
423                newnode->prev = prev;
424        }
425        newnode->next = node;
426        if(node != NULL) node->prev = newnode;
427       
428        //debug(1000, "out");
429        return newnode;
430}
431*/
432
433int readtithek(const char* filename)
434{
435        debug(1000, "in");
436        FILE *fd = NULL;
437        char *fileline = NULL;
438        int linecount = 0, len = 0, pay = 0;
439        struct tithek* last = NULL, *tmplast = NULL;
440
441        fileline = malloc(MINMALLOC);
442        if(fileline == NULL)
443        {
444                err("no memory");
445                return 1;
446        }
447
448        fd = fopen(filename, "r");
449        if(fd == NULL)
450        {
451                perr("can't open %s", filename);
452                free(fileline);
453                return 1;
454        }
455
456        pay = getconfigint("tithek_pay", NULL);
457
458        while(fgets(fileline, MINMALLOC, fd) != NULL)
459        {
460                if(fileline[0] == '\n')
461                        continue;
462                len = strlen(fileline) - 1;
463                if(fileline[len] == '\n')
464                        fileline[len] = '\0';
465                if(fileline[len - 1] == '\r')
466                        fileline[len - 1] = '\0';
467
468                linecount++;
469
470                if(last == NULL) last = tmplast;
471                last = addtithek(fileline, len + 2, linecount, last, pay);
472                if(last != NULL) tmplast = last;
473        }
474
475        free(fileline);
476        fclose(fd);
477        return linecount;
478}
479
480/*
481int readtithek(const char* filename)
482{
483        debug(1000, "in");
484        FILE *fd = NULL;
485        char *fileline = NULL;
486        int linecount = 0;
487        struct tithek* last = NULL, *tmplast = NULL;
488
489        fileline = malloc(MINMALLOC);
490        if(fileline == NULL)
491        {
492                err("no memory");
493                return 0;
494        }
495
496        fd = fopen(filename, "r");
497        if(fd == NULL)
498        {
499                perr("can't open %s", filename);
500                free(fileline);
501                return 0;
502        }
503
504        while(fgets(fileline, MINMALLOC, fd) != NULL)
505        {
506                if(fileline[0] == '#' || fileline[0] == '\n')
507                        continue;
508                if(fileline[strlen(fileline) - 1] == '\n')
509                        fileline[strlen(fileline) - 1] = '\0';
510                if(fileline[strlen(fileline) - 1] == '\r')
511                        fileline[strlen(fileline) - 1] = '\0';
512
513                linecount++;
514
515                if(last == NULL) last = tmplast;
516                last = addtithek(fileline, linecount, last);
517                if(last != NULL) tmplast = last;
518        }
519
520        free(fileline);
521        fclose(fd);
522        return linecount;
523}
524*/
525
526int deltithek(char* link)
527{
528        debug(1000, "in");
529        int ret = 1;
530
531        struct tithek *node = tithek, *prev = tithek;
532
533        while(node != NULL)
534        {
535                if(ostrcmp(link, node->link) == 0)
536                {
537                        ret = 0;
538                        if(node == tithek)
539                        {
540                                tithek = node->next;
541                                if(tithek != NULL)
542                                        tithek->prev = NULL;
543                        }
544                        else
545                        {
546                                prev->next = node->next;
547                                if(node->next != NULL)
548                                        node->next->prev = prev;
549                        }
550
551                        freetithekcontent(node);
552
553                        free(node);
554                        node = NULL;
555
556                        break;
557                }
558
559                prev = node;
560                node = node->next;
561        }
562
563        debug(1000, "out");
564        return ret;
565}
566
567void freetithek()
568{
569        debug(1000, "in");
570        struct tithek *node = tithek, *prev = tithek;
571
572        while(node != NULL)
573        {
574                prev = node;
575                node = node->next;
576                if(prev != NULL)
577                        deltithek(prev->link);
578        }
579
580        debug(1000, "out");
581}
582
583/*
584int deltithek(char* link)
585{
586        debug(1000, "in");
587        int ret = 1;
588        struct tithek *node = tithek, *prev = tithek;
589
590        while(node != NULL)
591        {
592                if(ostrcmp(link, node->link) == 0)
593                {
594                        ret = 0;
595                        if(node == tithek)
596                        {
597                                tithek = node->next;
598                                if(tithek != NULL)
599                                        tithek->prev = NULL;
600                        }
601                        else
602                        {
603                                prev->next = node->next;
604                                if(node->next != NULL)
605                                        node->next->prev = prev;
606                        }
607
608                        free(node->link);
609                        node->link = NULL;
610
611                        free(node->pic);
612                        node->pic = NULL;
613
614                        free(node->title);
615                        node->title = NULL;
616
617                        free(node->localname);
618                        node->localname = NULL;
619
620                        free(node->menutitle);
621                        node->menutitle = NULL;
622
623                        free(node);
624                        node = NULL;
625
626                        break;
627                }
628
629                prev = node;
630                node = node->next;
631        }
632
633        debug(1000, "out");
634        return ret;
635}
636
637void freetithek()
638{
639        debug(1000, "in");
640        struct tithek *node = tithek, *prev = tithek;
641
642        while(node != NULL)
643        {
644                prev = node;
645                node = node->next;
646                if(prev != NULL)
647                        deltithek(prev->link);
648        }
649        debug(1000, "out");
650}
651*/
652
653void tithekdownloadthread(struct stimerthread* timernode, struct download* node, int flag)
654{
655        int defpic = 0;
656
657        tithekdownloadcount++;
658
659        if(node != NULL)
660        {
661                m_lock(&status.tithekmutex, 20);
662                if(file_exist(node->filename))
663                {
664                        m_unlock(&status.tithekmutex, 20);
665                        goto end;
666                }
667
668                FILE *fd; fd = fopen(node->filename, "w");
669                if(fd != NULL) fclose(fd);
670                m_unlock(&status.tithekmutex, 20);
671
672                gethttpreal(node->host, node->page, node->port, node->filename, node->auth, NULL, 0, NULL, NULL, node->timeout, 0);
673
674                if(tithekrun == 0)
675                        unlink(node->filename);
676                else
677                {
678                        //check file size
679                        off64_t checkpic = getfilesize(node->filename);
680                        if(checkpic < 1000) defpic = 1;
681
682                        //check file is gif or html
683                        if(defpic == 0)
684                        {
685                                char* tmp = NULL;
686                                tmp = readbintomem(node->filename, 3);
687                                if(ostrcmp("GIF", tmp) == 0) defpic = 1; //gif
688                                if(ostrcmp("<", tmp) == 0) defpic = 1; //html
689                                free(tmp); tmp = NULL;
690                        }
691
692                        if(defpic == 1)
693                        {
694                                m_lock(&status.tithekmutex, 20);
695                                unlink(node->filename);
696                                symlink("/var/usr/local/share/titan/plugins/tithek/default.jpg", node->filename);
697                                m_unlock(&status.tithekmutex, 20);
698                        }
699                }
700
701end:
702                free(node->host); node->host = NULL;
703                free(node->page); node->page = NULL;
704                free(node->filename); node->filename = NULL;
705                free(node->auth); node->auth = NULL;
706        }
707
708        free(node); node = NULL;
709
710        tithekdownloadcount--;
711        tithekdownloadrun = 1;
712}
713
714char* tithekdownload(char* link, char* localname, char* pw, int pic, int flag)
715{
716        int ret = 1, port = 80, timeout = 50000;
717        char* ip = NULL, *pos = NULL, *path = NULL;
718        char* tmpstr = NULL, *localfile = NULL;
719
720        if(link == NULL) return NULL;
721
722        ip = string_replace("http://", "", (char*)link, 0);
723
724        if(ip != NULL)
725                pos = strchr(ip, '/');
726        if(pos != NULL)
727        {
728                pos[0] = '\0';
729                path = pos + 1;
730        }
731
732        if(ostrstr(ip, ":") != NULL)
733        {
734                ip = oregex("http://(.*):.*", link);
735                port = atoi(oregex("http://.*:(.*)/.*", link));
736        }
737
738        tmpstr = ostrcat(path, NULL, 0, 0);
739
740        if(flag == 0)
741        {
742                localfile = ostrcat(TITHEKPATH, "/", 0, 0);
743                if(localname == NULL)
744                        localfile = ostrcat(localfile, basename(tmpstr), 1, 0);
745                else
746                        localfile = ostrcat(localfile, localname, 1, 0);
747        }
748        else
749        {
750                localfile = ostrcat(getconfig("rec_streampath", NULL), "/", 0, 0);
751                if(localname == NULL)
752                        localfile = ostrcat(localfile, basename(tmpstr), 1, 0);
753                else
754                        localfile = ostrcat(localfile, localname, 1, 0);
755        }
756
757        debug(99, "---------------------------------------");
758        debug(99, "link: %s", link);
759        debug(99, "localname: %s", localname);
760        debug(99, "---------------------------------------");
761        debug(99, "ip: %s", ip);
762        debug(99, "port: %d", port);
763        debug(99, "path: %s", path);
764        debug(99, "localfile: %s", localfile);
765        debug(99, "pw: %s", pw);
766        debug(99, "---------------------------------------");
767
768        if(flag == 0)
769        {
770                if(localfile != NULL && !file_exist(localfile))
771                {
772                        if(pic == 1)
773                        {
774                                if(tithekdownloadcount >= 24) //start max 24 threads
775                                        gethttp(ip, path, port, localfile, pw, timeout, NULL, 0);
776                                else
777                                {
778                                        //dnode is freed in thread
779                                        struct download* dnode = calloc(1, sizeof(struct download));
780                                        if(dnode != NULL)
781                                        {
782                                                dnode->host = ostrcat(ip, NULL, 0, 0);
783                                                dnode->page = ostrcat(path, NULL, 0, 0);
784                                                dnode->port = port;
785                                                dnode->filename = ostrcat(localfile, NULL, 0, 0);
786                                                dnode->auth = ostrcat(pw, NULL, 0, 0);
787                                                dnode->connfd = -1;
788                                                dnode->ret = -1;
789                                                dnode->timeout = timeout;
790                                                addtimer(&tithekdownloadthread, START, 100, 1, (void*)dnode, NULL, NULL);
791                                        }
792                                }
793                        }
794                        else
795                                gethttp(ip, path, port, localfile, pw, timeout, NULL, 0);                       
796                }
797        }
798        else
799        {
800       
801                if(localfile != NULL && file_exist(localfile))
802                        ret = textbox(_("Message"), _("File exist, overwrite?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
803
804                if(localfile != NULL && ret == 1)
805                        screendownload("Download", ip, path, port, localfile, pw, timeout, 0);
806        }
807
808        free(ip); ip = NULL;
809        free(tmpstr); tmpstr = NULL;
810
811        return localfile;
812}
813
814int createtithekplay(char* titheklink, struct skin* grid, struct skin* listbox, struct skin* countlabel)
815{
816        int gridbr = 0, posx = 0, count = 0, sumcount = 0, count1 = 0, pagecount = 0, skip = 0;
817        int localfile = 0;
818        struct skin* tmp = NULL;
819        char* tithekfile = NULL;
820        char* tmpstr = NULL;
821
822        if(!ostrncmp("http://", titheklink, 7))
823                tithekfile = tithekdownload(titheklink, NULL, HTTPAUTH, 0, 0);
824        else
825        {
826                tithekfile = ostrcat(titheklink, NULL, 0, 0);
827                localfile = 1;
828        }
829
830        delmarkedscreennodes(grid, 1);
831        freetithek();
832//      if(readtithek(tithekfile) != 0) return 1;
833        int linecount = readtithek(tithekfile);
834//      if(linecount == 0) return 1;
835       
836        struct tithek* titheknode = tithek;
837
838        int height = 280;
839        int width = 390;
840        int picheight = 230;
841        int picwidth = 370;
842        int zcount = 3;
843        int fontsize = 20;
844        int pcount = 6;
845         
846        if(linecount > 8 && getconfigint("tithek_view", NULL) == 1)
847        {
848                height = 180;
849                width = 295;
850                picheight = 130;
851                picwidth = 270;
852                zcount = 4;
853                fontsize = 18;
854                pcount = 12;
855        }
856
857        while(titheknode != NULL)
858        {
859                tmp = addlistbox(grid, listbox, tmp, 1);
860                if(tmp != NULL)
861                {
862                        skip = 0;
863                        sumcount++;
864                        count++;
865                        count1++;
866                        if(gridbr == 0)
867                                tmp->type = GRIDBR;
868                        gridbr = 1;
869                        tmp->wrap = YES;
870
871                        tmp->picheight = picheight;
872                        tmp->picwidth = picwidth;
873
874                        tmp->fontsize = fontsize;
875                        tmp->height = height;
876                        tmp->width = width;
877                        tmp->prozwidth = 0;
878                        //tmp->bgcol = 0xffffff;
879                        tmp->bgspace = 1;
880                        tmp->vspace = 10;
881                        tmp->hspace = 10;
882                        tmp->posx = posx;
883                        //tmp->fontcol = 0x0000ff;
884                        tmp->halign = CENTER;
885                        tmp->valign = TEXTBOTTOM;
886                        changetext(tmp, titheknode->title);
887                        tmp->handle = (char*)titheknode;
888                        posx += tmp->width;
889                        if(count >= zcount)
890                        {
891                                count = 0;
892                                posx = 0;
893                                gridbr = 0;
894                        }
895                       
896                        if(count1 >= pcount)
897                        {
898                                count1 = 0;
899                                pagecount++;
900                                skip = 1;
901                        }
902                }
903                titheknode = titheknode->next;
904        }
905
906        if(skip == 0)
907                pagecount++;
908
909        tmpstr = oitoa(sumcount);
910
911        char* tmpstr1 = ostrcat(_("found"), NULL, 0, 0);
912        tmpstr1 = ostrcat(tmpstr1, " ", 1, 0);
913        tmpstr1 = ostrcat(tmpstr1, tmpstr, 1, 0);
914        free(tmpstr); tmpstr = NULL;
915        tmpstr1 = ostrcat(tmpstr1, " ", 1, 0);
916        tmpstr1 = ostrcat(tmpstr1, _("Results"), 1, 0);
917        changetext(countlabel, tmpstr1);
918        free(tmpstr1); tmpstr1 = NULL;
919
920        if(localfile == 0)
921                unlink(tithekfile);
922       
923        free(tithekfile); tithekfile = NULL;
924        return pagecount;
925}
926
927void removefav(char* title, char* link, char* pic, char* localname, char* menutitle, int flag)
928{
929        int count = 0, i = 0;
930        char* tmpstr = NULL, *tmpstr1 = NULL, *input = NULL;
931        struct splitstr* ret = NULL;
932
933        input = ostrcat(input, title, 1, 0);
934        input = ostrcat(input, "#", 1, 0);
935        input = ostrcat(input, link, 1, 0);
936        input = ostrcat(input, "#", 1, 0);
937        input = ostrcat(input, pic, 1, 0);
938        input = ostrcat(input, "#", 1, 0);
939        input = ostrcat(input, localname, 1, 0);
940        input = ostrcat(input, "#", 1, 0);
941        input = ostrcat(input, menutitle, 1, 0);
942        input = ostrcat(input, "#", 1, 0);
943        input = ostrcat(input, oitoa(flag), 1, 1);
944       
945        tmpstr = readfiletomem(getconfig("tithek_fav", NULL), 0);
946       
947        ret = strsplit(tmpstr, "\n", &count);
948
949        if(ret != NULL)
950        {
951                for(i = 0; i < count; i++)
952                {
953                        if(ostrcmp((ret[i]).part, input) != 0)
954                        {
955                                tmpstr1 = ostrcat(tmpstr1, ret[i].part, 1, 0);
956                                tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
957                        }
958                        else
959                                printf("remove: %s\n", ret[i].part);
960                }
961        }
962
963        if(tmpstr1 != NULL && strlen(tmpstr1) > 0)
964                tmpstr1[strlen(tmpstr1) - 1] = '\0';
965
966        writesys(getconfig("tithek_fav", NULL), tmpstr1, 0);
967
968        free(ret); ret = NULL;
969        free(tmpstr); tmpstr = NULL;
970        free(tmpstr1); tmpstr1 = NULL;
971        free(input); input = NULL;
972}
973
974void addfav(char* title, char* link, char* pic, char* localname, char* menutitle, int flag)
975{
976        int count = 0, i = 0;
977        char* tmpstr = NULL, *tmpstr1 = NULL, *input = NULL;
978        struct splitstr* ret = NULL;
979
980        input = ostrcat(input, title, 1, 0);
981        input = ostrcat(input, "#", 1, 0);
982        input = ostrcat(input, link, 1, 0);
983        input = ostrcat(input, "#", 1, 0);
984        input = ostrcat(input, pic, 1, 0);
985        input = ostrcat(input, "#", 1, 0);
986        input = ostrcat(input, localname, 1, 0);
987        input = ostrcat(input, "#", 1, 0);
988        input = ostrcat(input, menutitle, 1, 0);
989        input = ostrcat(input, "#", 1, 0);
990        input = ostrcat(input, oitoa(flag), 1, 1);
991       
992        tmpstr1 = ostrcat(tmpstr1, input, 1, 0);
993        tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
994
995        tmpstr = readfiletomem(getconfig("tithek_fav", NULL), 0);
996       
997        ret = strsplit(tmpstr, "\n", &count);
998
999        if(ret != NULL)
1000        {
1001                for(i = 0; i < count; i++)
1002                {
1003                        if(ostrcmp((ret[i]).part, input) != 0)
1004                        {
1005                                tmpstr1 = ostrcat(tmpstr1, ret[i].part, 1, 0);
1006                                tmpstr1 = ostrcat(tmpstr1, "\n", 1, 0);
1007                        }
1008                }
1009        }
1010
1011        if(tmpstr1 != NULL && strlen(tmpstr1) > 0)
1012                tmpstr1[strlen(tmpstr1) - 1] = '\0';
1013
1014        writesys(getconfig("tithek_fav", NULL), tmpstr1, 0);
1015
1016        free(ret); ret = NULL;
1017        free(tmpstr); tmpstr = NULL;
1018        free(tmpstr1); tmpstr1 = NULL;
1019        free(input); input = NULL;
1020}
1021
1022void cacheplay(char* link, char* filename, int flag)
1023{
1024        struct skin* load = getscreen("loadingproz");
1025        struct skin* proztext = getscreennode(load, "proztext");
1026
1027        drawscreen(load, 0, 0);
1028        int port = 80, count = 0, mcount = 0;
1029        off64_t size = 0, msize = 0;
1030        char* host = NULL, *pos = NULL, *path = NULL, *file = NULL, *tmpstr = NULL;
1031        host = string_replace("http://", "", (char*)link, 0);
1032
1033        if(host != NULL)
1034                pos = strchr(host, '/');
1035        if(pos != NULL)
1036        {
1037                pos[0] = '\0';
1038                path = pos + 1;
1039        }
1040
1041        file = ostrcat(getconfig("rec_streampath", NULL), "/.cache.", 0, 0);
1042        file = ostrcat(file, filename, 1, 0);
1043
1044        if(ostrstr(host, ":") != NULL)
1045        {
1046                host = oregex("http://(.*):.*", link);
1047                port = atoi(oregex("http://.*:(.*)/.*", link));
1048        }
1049
1050        debug(99, "---------------------------------------");
1051        debug(99, "link: %s", link);
1052        debug(99, "---------------------------------------");
1053        debug(99, "host: %s", host);
1054        debug(99, "port: %d", port);
1055        debug(99, "path: %s", path);
1056        debug(99, "local: %s", file);
1057        debug(99, "---------------------------------------");
1058       
1059       
1060        struct download* dnode = NULL;
1061        dnode = calloc(1, sizeof(struct download));
1062        if(dnode == NULL)
1063        {
1064                err("no mem");
1065                return;
1066        }               
1067        dnode->host = host;
1068        dnode->page = path;
1069        dnode->port = port;
1070        dnode->filename = file;
1071        dnode->auth = NULL;
1072        dnode->connfd = -1;
1073        dnode->ret = -1;
1074        dnode->timeout = 500000;
1075       
1076        addtimer(&gethttpstruct, START, 1000, 1, (void*)dnode, NULL, NULL);
1077
1078        if(flag == 1)
1079        {
1080                mcount = 120;
1081                msize = 10485760;
1082        }
1083        else if(flag == 2)
1084        {
1085                mcount = 240;
1086                msize = 20971520;
1087        }
1088        else if(flag == 3)
1089        {
1090                mcount = 360;
1091                msize = 31457280;
1092        }
1093                       
1094        while(count < mcount || size >= msize)
1095        {
1096                sleep(1);
1097                count++;
1098                if(file_exist(file))
1099                        size = getfilesize(file);
1100
1101                int proz = 0;
1102                int proz1 = size * 100 / msize;
1103                debug(99, "size (%dprozent)", proz1);
1104
1105                int proz2 = count * 100 / mcount;
1106                debug(99, "time (%dprozent)", proz2);
1107               
1108                if(proz1 > proz2)
1109                        proz = proz1;
1110                else
1111                        proz = proz2;
1112
1113                debug(99, "cacheing...(%lldkb) (%dprozent)", size / 1024, proz);
1114
1115                if(size >= msize)
1116                        break;
1117                if(count >= mcount)
1118                        break;
1119               
1120                tmpstr = ostrcat(_("please wait..."), " (", 0, 0);
1121                tmpstr = ostrcat(tmpstr, oitoa(proz), 1, 1);
1122                tmpstr = ostrcat(tmpstr, "%)", 1, 0);
1123                clearscreen(load);
1124                changetext(proztext, tmpstr);
1125                drawscreen(load, 0, 0);
1126                free(tmpstr), tmpstr = NULL;
1127        }
1128
1129        screenplay(file, 2, 0);
1130        sockclose(&dnode->connfd);
1131        free(dnode); dnode = NULL;
1132
1133        tmpstr = ostrcat(tmpstr, _("Remove Cachefile ?"), 1, 0);
1134        tmpstr = ostrcat(tmpstr, "\n\n", 1, 0);
1135        tmpstr = ostrcat(tmpstr, file, 1, 0);
1136       
1137        if(textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1)
1138        {
1139                unlink(file);
1140        }
1141        free(tmpstr), tmpstr = NULL;
1142        free(file), file = NULL;
1143        free(host), host = NULL;
1144}
1145       
1146void submenu(struct skin* listbox, struct skin* load, char* title)
1147{
1148        int flag = 0;
1149        if(status.security == 1)
1150        {
1151                drawscreen(load, 0, 0);
1152                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1153                char* tmpstr1 = NULL;
1154
1155                if(((struct tithek*)listbox->select->handle)->flag == 2)
1156                {
1157                        if(tmpstr != NULL) tmpstr1 = ostrcat(tmpstr, NULL, 0, 0);
1158                }                                               
1159                else if(((struct tithek*)listbox->select->handle)->flag == 4)
1160                {
1161                        if(tmpstr != NULL) tmpstr1 = youtube(tmpstr, NULL, NULL, 1);
1162                }                                               
1163                else if(((struct tithek*)listbox->select->handle)->flag == 5)
1164                {
1165                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://rtl2now.rtl2.de", "rtl2now", 1);
1166                }
1167                else if(((struct tithek*)listbox->select->handle)->flag == 6)
1168                {
1169                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://www.superrtlnow.de", "superrtlnow", 1);
1170                }
1171                else if(((struct tithek*)listbox->select->handle)->flag == 7)
1172                {
1173                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://rtl-now.rtl.de", "rtlnow", 1);
1174                }
1175                else if(((struct tithek*)listbox->select->handle)->flag == 8)
1176                {
1177                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://www.voxnow.de", "voxnow", 1);
1178                }
1179                else if(((struct tithek*)listbox->select->handle)->flag == 12)
1180                {
1181                        if(tmpstr != NULL) tmpstr1 = myvideo(tmpstr, NULL, NULL, 1);
1182                }
1183                else if(((struct tithek*)listbox->select->handle)->flag == 14)
1184                {
1185                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 1);
1186                }
1187                else if(((struct tithek*)listbox->select->handle)->flag == 15)
1188                {
1189                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 2);
1190                }
1191                else if(((struct tithek*)listbox->select->handle)->flag == 16)
1192                {
1193                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://www.superrtlnow.de", "superrtlnow", 1);
1194                }
1195                else if(((struct tithek*)listbox->select->handle)->flag == 17)
1196                {
1197                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://rtl-now.rtl.de", "rtlnow", 1);
1198                }
1199                else if(((struct tithek*)listbox->select->handle)->flag == 18)
1200                {
1201                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://www.voxnow.de", "voxnow", 1);
1202                }
1203                else if(((struct tithek*)listbox->select->handle)->flag == 19)
1204                {
1205                        if(tmpstr != NULL) tmpstr1 = rtl2now(tmpstr, "http://rtl2now.rtl2.de", "rtl2now", 1);
1206                }
1207                else if(((struct tithek*)listbox->select->handle)->flag == 20)
1208                {
1209                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 3);
1210                }
1211                else if(((struct tithek*)listbox->select->handle)->flag == 24)
1212                {
1213                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 4);
1214                }
1215                else if(((struct tithek*)listbox->select->handle)->flag == 25)
1216                {
1217                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 5);
1218                }
1219                else if(((struct tithek*)listbox->select->handle)->flag == 26)
1220                {
1221                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 6);
1222                }
1223                else if(((struct tithek*)listbox->select->handle)->flag == 27)
1224                {
1225                        if(tmpstr != NULL) tmpstr1 = kinox(tmpstr, NULL, NULL, 7);
1226                }
1227                else if(((struct tithek*)listbox->select->handle)->flag == 50)
1228                {
1229                        if(tmpstr != NULL) tmpstr1 = beeg(tmpstr);
1230                }
1231
1232                free(tmpstr); tmpstr = NULL;
1233
1234                if(ostrcmp(title, "TiThek - Internet Radio") == 0)
1235                        flag = 4;
1236
1237                if(tmpstr1 != NULL)
1238                {
1239                        char* filename = ostrcat(title, "_", 0, 0);
1240                        filename = ostrcat(filename, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1241                        filename = ostrcat(filename, ".mp4", 1, 0);
1242                        filename = string_replace_all(" ", ".", filename, 1);
1243                        filename = string_replace_all("-", "_", filename, 1);
1244                        filename = string_replace_all("._.", "_", filename, 1);
1245                        debug(99, "filename: %s", filename);
1246                               
1247                        char* keyconf = NULL;
1248                        char* skintitle = "Choice Playback";
1249                        struct menulist* mlist = NULL, *mbox = NULL;
1250                       
1251                        addmenulist(&mlist, "Streaming Playback (default)", NULL, NULL, 0, 0);
1252                       
1253                        if(!ostrncmp("http://", tmpstr1, 7))
1254                        {
1255                                if(flag == 4)
1256                                {
1257                                        addmenulist(&mlist, "Streaming Playback Caching (0.5MB)", NULL, NULL, 0, 0);
1258                                        addmenulist(&mlist, "Streaming Playback Caching (1MB)", NULL, NULL, 0, 0);
1259                                }       
1260                                else if(!ostrncmp("http://", tmpstr1, 7))
1261                                {
1262                                        addmenulist(&mlist, "Streaming Playback Caching (1MB)", NULL, NULL, 0, 0);
1263                                        addmenulist(&mlist, "Streaming Playback Caching (2MB)", NULL, NULL, 0, 0);
1264                                        addmenulist(&mlist, "Streaming Playback Caching (3MB)", NULL, NULL, 0, 0);
1265                                        addmenulist(&mlist, "Streaming Playback Caching (4MB)", NULL, NULL, 0, 0);
1266                                        addmenulist(&mlist, "Streaming Playback Caching (5MB)", NULL, NULL, 0, 0);
1267                                        if(file_exist(getconfig("rec_streampath", NULL)))
1268                                        {
1269//                                              addmenulist(&mlist, "File Caching Playback (10MB / 120s)", NULL, NULL, 0, 0);
1270//                                              addmenulist(&mlist, "File Caching Playback (20MB / 240s)", NULL, NULL, 0, 0);
1271//                                              addmenulist(&mlist, "File Caching Playback (30MB / 360s)", NULL, NULL, 0, 0);
1272                                                if(file_exist("/var/swap/etc/.tithekdownload") || status.expertmodus >= 11)
1273                                                        addmenulist(&mlist, "Download Full File", NULL, NULL, 0, 0);
1274                                        }
1275                                }
1276                        }
1277                        mbox = menulistbox(mlist, NULL, skintitle, NULL, NULL, 1, 0);
1278                        if(mbox != NULL) keyconf = mbox->name;
1279                        if(ostrcmp(keyconf, "Streaming Playback (default)") == 0)
1280                        {
1281                                addconfigtmp("playerbuffersize", "0");
1282                                screenplay(tmpstr1, 2, flag);
1283                                delconfigtmp("playerbuffersize");
1284                        }
1285                        else if(ostrcmp(keyconf, "Streaming Playback Caching (0.5MB)") == 0)
1286                        {
1287                                addconfigtmp("playerbuffersize", "524288");
1288                                screenplay(tmpstr1, 2, flag);
1289                                delconfigtmp("playerbuffersize");
1290                        }
1291                        else if(ostrcmp(keyconf, "Streaming Playback Caching (1MB)") == 0)
1292                        {
1293                                addconfigtmp("playerbuffersize", "1048576");
1294                                screenplay(tmpstr1, 2, flag);
1295                                delconfigtmp("playerbuffersize");
1296                        }
1297                        else if(ostrcmp(keyconf, "Streaming Playback Caching (2MB)") == 0)
1298                        {
1299                                addconfigtmp("playerbuffersize", "2097152");
1300                                screenplay(tmpstr1, 2, flag);
1301                                delconfigtmp("playerbuffersize");
1302                        }
1303                        else if(ostrcmp(keyconf, "Streaming Playback Caching (3MB)") == 0)
1304                        {
1305                                addconfigtmp("playerbuffersize", "3145728");
1306                                screenplay(tmpstr1, 2, flag);
1307                                delconfigtmp("playerbuffersize");
1308                        }
1309                        else if(ostrcmp(keyconf, "Streaming Playback Caching (4MB)") == 0)
1310                        {
1311                                addconfigtmp("playerbuffersize", "4194304");
1312                                screenplay(tmpstr1, 2, flag);
1313                                delconfigtmp("playerbuffersize");
1314                        }
1315                        else if(ostrcmp(keyconf, "Streaming Playback Caching (5MB)") == 0)
1316                        {
1317                                addconfigtmp("playerbuffersize", "5242880");
1318                                screenplay(tmpstr1, 2, flag);
1319                                delconfigtmp("playerbuffersize");
1320                        }
1321                        else if(ostrcmp(keyconf, "File Caching Playback (10MB / 120s)") == 0)
1322                        {
1323                                cacheplay(tmpstr1, filename, 1);
1324                        }
1325                        else if(ostrcmp(keyconf, "File Caching Playback (20MB / 240s)") == 0)
1326                        {
1327                                cacheplay(tmpstr1, filename, 2);
1328                        }
1329                        else if(ostrcmp(keyconf, "File Caching Playback (30MB / 360s)") == 0)
1330                        {
1331                                cacheplay(tmpstr1, filename, 3);
1332                        }
1333                        else if(ostrcmp(keyconf, "Download Full File") == 0)
1334                        {
1335                                char* search = textinput("Search", filename);
1336                                if(search != NULL)
1337                                {       
1338                                        char* tmpstr2 = tithekdownload(tmpstr1, search, NULL, 0, 1);
1339//                                              drawscreen(grid, 0, 0);
1340                                        free(tmpstr2); tmpstr2 = NULL;
1341                               
1342                                        if(textbox(_("Message"), _("Start playback"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1)
1343                                        {
1344                                                tmpstr2 = ostrcat(getconfig("rec_streampath", NULL), "/", 0, 0);
1345                                                tmpstr2 = ostrcat(tmpstr2, search, 1, 0);
1346                                                screenplay(tmpstr2, 2, flag);
1347                                                free(tmpstr2); tmpstr2 = NULL;
1348                                        }
1349                                }
1350                                free(search), search = NULL;
1351                        }
1352                        free(filename), filename = NULL;
1353                        freemenulist(mlist, 1); mlist = NULL;
1354                }
1355                else
1356                        textbox(_("Message"), _("Can't get Streamurl !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1357               
1358                free(tmpstr1); tmpstr1 = NULL;
1359        }
1360        else
1361                textbox(_("Message"), _("Registration needed, please contact Atemio !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0);
1362}
1363
1364void screentithekplay(char* titheklink, char* title, int first)
1365{
1366        int rcret = -1, oaktline = 1, oaktpage = -1, ogridcol = 0;
1367
1368        if(!file_exist("/var/swap/player"))
1369                mkdir("/var/swap/player", 0777);
1370
1371        writesysint("/proc/sys/vm/drop_caches", 3, 0);
1372       
1373        if(first == 1)
1374        {
1375                delallfiles("/tmp/tithek", NULL);
1376                mkdir("/tmp/tithek", 777);
1377                if(status.mcaktiv == 0)
1378                {
1379                        rcret = servicestop(status.aktservice, 1, 1);
1380                        if(rcret == 1) return;
1381                }
1382        }
1383
1384        struct skin* grid = getscreen("titheklist");
1385        struct skin* listbox = getscreennode(grid, "listbox");
1386        struct skin* countlabel = getscreennode(grid, "countlabel");
1387        struct skin* countpage = getscreennode(grid, "countpage");
1388        struct skin* load = getscreen("loading");
1389        struct skin* tmp = NULL;
1390        char* tithekpic = NULL;
1391       
1392        if(titheklink == NULL) return;
1393       
1394        listbox->aktpage = -1;
1395        listbox->aktline = 1;
1396        listbox->gridcol = 0;
1397        listbox->select = NULL;
1398
1399//      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) return;
1400        int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1401        if(pagecount == 0) return;
1402
1403        changetitle(grid, _(title));
1404        drawscreen(grid, 0, 0);
1405        addscreenrc(grid, listbox);
1406                               
1407        while(1)
1408        {
1409                changetitle(grid, _(title));
1410                if(listbox->select != NULL && listbox->select->handle != NULL)
1411                {
1412                        tmp = listbox->select;
1413                        while(tmp != NULL)
1414                        {
1415
1416                                if(tmp->pagecount != listbox->aktpage) break;
1417
1418                                char* tmpstr = ostrcat(_("Page"), NULL, 0, 0);
1419                                tmpstr = ostrcat(tmpstr, " ( ", 1, 0);
1420                                tmpstr = ostrcat(tmpstr, oitoa(tmp->pagecount), 1, 1);
1421                                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1422                                tmpstr = ostrcat(tmpstr, oitoa(pagecount), 1, 1);
1423                                tmpstr = ostrcat(tmpstr, _(" )"), 1, 0);
1424                                changetext(countpage, tmpstr);
1425                                free(tmpstr); tmpstr = NULL;
1426       
1427                                if(tmp->handle != NULL)
1428                                {
1429                                        tithekpic = tithekdownload(((struct tithek*)tmp->handle)->pic, ((struct tithek*)tmp->handle)->localname, "aXBrLUdaRmg6RkhaVkJHaG56ZnZFaEZERlRHenVpZjU2NzZ6aGpHVFVHQk5Iam0=", 1, 0);
1430
1431                                        /* not working with thread download
1432                                        off64_t checkpic = getfilesize(tithekpic);
1433                       
1434                                        if(checkpic < 1000)
1435                                        {
1436                                                free(tithekpic); tithekpic = NULL;
1437                                                tithekpic = ostrcat("/var/usr/local/share/titan/plugins/tithek/default.jpg", NULL, 0, 0);
1438                                        }
1439                                        */
1440                       
1441                                        changepic(tmp, tithekpic);
1442                                        free(tithekpic); tithekpic = NULL;
1443                                }
1444                                tmp = tmp->prev;
1445                        }
1446                        tmp = listbox->select;
1447                        if(tmp != NULL) tmp = tmp->next;
1448                        while(tmp != NULL)
1449                        {
1450                                if(tmp->pagecount != listbox->aktpage) break;
1451                                if(tmp->handle != NULL)
1452                                {
1453                                        tithekpic = tithekdownload(((struct tithek*)tmp->handle)->pic, ((struct tithek*)tmp->handle)->localname, "aXBrLUdaRmg6RkhaVkJHaG56ZnZFaEZERlRHenVpZjU2NzZ6aGpHVFVHQk5Iam0=", 1, 0);
1454
1455                                        /* not working with thread download
1456                                        off64_t checkpic = getfilesize(tithekpic);
1457
1458                                        if(checkpic < 1000)
1459                                        {
1460                                                free(tithekpic); tithekpic = NULL;
1461                                                tithekpic = ostrcat("/var/usr/local/share/titan/plugins/tithek/default.jpg", NULL, 0, 0);
1462                                        }
1463                                        */
1464
1465                                        changepic(tmp, tithekpic);
1466                                        free(tithekpic); tithekpic = NULL;
1467                                }
1468                                tmp = tmp->next;
1469                        }
1470                }
1471               
1472                int count = getfilecount(TITHEKPATH);
1473                if(count > 500)
1474                        delallfiles(TITHEKPATH, ".jpg");
1475
1476                drawscreen(grid, 0, 0);
1477waitrcstart:
1478                rcret = waitrc(grid, 2000, 2);
1479
1480                if(rcret == RCTIMEOUT)
1481                {
1482                        if(tithekdownloadrun == 1)
1483                        {
1484                                tithekdownloadrun = 0;
1485                                drawscreen(grid, 0, 0);
1486                        }
1487                        goto waitrcstart;
1488                }
1489
1490                if(rcret == getrcconfigint("rcblue", NULL))
1491                {
1492                        tithekexit = 1;
1493                        break;
1494                }
1495
1496                if(rcret == getrcconfigint("rcexit", NULL)) break;
1497                if(rcret == getrcconfigint("rcmenu", NULL))
1498                {
1499                        screentithek_settings();
1500                        createtithekplay(titheklink, grid, listbox, countlabel);
1501                        drawscreen(grid, 0, 0);
1502                }
1503               
1504                if(rcret == getrcconfigint("rcred", NULL))
1505                {
1506                        if(listbox->select != NULL && listbox->select->handle != NULL)
1507                        {
1508
1509                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->title, NULL, 0, 0);
1510                                debug(99, "tmpstr: %s", tmpstr);
1511                                tmpstr = string_replace("-1 (de)", "", tmpstr, 1);
1512                                tmpstr = string_replace("-1 (en)", "", tmpstr, 1);
1513                                tmpstr = string_replace("-1 (\?\?)", "", tmpstr, 1);
1514                                tmpstr = string_replace("-2 (de)", "", tmpstr, 1);
1515                                tmpstr = string_replace("-2 (en)", "", tmpstr, 1);
1516                                tmpstr = string_replace("-2 (\?\?)", "", tmpstr, 1);
1517                                tmpstr = string_replace("-3 (de)", "", tmpstr, 1);
1518                                tmpstr = string_replace("-3 (en)", "", tmpstr, 1);
1519                                tmpstr = string_replace("-3 (\?\?)", "", tmpstr, 1);
1520                                tmpstr = string_replace(" (de)", "", tmpstr, 1);
1521                                tmpstr = string_replace(" (en)", "", tmpstr, 1);
1522                                tmpstr = string_replace(" (\?\?)", "", tmpstr, 1);
1523                                debug(99, "tmpstr: %s", tmpstr);
1524
1525                                playrcred(tmpstr, 1, 0, 99);
1526                                free(tmpstr), tmpstr = NULL;
1527                        }
1528                }
1529                else if(rcret == getrcconfigint("rcok", NULL))
1530                {
1531                        if(listbox->select != NULL && listbox->select->handle != NULL)
1532                        {
1533                                clearscreen(grid);
1534
1535                                if((((struct tithek*)listbox->select->handle)->flag == 2) || (((struct tithek*)listbox->select->handle)->flag == 4) || (((struct tithek*)listbox->select->handle)->flag == 5) || (((struct tithek*)listbox->select->handle)->flag == 6) || (((struct tithek*)listbox->select->handle)->flag == 7) || (((struct tithek*)listbox->select->handle)->flag == 8) || (((struct tithek*)listbox->select->handle)->flag == 12) || (((struct tithek*)listbox->select->handle)->flag == 14) || (((struct tithek*)listbox->select->handle)->flag == 15) || (((struct tithek*)listbox->select->handle)->flag == 16) || (((struct tithek*)listbox->select->handle)->flag == 17) || (((struct tithek*)listbox->select->handle)->flag == 18) || (((struct tithek*)listbox->select->handle)->flag == 19) || (((struct tithek*)listbox->select->handle)->flag == 20) || (((struct tithek*)listbox->select->handle)->flag == 24) || (((struct tithek*)listbox->select->handle)->flag == 25) || (((struct tithek*)listbox->select->handle)->flag == 26) || (((struct tithek*)listbox->select->handle)->flag == 27) || (((struct tithek*)listbox->select->handle)->flag == 50))
1536                                {
1537                                        submenu(listbox, load, title);
1538                                        drawscreen(grid, 0, 0);
1539                                }
1540                                else if((((struct tithek*)listbox->select->handle)->flag == 9) || (((struct tithek*)listbox->select->handle)->flag == 10) || (((struct tithek*)listbox->select->handle)->flag == 11))
1541                                {
1542                                        if(youtube_search(grid, listbox, countlabel, load, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->title) == 0)
1543                                        {
1544                                                oaktpage = listbox->aktpage;
1545                                                oaktline = listbox->aktline;
1546                                                ogridcol = listbox->gridcol;
1547                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1548                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);
1549                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1550                                                screentithekplay(tmpstr, tmpstr2, 0);
1551                                                free(tmpstr); tmpstr = NULL;
1552                                                free(tmpstr2); tmpstr2 = NULL;
1553//                                      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1554                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1555                                                if(pagecount == 0 || tithekexit == 1) break;
1556
1557                                                listbox->aktpage = oaktpage;
1558                                                listbox->aktline = oaktline;
1559                                                listbox->gridcol = ogridcol;
1560                                                addscreenrc(grid, listbox);
1561                                        }
1562                                }
1563                                else if((((struct tithek*)listbox->select->handle)->flag == 13))
1564                                {
1565                                        if(myvideo_search(grid, listbox, countlabel, load, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->title) == 0)
1566                                        {
1567                                                oaktpage = listbox->aktpage;
1568                                                oaktline = listbox->aktline;
1569                                                ogridcol = listbox->gridcol;
1570                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1571                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);
1572                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1573                                                screentithekplay(tmpstr, tmpstr2, 0);
1574                                                free(tmpstr); tmpstr = NULL;
1575                                                free(tmpstr2); tmpstr2 = NULL;
1576//                                      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1577                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1578                                                if(pagecount == 0 || tithekexit == 1) break;
1579
1580                                                listbox->aktpage = oaktpage;
1581                                                listbox->aktline = oaktline;
1582                                                listbox->gridcol = ogridcol;
1583                                                addscreenrc(grid, listbox);
1584                                        }
1585                                }
1586                                else if((((struct tithek*)listbox->select->handle)->flag == 21))
1587                                {
1588                                        if(kinox_search(grid, listbox, countlabel, load, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->title) == 0)
1589                                        {
1590                                                oaktpage = listbox->aktpage;
1591                                                oaktline = listbox->aktline;
1592                                                ogridcol = listbox->gridcol;
1593                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1594                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);
1595                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1596                                                screentithekplay(tmpstr, tmpstr2, 0);
1597                                                free(tmpstr); tmpstr = NULL;
1598                                                free(tmpstr2); tmpstr2 = NULL;
1599//                                      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1600                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1601                                                if(pagecount == 0 || tithekexit == 1) break;
1602
1603                                                listbox->aktpage = oaktpage;
1604                                                listbox->aktline = oaktline;
1605                                                listbox->gridcol = ogridcol;
1606                                                addscreenrc(grid, listbox);
1607                                        }
1608                                }
1609                                else if((((struct tithek*)listbox->select->handle)->flag == 22))
1610                                {
1611                                        if(kinox_hoster(grid, listbox, countlabel, load, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->title) == 0)
1612                                        {
1613                                                oaktpage = listbox->aktpage;
1614                                                oaktline = listbox->aktline;
1615                                                ogridcol = listbox->gridcol;
1616                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1617                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);
1618                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1619                                                screentithekplay(tmpstr, tmpstr2, 0);
1620                                                free(tmpstr); tmpstr = NULL;
1621                                                free(tmpstr2); tmpstr2 = NULL;
1622//                                      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1623                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1624                                                if(pagecount == 0 || tithekexit == 1) break;
1625
1626                                                listbox->aktpage = oaktpage;
1627                                                listbox->aktline = oaktline;
1628                                                listbox->gridcol = ogridcol;
1629                                                addscreenrc(grid, listbox);
1630                                        }
1631                                }                       
1632                                else if((((struct tithek*)listbox->select->handle)->flag == 23))
1633                                {
1634                                        if(kinox_hoster_series(grid, listbox, countlabel, load, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->title) == 0)
1635                                        {
1636                                                oaktpage = listbox->aktpage;
1637                                                oaktline = listbox->aktline;
1638                                                ogridcol = listbox->gridcol;
1639                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1640                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);
1641                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1642                                                screentithekplay(tmpstr, tmpstr2, 0);
1643                                                free(tmpstr); tmpstr = NULL;
1644                                                free(tmpstr2); tmpstr2 = NULL;
1645//                                      if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1646                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1647                                                if(pagecount == 0 || tithekexit == 1) break;
1648
1649                                                listbox->aktpage = oaktpage;
1650                                                listbox->aktline = oaktline;
1651                                                listbox->gridcol = ogridcol;
1652                                                addscreenrc(grid, listbox);
1653                                        }
1654                                }
1655                                else if((((struct tithek*)listbox->select->handle)->flag == 66))
1656                                {
1657                                        textbox(_("Message"), _("The hoster is not yet supported for the time !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0);
1658                                        continue;
1659                                }       
1660                                else
1661                                {
1662                                        int pincheck = 0;
1663                                        if(((struct tithek*)listbox->select->handle)->flag == 1000)
1664                                                pincheck = screenpincheck(0, NULL);
1665                                        if(pincheck == 0)
1666                                        {
1667                                                oaktpage = listbox->aktpage;
1668                                                oaktline = listbox->aktline;
1669                                                ogridcol = listbox->gridcol;
1670                                                char* tmpstr = ostrcat(((struct tithek*)listbox->select->handle)->link, NULL, 0, 0);
1671                                                char* tmpstr1 = ostrcat(((struct tithek*)listbox->select->handle)->menutitle, " - ", 0, 0);                                     
1672                                                char* tmpstr2 = ostrcat(tmpstr1, ((struct tithek*)listbox->select->handle)->title, 1, 0);
1673                                                screentithekplay(tmpstr, tmpstr2, 0);
1674                                                free(tmpstr); tmpstr = NULL;
1675                                                free(tmpstr2); tmpstr2 = NULL; 
1676//                                              if(createtithekplay(titheklink, grid, listbox, countlabel) != 0) break;
1677                                                int pagecount = createtithekplay(titheklink, grid, listbox, countlabel);
1678                                                if(pagecount == 0 || tithekexit == 1) break;
1679
1680                                                listbox->aktpage = oaktpage;
1681                                                listbox->aktline = oaktline;
1682                                                listbox->gridcol = ogridcol;
1683                                                addscreenrc(grid, listbox);
1684                                        }
1685                                }
1686                                drawscreen(grid, 0, 0);
1687//                              sleep(1);
1688                        }                       
1689                }
1690                else if(rcret == getrcconfigint("rcyellow", NULL) && ostrcmp(title, "TiThek - Favoriten") == 0)
1691                {
1692                        if(textbox(_("Message"), _("Remove this Favorite ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0) == 1)
1693                        {
1694                                removefav(((struct tithek*)listbox->select->handle)->title, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->pic, ((struct tithek*)listbox->select->handle)->localname, ((struct tithek*)listbox->select->handle)->menutitle, ((struct tithek*)listbox->select->handle)->flag);             
1695                                int pagecount = createtithekplay(getconfig("tithek_fav", NULL), grid, listbox, countlabel);
1696                                if(pagecount == 0) return;
1697                                       
1698                                drawscreen(grid, 0, 0);
1699                        }
1700                }
1701                else if(rcret == getrcconfigint("rcgreen", NULL) && ostrcmp(title, "TiThek - Favoriten") != 0)
1702                {
1703                        if(textbox(_("Message"), _("Add this link as Favorite ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0) == 1)
1704                        {
1705                                addfav(((struct tithek*)listbox->select->handle)->title, ((struct tithek*)listbox->select->handle)->link, ((struct tithek*)listbox->select->handle)->pic, ((struct tithek*)listbox->select->handle)->localname, ((struct tithek*)listbox->select->handle)->menutitle, ((struct tithek*)listbox->select->handle)->flag);         
1706                        }
1707                }
1708        }
1709
1710        delmarkedscreennodes(grid, 1);
1711        delownerrc(grid);
1712        clearscreen(grid);
1713
1714        if(first == 1)
1715        {
1716                freetithek();
1717                delallfiles("/tmp/tithek", ".list");
1718                if(status.mcaktiv == 0)
1719                        servicecheckret(servicestart(status.lastservice->channel, NULL, NULL, 0), 0);
1720        }
1721}
1722
1723#endif
Note: See TracBrowser for help on using the repository browser.