source: titan/plugins/mc/mc_global.h @ 44530

Last change on this file since 44530 was 44530, checked in by obi, 4 years ago

fix tpk building

File size: 36.1 KB
Line 
1#ifndef MC_GLOBAL_H
2#define MC_GLOBAL_H
3
4/*
5 ------------------------------------------
6        mc_changeview start
7 ------------------------------------------
8*/
9// flag 1 = vp
10// flag 2 = ap
11// flag 3 = pp
12void mc_changeview(int view, struct skin* filelist, struct skin* apskin, int flag)
13{
14        struct skin* node = filelist;
15
16        struct skin* plot = getscreennode(apskin, "plot");
17        struct skin* title = getscreennode(apskin, "title");
18        struct skin* thumb = getscreennode(apskin, "thumb");
19        struct skin* actorstext = getscreennode(apskin, "actorstext");
20        struct skin* actors = getscreennode(apskin, "actors");
21        struct skin* genretext = getscreennode(apskin, "genretext");
22        struct skin* genre = getscreennode(apskin, "genre");
23        struct skin* yeartext = getscreennode(apskin, "yeartext");
24        struct skin* year = getscreennode(apskin, "year");
25        struct skin* realnametext = getscreennode(apskin, "realnametext");
26        struct skin* realname = getscreennode(apskin, "realname");
27        struct skin* albumtext = getscreennode(apskin, "albumtext");
28        struct skin* album = getscreennode(apskin, "album");
29        struct skin* stars = getscreennode(apskin, "stars");
30
31        struct skin* loadmediadb = getscreen("loading");
32        struct skin* blackscreen = getscreen("blackscreen");
33        drawscreen(blackscreen, 0, 0);
34        drawscreen(loadmediadb, 0, 0);
35                       
36        while(node != NULL)
37        {
38                if(node->del == FILELISTDELMARK)
39                {
40                        node->fontsize = 0;
41                        node->height = 0;
42                        node->width = 0;
43                        node->height = 0;
44                        node->bgcol = 0;
45                        node->transparent = 0;
46                        node->prozwidth = 0;
47                        node->posx = 0;
48                }
49                node = node->next;
50        }
51
52        if(view == 0)
53        {
54                filelist->fontsize = 25;//, fontspace = 5;
55                filelist->height = 460;
56                filelist->width = 1160;
57                filelist->prozwidth = 0;
58                filelist->posx = 40;
59                filelist->transparent = -1;
60                filelist->bgcol = -1;
61                thumb->hidden = YES;
62                plot->hidden = YES;
63                title->hidden = YES;
64                actorstext->hidden = YES;
65                actors->hidden = YES;
66                genretext->hidden = YES;
67                genre->hidden = YES;
68                yeartext->hidden = YES;
69                year->hidden = YES;
70                realnametext->hidden = YES;
71                realname->hidden = YES;
72                albumtext->hidden = YES;
73                album->hidden = YES;
74                stars->hidden = YES;
75        }
76        else if(view == 1)
77        {
78                filelist->fontsize = 35;//, fontspace = 5;
79                filelist->height = 460;
80                filelist->width = 1160;
81                filelist->prozwidth = 0;
82                filelist->posx = 40;
83                filelist->transparent = -1;
84                filelist->bgcol = -1;
85                filelist->prozwidth = 0;
86                thumb->hidden = YES;
87                plot->hidden = YES;
88                title->hidden = YES;   
89                actorstext->hidden = YES;
90                actors->hidden = YES;
91                genretext->hidden = YES;
92                genre->hidden = YES;
93                yeartext->hidden = YES;
94                year->hidden = YES;
95                realnametext->hidden = YES;
96                realname->hidden = YES;
97                albumtext->hidden = YES;
98                album->hidden = YES;
99                stars->hidden = YES;
100        }
101        else if(view == 2)
102        {
103                filelist->fontsize = 20;//, fontspace = 5;
104                filelist->height = 480;
105                filelist->width = 1160;
106                filelist->prozwidth = 0;       
107                filelist->posx = 40;
108                filelist->transparent = -1;
109                filelist->bgcol = -1;
110                thumb->hidden = YES;
111                plot->hidden = YES;
112                title->hidden = YES;
113                actorstext->hidden = YES;
114                actors->hidden = YES;
115                genretext->hidden = YES;
116                genre->hidden = YES;
117                yeartext->hidden = YES;
118                year->hidden = YES;
119                realnametext->hidden = YES;
120                realname->hidden = YES;
121                albumtext->hidden = YES;
122                album->hidden = YES;
123                stars->hidden = YES;
124        }
125        else if(view == 3)
126        {
127                filelist->fontsize = 25;//, fontspace = 10;
128                filelist->height = 350;
129                if(flag == 2)
130                        filelist->width = 800;
131                else
132                        filelist->width = 600;
133                filelist->prozwidth = 0;               
134                filelist->bgcol = 0x474747;
135                filelist->transparent = 40;
136                filelist->posx = 20;
137                thumb->hidden = NO;
138                title->hidden = NO;
139
140                if(flag == 2)
141                {
142                        plot->hidden = YES;
143                        actorstext->hidden = NO;
144                        actors->hidden = NO;
145                        genretext->hidden = NO;
146                        genre->hidden = NO;
147                        yeartext->hidden = NO;
148                        year->hidden = NO;
149                        realnametext->hidden = NO;
150                        realname->hidden = NO;
151                        albumtext->hidden = NO;
152                        album->hidden = NO;
153                        stars->hidden = YES;
154                }
155                else
156                {
157                        plot->hidden = NO;
158                        actorstext->hidden = YES;
159                        actors->hidden = YES;
160                        genretext->hidden = YES;
161                        genre->hidden = YES;
162                        yeartext->hidden = YES;
163                        year->hidden = YES;
164                        realnametext->hidden = YES;
165                        realname->hidden = YES;
166                        albumtext->hidden = YES;
167                        album->hidden = YES;
168                        stars->hidden = NO;
169                }
170        }       
171        else if(view == 4)
172        {
173                filelist->fontsize = 30;//, fontspace = 5;
174                filelist->height = 460;
175                filelist->width = 1160;
176                filelist->prozwidth = 0;
177                filelist->posx = 40;
178                filelist->transparent = -1;
179                filelist->bgcol = -1;
180                filelist->prozwidth = 0;
181                thumb->hidden = YES;
182                plot->hidden = YES;
183                title->hidden = YES;           
184                actorstext->hidden = YES;
185                actors->hidden = YES;
186                genretext->hidden = YES;
187                genre->hidden = YES;
188                yeartext->hidden = YES;
189                year->hidden = YES;
190                realnametext->hidden = YES;
191                realname->hidden = YES;
192                albumtext->hidden = YES;
193                album->hidden = YES;
194                stars->hidden = YES;
195        }
196        else if(view == 5)
197        {
198                filelist->fontsize = 25;//, fontspace = 5;
199                filelist->height = 460;
200                filelist->width = 1160;
201                filelist->prozwidth = 0;
202                filelist->posx = 40;
203                filelist->transparent = -1;
204                filelist->bgcol = -1;
205                filelist->prozwidth = 0;
206                thumb->hidden = YES;
207                plot->hidden = YES;
208                title->hidden = YES;   
209                actorstext->hidden = YES;
210                actors->hidden = YES;
211                genretext->hidden = YES;
212                genre->hidden = YES;
213                yeartext->hidden = YES;
214                year->hidden = YES;
215                realnametext->hidden = YES;
216                realname->hidden = YES;
217                albumtext->hidden = YES;
218                album->hidden = YES;
219                stars->hidden = YES;
220        }
221
222        filelist->fontsize += status.fontsizeadjust;
223}
224
225/*
226 ------------------------------------------
227        mc_changeratio start
228 ------------------------------------------
229*/
230int mc_changeratio()
231{
232        debug(50, "[mc_changeratio] start");
233        char *tmppolicy = NULL, *tmpstr = NULL;
234        debug(50, "[mc_changeratio] getpolicy");
235        tmppolicy = getpolicy();
236
237        debug(50, "[mc_changeratio] from: %s", tmppolicy);
238
239        if(!strncmp("letterbox", tmppolicy, 8)){
240                tmpstr = ostrcat(tmpstr, "panscan", 1, 0);
241        } else if(!strncmp("panscan", tmppolicy, 7)){
242                tmpstr = ostrcat(tmpstr, "non", 1, 0);
243        } else if(!strncmp("non", tmppolicy, 3)){
244                tmpstr = ostrcat(tmpstr, "bestfit", 1, 0);
245        } else if(!strncmp("bestfit", tmppolicy, 7)){
246                tmpstr = ostrcat(tmpstr, "letterbox", 1, 0);
247        }
248
249        debug(50, "[mc_changeratio] to: %s", tmpstr);
250        setpolicy(tmpstr);
251
252        free(tmpstr); tmpstr = NULL;
253        free(tmppolicy); tmppolicy = NULL;
254        return 0;
255}
256
257extern struct skin* skin;
258extern struct screensaver* screensaver;
259
260void playereof(struct skin* apskin, struct skin* filelist, struct skin* listbox, struct skin* filelistpath, struct skin* b2, struct skin* picscreen, struct skin* picture, struct skin* picname, int* skip, int* eof, int* playlist, int playertype, int flag)
261{
262                debug(50, "--------------eof-------------");
263                status.playspeed = 0;
264                status.pause = 0;
265                status.play = 0;
266                int skiprcok = 0;
267               
268                //playlist
269                if(*playlist == 1 && flag != 4)
270                {
271//                      changetext(b2, _("Playlist-Mode"));
272                        changetext(b2, _("Playlist"));
273
274                        if(screensaver != NULL && screensaver->type == 3 && flag == 2)
275                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
276               
277                        drawscreen(apskin, 0, 0);
278               
279                        int switchtofilelist = 0;
280                                               
281                        if(status.random == 1 && status.repeat == 0)
282                        {
283                                int maxdirs = 0, maxfiles = 0;
284                                getplaylistmaxold(listbox, &maxdirs, &maxfiles);
285                                struct skin* tmplist = getplaylistrandomold(listbox, maxdirs, maxfiles);
286                                debug(50, "struct skin xtext=%s", tmplist->text);
287                                if(tmplist != NULL)
288                                {
289                                        debug(50, "struct skin randomtext=%s", tmplist->text);
290                                        setlistboxselection(listbox, tmplist->name);
291                                }
292                        }
293                        else
294                        {
295                                if(status.repeat == 0)
296                                {
297                                        debug(50, "writerc: rcdown next file");
298
299                                        debug(50, "listbox->aktline: %d", listbox->aktline);
300                                        debug(50, "listbox->linecount: %d", listbox->linecount);
301                                        debug(50, "*eof: %d", *eof);
302                                        debug(50, "flag: %d", flag);
303                       
304
305                                        if(*eof == 0)
306                                        {
307                                                if(listbox->aktline < listbox->linecount)
308                                                {
309                                                        listbox->aktline ++;
310//                                                      if(flag == 1)
311//                                                      {
312//                                                              apskin->hidden = YES;
313//                                                              delownerrc(apskin);
314//                                                              drawscreen(skin, 0, 0);
315//                                                      }
316                                                }
317                                                else
318                                                {
319                                                        if(flag != 3)
320                                                                playrcstop(playertype, flag);
321                                                        if((flag == 1) || (flag == 3))
322                                                        {
323                                                                apskin->hidden = NO;
324                                                                filelist->hidden = NO;
325                                                                listbox->hidden = YES;
326
327                                                                if(flag == 1)
328                                                                        changetext(filelistpath, _(getconfig("mc_vp_path", NULL)));
329                                                                else if(flag == 2)
330                                                                        changetext(filelistpath, _(getconfig("mc_ap_path", NULL)));
331                                                                else if(flag == 3)
332                                                                {
333                                                                        changetext(filelistpath, _(getconfig("mc_pp_path", NULL)));
334                                                                        picplayer(picscreen, picture, picname, NULL, 0);
335                                                                        clearscreen(picscreen);
336                                                                }
337
338                                                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
339//                                                              changetext(b2, _("Filelist-Mode"));
340                                                                changetext(b2, _("Playlist"));
341//                                                              writevfdmenu("Filelist-Mode");
342                                                                writevfdmenu("Playlist");
343
344                                                                switchtofilelist = 1;
345       
346                                                                drawscreen(skin, 0, 0);
347                                                               
348                                                                // show skin
349                                                                setfbtransparent(255);
350
351                                                                *playlist = 0;
352                                                        }
353                                                        else
354                                                        {
355                                                                if(screensaver != NULL && screensaver->type == 3 && flag == 2)
356                                                                        singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
357                                                        }
358                                                        skiprcok = 1;
359                                                }
360                                        }
361                                        else if(*eof == 1)
362                                        {
363                                                if(listbox->aktline < listbox->linecount)
364                                                        listbox->aktline ++;
365                                                        if(flag == 1)
366                                                        {
367                                                                //apskin->hidden = YES;
368                                                                //delownerrc(apskin);
369                                                                drawscreen(skin, 0, 0);
370                                                        }
371                                                else
372                                                {
373                                                        status.play = 1;
374                                                        skiprcok = 1;
375                                                }
376                                        }
377                                        else if(*eof == 2)
378                                        {
379                                                if(listbox->aktline == 1)
380                                                {
381                                                        status.play = 1;
382                                                        if(screensaver != NULL && screensaver->type == 3 && flag == 2)
383                                                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
384                                                        skiprcok = 1;
385                                                }
386                                                else
387                                                {
388                                                        listbox->aktline --;
389                                                        if(flag == 1)
390                                                        {
391                                                                //apskin->hidden = YES;
392                                                                //delownerrc(apskin);
393                                                                drawscreen(skin, 0, 0);
394                                                        }
395                                                        // workaround dont open folder on rcchup
396                                                        *skip = 1;
397                                                }
398                                        }
399
400                                        *eof = 0;
401
402                                        debug(50, "listbox->aktline: %d", listbox->aktline);
403                                        debug(50, "listbox->linecount: %d", listbox->linecount);
404                                }
405                        }
406                        delownerrc(apskin);
407                        if(switchtofilelist == 0)
408                                addscreenrc(apskin, listbox);
409                        else
410                                addscreenrc(apskin, filelist);                 
411                }
412                else if (flag != 4)
413                {
414//                      changetext(b2, _("Filelist-Mode"));
415                        changetext(b2, _("Playlist"));
416                       
417               
418                        if(screensaver != NULL && screensaver->type == 3 && flag == 2)
419                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
420
421                        if(flag != 3)
422                                drawscreen(apskin, 0, 0);
423
424                        if(status.random == 1 && status.repeat == 0)
425                        {
426                                int maxdirs = 0, maxfiles = 0;
427                                getfilelistmax(filelist, &maxdirs, &maxfiles);
428                                struct skin* tmplist = getfilelistrandom(filelist, maxdirs, maxfiles);
429                                debug(50, "struct skin xtext=%s", tmplist->text);
430                                if(tmplist != NULL)
431                                {
432                                        debug(50, "struct skin randomtext=%s", tmplist->text);
433                                        setlistboxselection(filelist, tmplist->name);
434                                }
435                        }
436                        else
437                        {
438                                if(status.repeat == 0)
439                                {
440                                        debug(50, "writerc: rcdown next file");
441
442                                        debug(50, "filelist->aktline: %d", filelist->aktline);
443                                        debug(50, "filelist->linecount: %d", filelist->linecount);
444
445                                        if(*eof == 0)
446                                        {
447                                                if(filelist->aktline < filelist->linecount)
448                                                {
449                                                        filelist->aktline ++;
450                                                }
451                                                else
452                                                {                                                       
453                                                        if(flag != 3)
454                                                                playrcstop(playertype, flag);
455                                                        if((flag == 1) || (flag == 3))
456                                                        {
457                                                                if(flag == 3)
458                                                                {
459                                                                        picplayer(picscreen, picture, picname, NULL, 0);
460                                                                        clearscreen(picscreen);
461                                                                }
462
463                                                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
464
465                                                                apskin->hidden = NO;
466                                                                filelist->hidden = NO;
467                                                                listbox->hidden = YES;
468
469                                                                // switch filelist
470                                                                delownerrc(apskin);
471                                                                addscreenrc(apskin, filelist);
472
473                                                                setfbtransparent(255);
474                                                        }
475                                                        else
476                                                        {
477                                                                if(screensaver != NULL && screensaver->type == 3 && flag == 2)
478                                                                        singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
479                                                        }
480                                                        skiprcok = 1;
481                                                }
482
483                                        }
484                                        else if(*eof == 1)
485                                        {
486                                                if(filelist->aktline < filelist->linecount)
487                                                        filelist->aktline ++;
488                                                else
489                                                {
490                                                        status.play = 1;
491                                                        skiprcok = 1;
492                                                }
493                                        }
494                                        else if(*eof == 2)
495                                        {
496                                                if(filelist->aktline == 1)
497                                                {
498                                                        status.play = 1;
499                                                        if(screensaver != NULL && screensaver->type == 3 && flag == 2)
500                                                                singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
501                                                        skiprcok = 1;
502                                                }
503                                                else
504                                                {
505                                                        filelist->aktline --;
506                                                        // workaround dont open folder on rcchup
507                                                        *skip = 1;
508                                                }
509                                        }
510
511                                        *eof = 0;
512
513                                        debug(50, "filelist->aktline: %d", filelist->aktline);
514                                        debug(50, "filelist->linecount: %d", filelist->linecount);
515                                }
516                        }
517                        delownerrc(apskin);
518                        addscreenrc(apskin, filelist);
519                }
520
521                debug(50, "flag: %d", flag);
522                debug(50, "skiprcok: %d", skiprcok);                                   
523
524                if(flag == 4)
525                {
526                        skiprcok = 1;
527                        singlepicstart("/var/usr/local/share/titan/plugins/mc/skin/default.mvi", 0);
528                        drawscreen(apskin, 0, 0);
529                }
530                else if(flag == 3 && skiprcok == 0)
531                        drawscreen(apskin, 2, 0);
532                else
533                        drawscreen(apskin, 0, 0);
534                       
535                if(skiprcok == 0)
536                        writerc(getrcconfigint("rcok", NULL));
537}
538
539void playerrandom(struct skin* apskin, struct skin* filelist, struct skin* listbox, struct skin* b3, int playlist, int flag)
540{
541        if(playlist == 0)
542        {
543                debug(50, "rcyellow: random");
544                if(status.random == 0)
545                {
546                        int maxdirs = 0, maxfiles = 0;
547                        getfilelistmax(filelist, &maxdirs, &maxfiles);
548                        struct skin* tmplist = getfilelistrandom(filelist, maxdirs, maxfiles);
549
550                        if(tmplist != NULL)
551                        {
552                                debug(50, "struct skin randomtext=%s", tmplist->text);
553                                setlistboxselection(filelist, tmplist->name);
554//                              if(flag == 2)
555                                        changetext(b3, _("Random-On"));
556                                drawscreen(apskin, 0, 0);
557                                status.random = 1;
558                                debug(50, "writerc rcok");
559                                writerc(getrcconfigint("rcok", NULL));
560                        }
561                }
562                else
563                {
564                        status.random = 0;
565//                      if(flag == 2)
566                                changetext(b3, _("Random"));
567                        drawscreen(apskin, 0, 0);
568                }
569        }
570        else
571        {
572                debug(50, "rcyellow: random");
573                if(status.random == 0)
574                {
575                        int maxdirs = 0, maxfiles = 0;
576                        getplaylistmaxold(listbox, &maxdirs, &maxfiles);
577                        struct skin* tmplist = getplaylistrandomold(listbox, maxdirs, maxfiles);
578                        if(tmplist != NULL)
579                        {
580                                debug(50, "struct skin randomtext=%s", tmplist->text);
581                                setlistboxselection(listbox, tmplist->name);
582//                              if(flag == 2)
583                                        changetext(b3, _("Random-On"));
584                                drawscreen(apskin, 0, 0);
585                                status.random = 1;
586                                debug(50, "writerc rcok");
587                                writerc(getrcconfigint("rcok", NULL));
588                        }
589                }
590                else
591                {
592                        status.random = 0;
593//                      if(flag == 2)
594                                changetext(b3, _("Random"));
595                        drawscreen(apskin, 0, 0);
596                }
597        }
598}
599
600void showplaylist(struct skin* apskin, struct skin* filelistpath, struct skin* filelist, struct skin* listbox, struct skin* b2, int mode, int* playlist, int* eof, char** filename, char** currentdirectory, int* playertype, int flag)
601{
602        int playerret = 0;
603        struct skin* tmp = NULL;
604        struct mainplaylist* mplaylist = NULL;
605        struct playlist* playlistnode = NULL;
606        struct menulist* mlist = NULL, *mbox = NULL;
607        char* title = NULL;
608        int count = 0;
609
610        if(mode == 0)
611        {
612                debug(50, "rcgreenss: playlist menu");
613
614                addmenulist(&mlist, _("Load Playlist"), NULL, NULL, 0, 0);
615                addmenulist(&mlist, _("Edit Playlist"), NULL, NULL, 0, 0);
616               
617                mbox = menulistbox(mlist, "playlistmenu", _("Playlist Menu"), _("Choose your Playlist Mode from the following list"), "%pluginpath%/mc/skin", NULL, 1, 0);
618
619                drawscreen(apskin, 0, 0);
620
621                if(mbox != NULL)
622                {
623                        if(ostrcmp(mbox->name, _("Load Playlist")) == 0)
624                        {
625//                              *count = 0;
626//                              *rcwait = 1000;
627       
628                                status.playspeed = 0;
629                                status.pause = 0;
630                                status.play = 0;
631
632                                mplaylist = screenmainplaylist(1);
633                                drawscreen(apskin, 0, 0);
634
635                                if(mplaylist != NULL && mplaylist->playlist != NULL)
636                                {
637                                        playlistnode = NULL;
638                                        playlistnode = mplaylist->playlist;
639                                        if(playlistnode->file != NULL)
640                                        {
641                                                *filename = ostrcat("", playlistnode->file, 0, 0);
642                                                playrcstop(*playertype, flag);
643
644                                                count = 0;
645
646                                                // clear listbox, not working ?
647                                                delmarkedscreennodes(apskin, 2);
648
649                                                char* firsttitle = NULL;
650                                                while(playlistnode != NULL)
651                                                {
652                                                        tmp = addlistbox(apskin, listbox, tmp, 2);
653                                                        if(tmp != NULL)
654                                                        {
655                                                                int count1 = 0;
656                                                                char* tmpstr1 = NULL;
657                                                                tmpstr1 = ostrcat("", playlistnode->file, 0, 0);
658
659                                                                int i = 0;
660                                                                struct splitstr* ret1 = NULL;
661                                                                ret1 = strsplit(tmpstr1, "/", &count1);
662                                                                if(count1 >= 1)
663                                                                        i = count1 - 1;
664                                                                count ++;
665                                                                debug(50, "addlistbox (%d) %s", count, playlistnode->file);
666
667                                                                title = ostrcat("(", oitoa(count), 0, 1);
668                                                                if(count < 10)
669                                                                        title = ostrcat(title, ")    ", 1, 0);
670                                                                else if(count < 100)
671                                                                        title = ostrcat(title, ")   ", 1, 0);
672                                                                else
673                                                                        title = ostrcat(title, ")  ", 1, 0);
674
675                                                                title = ostrcat(title, (&ret1[i])->part, 1, 0);
676                                                                changetext(tmp, _(title));
677
678                                                                if(firsttitle == NULL)
679                                                                        firsttitle = ostrcat("", title, 0, 0);                 
680
681                                                                free(ret1), ret1 = NULL;
682                                                                free(tmpstr1), tmpstr1 = NULL;
683
684                                                                // new
685
686                                                                changename(tmp, playlistnode->file);
687                                                                tmp->handle = (char*)playlistnode;
688                                                                tmp->del = 2;
689                                                        }
690                                                        playlistnode = playlistnode->next;
691                                                }
692
693                                                *currentdirectory = ostrcat("Playlist: ", mplaylist->name, 0, 0);
694                                                changetext(filelistpath, _(*currentdirectory));
695                                                filelist->hidden = YES;
696                                                listbox->hidden = NO;
697
698                                                // workaround playereof
699                                                playlistnode = NULL;
700                                                playlistnode = mplaylist->playlist;
701
702                                                setlistboxselection(listbox, *filename);
703                                                if(firsttitle == NULL)
704                                                        firsttitle = ostrcat("", "dummy no read title", 0, 0);                                         
705
706                                                title = ostrcat("", firsttitle, 0, 0);
707//                                              changetext(b2, _("Playlist-Mode"));
708                                                changetext(b2, _("Playlist"));
709
710                                                if(screensaver != NULL && screensaver->type == 0)
711                                                        screensaver->value = title;
712
713                                                delownerrc(apskin);
714                                                addscreenrc(apskin, listbox);
715                                                drawscreen(apskin, 0, 0);
716                                                // show playlist end   
717                                                sleep(1);
718
719                                                if(flag == 1  && status.play == 1)
720                                                {
721                                                        servicestop(status.aktservice, 1, 1);
722                                                        drawscreen(skin, 0, 0);
723                                                        setfbtransparent(255);
724                                                        debug(50, "check");
725                                                        debug(50, "autostart_playlist: %d", getconfigint("mc_vp_autostart_playlist", NULL));
726                                                        debug(50, "status.play: %d", status.play);
727                                                        debug(50, "flag: %d", flag);
728                                                }
729                                                else if(flag == 2  && status.play == 1)
730                                                {
731                                                        addscreenrc(apskin, listbox);
732                                                        drawscreen(apskin, 0, 0);
733                                                        debug(50, "check");
734                                                        debug(50, "autostart_playlist: %d", getconfigint("mc_ap_autostart_playlist", NULL));
735                                                        debug(50, "status.play: %d", status.play);                             
736                                                        debug(50, "flag: %d", flag);
737                                                }
738                       
739                                                if((getconfigint("mc_vp_autostart_playlist", NULL) == 1 && flag == 1 && status.play == 0) || (getconfigint("mc_ap_autostart_playlist", NULL) == 1 && flag == 2 && status.play == 0))
740                                                {
741                                                        debug(50, "-------------- check ok titan playlist pls --------------");
742                                                        debug(50, "playerstart: %s", *filename);
743                                                        debug(50, "flag: %d", flag);
744                                                        debug(50, "playertype: %d", *playertype);       
745                                                                                       
746                                                        if(flag == 1)
747                                                        {
748                                                                servicestop(status.aktservice, 1, 1);
749                                                                drawscreen(skin, 0, 0);
750                                                                setfbtransparent(255);
751                                                                debug(50, "check");
752                                                                debug(50, "autostart_playlist: %d", getconfigint("mc_vp_autostart_playlist", NULL));
753                                                                debug(50, "status.play: %d", status.play);
754                                                        }
755                                                        else if(flag == 2)
756                                                        {
757                                                                addscreenrc(apskin, listbox);
758                                                                drawscreen(apskin, 0, 0);
759                                                                debug(50, "check");
760                                                                debug(50, "autostart_playlist: %d", getconfigint("mc_ap_autostart_playlist", NULL));
761                                                                debug(50, "status.play: %d", status.play);                             
762                                                        }
763                       
764//                                                      playerret = playerstart(*filename);
765                                                        if(getconfigint("playertype", NULL) == 1 && cmpfilenameext(*filename, ".ts") == 0 && ostrstr(*filename, "://") == NULL)
766                                                                *playertype = 1;
767                                                        else
768                                                                *playertype = 0;
769                                       
770                                                        if(*playertype == 1)
771                                                                playerret = playerstartts(*filename, 0);
772                                                        else
773                                                                playerret = playerstart(*filename);
774                                       
775                                                        playwritevfd(*filename, NULL);
776                               
777       
778                                                        #ifndef SIMULATE
779                                                        if(playerret != 0)
780                                                        {
781                                                                textbox(_("Message"), _("Can't start playback !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
782                                                                *eof = 1;
783                                                        }
784                                                        #endif
785       
786                                                        status.play = 1;
787                                                }
788                                                *playlist = 1;
789                                                free(firsttitle), firsttitle = NULL;
790                                        }
791                                }
792                        }
793                        else
794                        {
795                                screenmainplaylist(0);
796                                writeallconfig(0);
797                                drawscreen(apskin, 0, 0);
798                        }
799                        freemenulist(mlist, 1);
800                }
801        }
802        else
803        {
804                FILE *fd = NULL;
805                char *fileline = NULL;
806                int linecount = 0;
807                int httpstream = 0;
808
809                fileline = malloc(MINMALLOC);
810                if(fileline == NULL)
811                {
812                        err("no memory");
813                        return;
814                }
815
816                fd = fopen(*filename, "r");
817                if(fd == NULL)
818                {
819                        perr("can't open %s", *filename);
820                        free(fileline);
821                        return;
822                }
823               
824                // clear listbox, not working ?
825                delmarkedscreennodes(apskin, 2);
826
827                char* firstfile = NULL;
828                char* firsttitle = NULL;
829                char* extra = NULL;
830                while(fgets(fileline, MINMALLOC, fd) != NULL)
831                {
832                        int addcurrdir = 0;
833
834                        if(ostrstr(fileline, "#EXTM3U") != NULL)
835                                continue;
836                        if(fileline[0] == '#' || fileline[0] == '\n' || fileline[0] == '\r')
837                        {
838
839                                if(fileline[strlen(fileline) - 1] == '\n')
840                                        fileline[strlen(fileline) - 1] = '\0';
841                                if(fileline[strlen(fileline) - 1] == '\r')
842                                        fileline[strlen(fileline) - 1] = '\0';
843
844                                printf("fileline: %s\n", fileline);
845
846//                              extra = ostrcat(fileline, NULL, 0, 0);
847//                              extra = stringreplacechar(extra, '\n', '\0');
848                                extra = oregex(".*,(.*).*", fileline);
849                                printf("set extra: %s\n", extra);
850                                continue;
851                        }
852                        if(fileline[0] == '/')
853                                addcurrdir = 1;
854//                      if(strlen(fileline) >= 6 && fileline[4] == ':' && fileline[5] == '/' && fileline[6] == '/')
855                        if(ostrstr(fileline, "://") != NULL)
856                        {
857                                addcurrdir = 1;
858                                httpstream = 1;
859                        }
860                        if(fileline[strlen(fileline) - 1] == '\n')
861                                fileline[strlen(fileline) - 1] = '\0';
862                        if(fileline[strlen(fileline) - 1] == '\r')
863                                fileline[strlen(fileline) - 1] = '\0';
864
865                        linecount++;
866
867                        tmp = addlistbox(apskin, listbox, tmp, 2);
868                        if(tmp != NULL)
869                        {
870                                int count1 = 0;
871                                char* tmpstr1 = NULL;
872                                tmpstr1 = ostrcat("", fileline, 0, 0);
873
874                                int i = 0;
875                                struct splitstr* ret1 = NULL;
876                                ret1 = strsplit(tmpstr1, "/", &count1);
877                                if(count1 >= 1)
878                                        i = count1 - 1;
879                                count ++;
880
881                                debug(50, "title1: %s", title);
882
883                                title = ostrcat("(", oitoa(count), 0, 1);
884                                debug(50, "title2: %s", title);
885
886                                if(count < 10)
887                                        title = ostrcat(title, ")    ", 1, 0);
888                                else if(count < 100)
889                                        title = ostrcat(title, ")   ", 1, 0);
890                                else
891                                        title = ostrcat(title, ")  ", 1, 0);
892
893                                debug(50, "title3: %s", title);
894
895//                              struct splitstr* ret2 = NULL;
896//                              title = ostrcat(title, extra, 1, 0);
897//                              ret2 = strsplit(tmpstr2, ",", &count2);
898
899                                if(extra != NULL)
900                                        title = ostrcat(title, extra, 1, 0);
901                                else if(ret1 != NULL)
902                                        title = ostrcat(title, (&ret1[i])->part, 1, 0);
903
904                                debug(50, "title4: %s", title);
905
906                                printf("extra2: %s\n", extra);
907
908                                if(title != NULL)
909                                {
910                                        title = string_replace("#EXTINF:-1,", "", title, 1);
911                                        title = string_replace("#EXTINF:,", "", title, 1);
912                                        title = string_replace("#EXTINF,", "", title, 1);
913                                        title = string_replace("#", "", title, 1);
914                                }
915
916                                debug(50, "#########################");
917
918                                debug(50, "title5: %s", title);
919                                debug(50, "fileline: %s", fileline);
920                                debug(50, "#########################");
921
922                                debug(50, "addlistbox (%d) %s: %s", count, title, fileline);
923
924                                changetext(tmp, _(title));
925
926                                if(extra != NULL)
927                                {
928                                        free(extra), extra = NULL;
929                                        free(title), title = NULL;
930                                }
931
932                                if(firstfile == NULL)
933                                {
934                                        if(addcurrdir == 0)
935                                        {
936                                                if(flag == 1)
937                                                        firstfile = ostrcat(getconfig("mc_vp_path", NULL), "/", 0, 0);
938                                                else if(flag == 2)
939                                                        firstfile = ostrcat(getconfig("mc_ap_path", NULL), "/", 0, 0);
940
941                                                firstfile = ostrcat(firstfile, fileline, 1, 0);
942                                        }
943                                        else
944                                                firstfile = ostrcat("", fileline, 0, 0);
945
946                                        firsttitle = ostrcat("", title, 0, 0);                 
947                                }
948                                free(ret1), ret1 = NULL;
949                                free(tmpstr1), tmpstr1 = NULL;
950
951                                if(addcurrdir == 0)
952                                {                                       
953                                        char* tmpstr3 = NULL;
954
955                                        if(flag == 1)
956                                                tmpstr3 = ostrcat(getconfig("mc_vp_path", NULL), "/", 0, 0);
957                                        else if(flag == 2)
958                                                tmpstr3 = ostrcat(getconfig("mc_ap_path", NULL), "/", 0, 0);
959
960                                        tmpstr3 = ostrcat(tmpstr3, fileline, 1, 0);
961                                        changename(tmp, tmpstr3);
962                                        free(tmpstr3), tmpstr3 = NULL;
963                                }
964                                else
965                                        changename(tmp, fileline);
966
967
968                                //tmp->handle = (char*)fileline;
969                                tmp->del = 2;
970                        }
971                }
972
973                if(*filename[0] == '/')
974                {
975                        int count3 = 0;
976                        char* tmpstr3 = NULL;
977                        char* title = NULL;
978                        tmpstr3 = ostrcat("", *filename, 0, 0);
979
980                        struct splitstr* ret3 = NULL;
981                        ret3 = strsplit(tmpstr3, "/", &count3);
982                        count = count3 - 1;
983                        title = ostrcat("", (&ret3[count])->part, 0, 0);
984                        *currentdirectory= ostrcat("Playlist: ", title, 0, 0);
985                        free(ret3), ret3 = NULL;
986                        free(tmpstr3), tmpstr3 = NULL;
987                        free(title), title = NULL;
988                }
989                else
990                {
991                        *currentdirectory= ostrcat("Playlist: ", *filename, 0, 0);
992                }
993
994                changetext(filelistpath, _(*currentdirectory));
995
996                filelist->hidden = YES;
997                listbox->hidden = NO;
998
999//              changetext(b2, _("Playlist-Mode"));
1000                changetext(b2, _("Playlist"));
1001                delownerrc(apskin);
1002                addscreenrc(apskin, listbox);
1003                drawscreen(apskin, 0, 0);
1004                // show playlist end   
1005
1006                if(firstfile != NULL)
1007                {
1008                        playrcstop(*playertype, flag);
1009                        setlistboxselection(listbox, *filename);
1010                        *filename = ostrcat("", firstfile, 0, 0);
1011                        title = ostrcat("", firsttitle, 0, 0);
1012
1013                        //if(flag == 2)
1014//                              changetext(b2, _("Playlist-Mode"));
1015                                changetext(b2, _("Playlist"));
1016
1017                        if(screensaver != NULL && screensaver->type == 0 && flag == 2)
1018                                screensaver->value = title;
1019
1020                        sleep(1);
1021
1022                        if(flag == 1  && status.play == 1)
1023                        {
1024                                servicestop(status.aktservice, 1, 1);
1025                                drawscreen(skin, 0, 0);
1026                                setfbtransparent(255);
1027                                debug(50, "check");
1028                                debug(50, "autostart_playlist: %d", getconfigint("mc_vp_autostart_playlist", NULL));
1029                                debug(50, "status.play: %d", status.play);
1030                                debug(50, "flag: %d", flag);
1031                        }
1032                        else if(flag == 2  && status.play == 1)
1033                        {
1034                                addscreenrc(apskin, listbox);
1035                                drawscreen(apskin, 0, 0);
1036                                debug(50, "check");
1037                                debug(50, "autostart_playlist: %d", getconfigint("mc_ap_autostart_playlist", NULL));
1038                                debug(50, "status.play: %d", status.play);                             
1039                                debug(50, "flag: %d", flag);
1040                        }
1041
1042                        // show playlist end
1043                        if((getconfigint("mc_vp_autostart_playlist", NULL) == 1 && flag == 1 && status.play == 0) || (getconfigint("mc_ap_autostart_playlist", NULL) == 1 && flag == 2 && status.play == 0))
1044                        {
1045                                delownerrc(apskin);
1046                                debug(50, "-------------- check ok m3u --------------");
1047                                debug(50, "playerstart: %s", *filename);
1048                                debug(50, "flag: %d", flag);
1049                                debug(50, "playertype: %d", *playertype);
1050
1051                                if(flag == 1)
1052                                {
1053                                        servicestop(status.aktservice, 1, 1);
1054                                        drawscreen(skin, 0, 0);
1055                                        setfbtransparent(255);
1056                                        debug(50, "check");
1057                                        debug(50, "autostart_playlist: %d", getconfigint("mc_vp_autostart_playlist", NULL));
1058                                        debug(50, "status.play: %d", status.play);
1059                                }
1060                                else if(flag == 2)
1061                                {
1062                                        addscreenrc(apskin, listbox);
1063                                        drawscreen(apskin, 0, 0);
1064                                        debug(50, "check");
1065                                        debug(50, "autostart_playlist: %d", getconfigint("mc_ap_autostart_playlist", NULL));
1066                                        debug(50, "status.play: %d", status.play);                             
1067                                }
1068
1069//                              playerret = playerstart(*filename);
1070                                if(getconfigint("playertype", NULL) == 1 && cmpfilenameext(*filename, ".ts") == 0)
1071                                        *playertype = 1;
1072                                else
1073                                        *playertype = 0;
1074               
1075                                if(*playertype == 1)
1076                                        playerret = playerstartts(*filename, 0);
1077                                else
1078                                        playerret = playerstart(*filename);
1079
1080                                playwritevfd(*filename, NULL);
1081                               
1082                                //playwritevfd(*filename, NULL);
1083                                #ifndef SIMULATE
1084                                        if(playerret != 0)
1085                                        {
1086                                                textbox(_("Message"), _("Can't start playback !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1087
1088                                                *eof = 1;
1089                                        }
1090                                #endif
1091       
1092                                status.play = 1;
1093                                if(flag == 1)
1094                                        screenplayinfobar(*filename, NULL, 0, 0, 0);
1095                        }                               
1096
1097                        *playlist = 1;
1098
1099                        free(fileline), fileline = NULL;
1100                        free(firstfile), firstfile = NULL;
1101                        free(firsttitle), firsttitle = NULL;
1102                }
1103                fclose(fd);
1104        }
1105}
1106
1107void mc_audioplayer_infobar(struct skin* apskin, struct skin* infobar, struct skin* spos, struct skin* slen, struct skin* sreverse, struct skin* sprogress, struct skin* b12, struct skin* b13, char* filename)
1108{
1109        debug(50, "infobar start");
1110
1111        char* tmpstr = NULL;
1112        unsigned long long int pos = 0, len = 0, reverse = 0;
1113
1114        pos = playergetpts() / 90000;
1115        len = playergetlength();
1116        reverse = len - pos;
1117
1118        debug(50, "pos: %llu", pos);
1119        debug(50, "len: %llu", len);
1120        debug(50, "reverse: %llu", reverse);
1121
1122        if(len == 0)
1123                sprogress->progresssize = 0;
1124        else
1125                sprogress->progresssize = pos * 100 / len;
1126
1127        tmpstr = convert_timesec(pos);
1128        changetext(spos, _(tmpstr));
1129        free(tmpstr); tmpstr = NULL;
1130
1131        tmpstr = convert_timesec(len);
1132        changetext(slen, _(tmpstr));
1133        free(tmpstr); tmpstr = NULL;
1134
1135        tmpstr = convert_timesec(reverse);
1136        changetext(sreverse, _(tmpstr));
1137        free(tmpstr); tmpstr = NULL;
1138
1139        if(status.random == 1)
1140                changetext(b12, _("Random-On"));
1141        else
1142                changetext(b12, _("Random"));   
1143
1144        if(status.repeat == 1)
1145                changetext(b13, _("Repeat-On"));
1146        else
1147                changetext(b13, _("Repeat"));
1148
1149        drawscreen(infobar, 0, 0);
1150}
1151
1152void picplayer(struct skin* picscreen, struct skin* picture, struct skin* picname, char* filename, int flag)
1153{
1154        if(filename == NULL)
1155        {
1156                clearscreen(picscreen);
1157                drawscreen(skin, 0, 0);
1158                return;
1159        }
1160
1161        char* tmpstr = NULL;
1162
1163        tmpstr = ostrcat(filename, "", 0, 0);
1164
1165        if(getconfigint("mc_pp_showpictitle", NULL) == 1 && tmpstr != NULL) changetext(picname,_((basename(tmpstr))));
1166        free(tmpstr); tmpstr = NULL;
1167
1168        changepic(picture, filename);
1169        picture->picwidth = 1;
1170        picture->picheight = 1;
1171        picture->bgcol = 0;
1172        picture->picquality = getconfigint("mc_pp_picquality", NULL);
1173
1174        drawscreen(picscreen, 0, 4);
1175}
1176
1177#include <stdio.h>
1178#include <curl/curl.h>
1179
1180/* This callback is, currently, a simple wrapper around fwrite(). You
1181   could get it to write to memory, or do anything else you'd like
1182   with the output. For more info, see
1183   http://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
1184 */
1185
1186struct MemoryStruct {
1187  char *memory;
1188  size_t size;
1189};
1190
1191static size_t
1192WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
1193{
1194  size_t realsize = size * nmemb;
1195  struct MemoryStruct *mem = (struct MemoryStruct *)userp;
1196 
1197  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
1198  if(mem->memory == NULL) {
1199        /* out of memory! */
1200        printf("not enough memory (realloc returned NULL)\n");
1201        return 0;
1202  }
1203 
1204  memcpy(&(mem->memory[mem->size]), contents, realsize);
1205  mem->size += realsize;
1206  mem->memory[mem->size] = 0;
1207 
1208  return realsize;
1209}
1210
1211static size_t writeCallback(void *contents, size_t size, size_t nitems, FILE *file) {
1212  return fwrite(contents, size, nitems, file);
1213}
1214
1215// flag = 0 (without header in output)
1216// flag = 1 (with header in output)
1217char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, char* referer, int flag)
1218{
1219        debug(99, "url: %s", url);
1220
1221        int debuglevel = getconfigint("debuglevel", NULL);
1222
1223        char* tmpstr = NULL;
1224        FILE *fp;
1225
1226        CURL *curl_handle;
1227        CURLcode res;
1228       
1229        struct MemoryStruct chunk;
1230       
1231        chunk.memory = malloc(1);  /* will be grown as needed by the realloc above */
1232        chunk.size = 0;    /* no data at this point */
1233       
1234        curl_global_init(CURL_GLOBAL_ALL);
1235
1236        /* init the curl session */
1237        curl_handle = curl_easy_init();
1238        if(curl_handle)
1239        {
1240                if(localfile != NULL)
1241                    fp = fopen(localfile,"wb");
1242               
1243                /* specify URL to get */
1244                curl_easy_setopt(curl_handle, CURLOPT_URL, url);
1245
1246                if(user != NULL && pass != NULL)
1247                {
1248                        curl_easy_setopt(curl_handle, CURLOPT_USERNAME, user);
1249                        curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, pass);
1250                        curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
1251                }
1252                if(data == NULL)
1253                        curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1L);
1254                else
1255                {
1256                        curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
1257                        curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
1258
1259                        /* example.com is redirected, so we tell libcurl to send POST on 301, 302 and
1260                        303 HTTP response codes */
1261                        curl_easy_setopt(curl_handle, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
1262                }
1263                if(flag == 1)
1264                        curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1L);
1265                curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
1266                curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 3);
1267//              curl_easy_setopt(curl_handle, CURLOPT_RETURNTRANSFER, 1);
1268
1269                if(localfile == NULL)
1270                {
1271                        /* send all data to this function  */
1272                        curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
1273                }
1274                else
1275                {
1276                        /* When data arrives, curl will call writeCallback. */
1277                        curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCallback);
1278                }
1279
1280
1281
1282                if(localfile == NULL)
1283                {
1284                        /* we pass our 'chunk' struct to the callback function */
1285                        curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
1286                }
1287                else
1288                {
1289                        /* The last argument to writeCallback will be our file: */
1290                        curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)fp);
1291                }
1292
1293                /* some servers don't like requests that are made without a user-agent field, so we provide one */
1294//              curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
1295                curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.7.3000 Chrome/30.0.1599.101 Safari/537.36");
1296
1297                // This is occassionally required to stop CURL from verifying the peers certificate.
1298                // CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if
1299                // CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a
1300                // common name and also verify that it matches the hostname provided)
1301#ifdef MIPSEL
1302                curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L);
1303#else
1304                curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
1305#endif
1306
1307                curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
1308                if(debuglevel == 99)
1309                        curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
1310                curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "/mnt/network/cookies");
1311                curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "/mnt/network/cookies");
1312                /* enable redirect following */
1313                curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
1314                /* allow three redirects */
1315                curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
1316
1317
1318                /* enable all supported built-in compressions */
1319                curl_easy_setopt(curl_handle, CURLOPT_ACCEPT_ENCODING, "");
1320 
1321                if(referer == NULL)
1322                        curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L);
1323                else
1324                        curl_easy_setopt(curl_handle, CURLOPT_REFERER, referer);
1325
1326
1327                /* get it! */
1328                res = curl_easy_perform(curl_handle);
1329
1330                /* check for errors */
1331                if(res != CURLE_OK)
1332                {
1333                        err("failed: %s", curl_easy_strerror(res));
1334                        printf("curl error\n");
1335                }
1336                else
1337                {
1338                        /*
1339                         * Now, our chunk.memory points to a memory block that is chunk.size
1340                         * bytes big and contains the remote file.
1341                         *
1342                         * Do something nice with it!
1343                         */
1344                        printf("%lu bytes retrieved\n", (long)chunk.size);
1345                }
1346               
1347                /* cleanup curl stuff */
1348                curl_easy_cleanup(curl_handle);
1349                if(localfile != NULL)
1350                        fclose(fp);
1351        }
1352
1353        if(localfile == NULL)
1354                tmpstr = ostrcat(chunk.memory, NULL, 0, 0);
1355
1356        free(chunk.memory);
1357        /* we're done with libcurl, so clean it up */
1358
1359        curl_global_cleanup();
1360
1361        if(localfile != NULL)
1362                free(tmpstr), tmpstr = NULL;
1363
1364        return tmpstr;
1365}
1366
1367int update_iptv(char* file)
1368{
1369        char* tmpstr = NULL, *link = NULL;
1370        int ret = 0;
1371
1372        tmpstr = dirname(file);
1373        link = getconfig("iptvserver", NULL);
1374
1375        if(link != NULL)
1376        {
1377                debug(10, "update %s", link);
1378
1379                if(!file_exist(tmpstr))
1380                        mkdir(tmpstr, 0777);
1381
1382                tmpstr = ostrcat(tmpstr, "/iptv.m3u", 1, 0);
1383                if(file_exist(tmpstr))
1384                        unlink(tmpstr);
1385
1386                if(!file_exist(tmpstr))
1387                        gethttps(link, tmpstr, NULL, NULL, NULL, NULL, 0);
1388
1389                if(file_exist(tmpstr)) ret = 1;
1390
1391        }
1392
1393        free(tmpstr), tmpstr = NULL;
1394        free(link), link = NULL;
1395
1396        return ret;
1397}
1398
1399#endif
Note: See TracBrowser for help on using the repository browser.