-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyctrl_stream.cpp
4512 lines (4366 loc) · 316 KB
/
myctrl_stream.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <string.h>
#include <mysql.h>
#include <GL/glc.h>
#include <pthread.h> // multi thread support
#include <libxml/parser.h>
#include <sys/stat.h>
#include <time.h>
#include <cmath>
#include <iostream>
#include <fmt/format.h>
#include "myctrl_stream.h"
#include "utility.h"
#include "myth_ttffont.h"
#include "utility.h"
#include "readjpg.h"
#include "loadpng.h"
#include "myctrl_glprint.h"
// web file loader
#include "myctrl_readwebfile.h"
//
// text render is glcRenderString for freetype font support (slow)
// new text render in use drawText()
//
extern long configrssguidelastupdate;
extern FILE *logfile;
extern char localuserhomedir[4096]; // user homedir set in main
extern char debuglogdata[1024]; // used by log system
extern char debuglogdata[1024]; // used by log system
extern float configdefaultstreamfontsize;
extern int tema;
extern char *dbname; // internal database name in mysql (music,movie,radio)
extern char configmysqluser[256]; //
extern char configmysqlpass[256]; //
extern char configmysqlhost[256]; //
extern char configmusicpath[256];
extern int configmythtvver;
extern int screen_size;
extern int screensizey;
extern int screeny;
// debug mode
// 1 = wifi net
// 2 = music
// 4 = stream
// 8 = keyboard/mouse move
// 16 = movie
// 32 = searcg
extern int debugmode; // 64 = radio station land icon loader
// 128= stream search
// 256 = tv program stuf
// 512 = media importer
// 1024 = flag loader
extern unsigned int musicoversigt_antal; //
extern int do_stream_icon_anim_icon_ofset; //
extern GLuint radiooptions,radiooptionsmask; //
extern GLuint _textureIdback; // back icon
extern GLuint newstuf_icon; //
extern int fonttype;
extern fontctrl aktivfont;
extern int orgwinsizey,orgwinsizex;
extern int _sangley;
extern GLuint _textureIdloading,_textureIdloading1;
//extern GLuint _textureIdloading_mask;
// stream mask
extern GLuint onlinestreammask;
extern GLuint onlinestreammaskicon; // icon mask on web icon
extern stream_class streamoversigt;
extern GLint cur_avail_mem_kb;
extern bool stream_loadergfx_started;
extern bool stream_loadergfx_started_done;
extern bool stream_loadergfx_started_break;
// constructor
stream_class::stream_class() : antal(0) {
int i;
for(i=0;i<maxantal;i++) stack[i]=0;
stream_optionselect=0; // selected line in stream options
stream_oversigt_loaded=false;
stream_oversigt_loaded_nr=0;
antal=0;
gfx_loaded=false; // gfx loaded
stream_is_playing=false; // is we playing any media
stream_is_pause=false; // is player on pause
}
// destructor
stream_class::~stream_class() {
clean_stream_oversigt();
}
// return the name
char *stream_class::get_stream_name(int nr) {
if (nr<antal) return (stack[nr]->feed_name); else return (NULL);
}
// return the description
char *stream_class::get_stream_desc(int nr) {
if (nr<antal) return (stack[nr]->feed_desc); else return (NULL);
}
// clean up number of created
void stream_class::clean_stream_oversigt() {
startup_loaded=false; // set radio station loaded in
for(int i=1;i<antal;i++) {
if (stack[i]->textureId) glDeleteTextures(1, &stack[i]->textureId); // delete stream texture
//if (stack[i]) delete stack[i]; // delete radio station
}
antal=0;
stream_oversigt_loaded=false; // set load icon texture again
stream_oversigt_loaded_nr=0;
stream_oversigt_nowloading=0;
}
// set en stream icon image
void stream_class::set_texture(int nr,GLuint idtexture) {
stack[nr]->textureId=idtexture;
}
//
// vlc player interface
//
// default player
// stop playing stream sound or video
void stream_class::stopstream() {
if ((vlc_in_playing()) && (stream_is_playing)) vlc_controller::stopmedia();
stream_is_playing=false;
}
// ****************************************************************************************
//
// vlc stop player
//
// ****************************************************************************************
void stream_class::softstopstream() {
if ((vlc_in_playing()) && (stream_is_playing)) vlc_controller::stopmedia();
stream_is_playing=false;
}
// get length on stream
//
// ****************************************************************************************
unsigned long stream_class::get_length_in_ms() {
vlc_controller::get_length_in_ms();
return(1);
}
// jump in player
//
// ****************************************************************************************
float stream_class::jump_position(float ofset) {
ofset=vlc_controller::jump_position(ofset);
return(ofset);
}
// to play streams from web
//vlc_m = libvlc_media_new_location(vlc_inst, "http://www.ukaff.ac.uk/movies/cluster.avi");
// pause stream
//
// ****************************************************************************************
int stream_class::pausestream(int pause) {
//stream_is_playing=true;
vlc_controller::pause(1);
if (!(stream_is_pause)) stream_is_pause=true; else stream_is_pause=false;
return(1);
}
// ****************************************************************************************
// start playing movie by vlclib
//
// ****************************************************************************************
int stream_class::playstream(int nr) {
char path[PATH_MAX]; // max path length from os
strcpy(path,"");
strcat(path,get_stream_url(nr));
stream_is_playing=true;
vlc_controller::playmedia(path);
return(1);
}
// ****************************************************************************************
//
// ****************************************************************************************
int stream_class::playstream_url(char *path) {
stream_is_playing=true;
vlc_controller::playwebmedia(path);
return(1);
}
// ****************************************************************************************
//
// ****************************************************************************************
float stream_class::getstream_pos() {
return(vlc_controller::get_position());
}
// ****************************************************************************************
// update nr of view on podcast
//
// ****************************************************************************************
void stream_class::update_rss_nr_of_view(char *url) {
// mysql vars
std::string sqlinsert;
MYSQL *conn;
MYSQL_RES *res,*res1;
MYSQL_ROW row;
char *database = (char *) "mythtvcontroller";
conn=mysql_init(NULL);
// get homedir
try {
if (conn) {
mysql_real_connect(conn, configmysqlhost,configmysqluser, configmysqlpass, database, 0, NULL, 0);
sqlinsert = fmt::v8::format("update mythtvcontroller.internetcontentarticles set time=time+1 where mediaURL like '{}'",url);
mysql_query(conn,sqlinsert.c_str());
res = mysql_store_result(conn);
mysql_free_result(res);
mysql_close(conn);
}
}
catch (...) {
printf("Error open mysql connection.\n");
}
}
// ****************************************************************************************
//
// used to download rss file from web to db info (url is flag for master rss file (mediaURL IS NULL))
// in db if mediaURL have url this is the rss feed loaded from rss file
// updaterssfile bool is do it now (u key in overview)
//
// ****************************************************************************************
int stream_class::loadrssfile(bool updaterssfile) {
bool haveupdated=false;
char sqlselect[2048];
char sqlinsert[32768];
char totalurl[2048];
char parsefilename[2048];
char homedir[2048];
char baseicon[2048];
char temptxt[2024];
unsigned int recantal;
MYSQL *conn;
MYSQL_RES *res,*res1;
MYSQL_ROW row;
time_t timenow;
char *database = (char *) "mythtvcontroller";
struct stat attr;
const int updateinterval=86400;
time(&timenow);
bool set_update_rss=false;
conn=mysql_init(NULL);
// get homedir
strcpy(homedir,localuserhomedir);
strcat(homedir,"/rss");
if (!(file_exists(homedir))) mkdir(homedir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
strcat(homedir,"/images");
if (!(file_exists(homedir))) mkdir(homedir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (configrssguidelastupdate==0) {
configrssguidelastupdate=time(NULL);
set_update_rss=false;
} else {
if ((configrssguidelastupdate+600)<=time(NULL)) {
set_update_rss=true;
//configrssguidelastupdate=time(NULL);
}
}
if (updaterssfile==true) set_update_rss=true; // force update
if (set_update_rss) printf("set_update_rss %d configrssguidelastupdate = %ld time = %ld \n",set_update_rss,configrssguidelastupdate,time(NULL));
if ((conn) && (set_update_rss)) {
mysql_real_connect(conn, configmysqlhost,configmysqluser, configmysqlpass, database, 0, NULL, 0);
strcpy(sqlselect,"select count(mediaURL) from internetcontentarticles where mediaURL IS NULL");
mysql_query(conn,sqlselect);
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
recantal=atoi(row[0]);
}
mysql_free_result(res);
}
stream_rssparse_nowloading=0;
strcpy(sqlselect,"select * from internetcontentarticles where mediaURL is NULL");
mysql_query(conn,sqlselect);
res = mysql_store_result(conn);
// go to all record have the url in xml files to download
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
stream_rssparse_nowloading++;
printf("Get rss file %10s antal streams %d \n",row[0],antal_rss_streams());
// antalrss_feeds++;
snprintf(temptxt,sizeof(temptxt),"Get rss feed title %10s ",row[0]);
write_logfile(logfile,temptxt);
if ((row[3]) && (strcmp(row[3],"")!=0)) {
//getuserhomedir(homedir); // get user homedir
strcpy(homedir,localuserhomedir);
strcpy(totalurl,"wget -U Netscape --timeout=10 '");
if (row[7]) strcat(totalurl,row[7]); else if (row[3]) strcat(totalurl,row[3]);
strcat(totalurl,"' -o '");
strcat(totalurl,homedir); // add user homedir
strcat(totalurl,"/rss/wget.log'"); // log file
strcat(totalurl," -O '");
strcat(totalurl,homedir); // add user homedir
strcat(totalurl,"/rss/"); // add output filename
if (row[3]) strcat(totalurl,row[3]);
strcat(totalurl,".rss'");
strcpy(parsefilename,homedir); // copy user homedir
strcat(parsefilename,"/rss/");
strcat(parsefilename,row[3]);
strcat(parsefilename,".rss");
strcpy(baseicon,"");
stat(parsefilename, &attr);
if ((file_exists(parsefilename)) && (attr.st_mtime+updateinterval<timenow)) {
// download rss file
system(totalurl);
// parse file
strcpy(parsefilename,homedir);
strcat(parsefilename,"/rss/");
strcat(parsefilename,row[3]);
strcat(parsefilename,".rss");
// if podcast is rss
// if title ok and not podcast bud real rss feed
if ((strcmp(row[3],"")!=0) && (!(row[23]))) {
// parse downloaded xmlfile now (create db records)
parsexmlrssfile(parsefilename,baseicon);
}
} else if ((!(file_exists(parsefilename))) || (updaterssfile)) {
// download rss file
system(totalurl);
// parse file
strcpy(parsefilename,homedir);
strcat(parsefilename,"/rss/");
strcat(parsefilename,row[3]);
strcat(parsefilename,".rss");
// if podcast is rss
// if title ok and not podcast bud real rss feed
if ((strcmp(row[3],"")!=0) && (!(row[23]))) {
// parse downloaded xmlfile now (create db records)
// and get base image from funccall (baseicon (url to image))
parsexmlrssfile(parsefilename,baseicon);
//printf("... Parse %s rss file \n",parsefilename);
} else {
printf("XML FILE is missing/not working on %s file.\n",row[3]);
}
}
// update master icon if none
if ((strcmp(row[0],"")!=0) && (strcmp(baseicon,"")!=0)) {
snprintf(sqlinsert,sizeof(sqlinsert),"UPDATE internetcontentarticles set paththumb='%s' where feedtitle like '%s' and paththumb IS NULL",baseicon,row[0]);
mysql_query(conn,sqlinsert);
res1 = mysql_store_result(conn);
haveupdated=true;
}
// if podcast is not rss and title ok
if ((strcmp(row[3],"")!=0) && (row[23])) {
if (atoi(row[23])==1) {
snprintf(sqlinsert,sizeof(sqlinsert),"UPDATE internetcontentarticles set mediaURL=url where podcast=1 and feedtitle like '%s'",row[0]);
mysql_query(conn,sqlinsert);
res1 = mysql_store_result(conn);
haveupdated=true;
}
}
}
}
mysql_free_result(res);
stream_rssparse_nowloading=0;
}
mysql_close(conn);
} else return(-1);
if (haveupdated) return(1); else return(0);
}
// ****************************************************************************************
//
// ****************************************************************************************
void search_and_replace2(char *text) {
int n=0;
int nn=0;
char newtext[2048];
strcpy(newtext,"");
while(n<strlen(text)) {
if (text[n]=='"') {
strcat(newtext,"'");
n++;
} else {
newtext[nn]=text[n];
newtext[nn+1]='\0'; // null terminate string
nn++;
n++;
}
}
newtext[n]=0;
strcpy(text,newtext);
}
// ****************************************************************************************
//
// xml parser
//
// ****************************************************************************************
int stream_class::parsexmlrssfile(char *filename,char *baseiconfile) {
xmlChar *tmpdat;
xmlDoc *document;
xmlNode *root, *first_child, *node, *node1 ,*subnode,*subnode2,*subnode3;
xmlChar *xmlrssid;
xmlChar *content;
char rssprgtitle[2048];
char rssprgfeedtitle[2048];
char rssprgdesc[2048];
char rssprgimage[2048];
char rssprgimage1[2048];
char rssvideolink[2048];
char rssprgpubdate[256];
char rsstime[2048];
char rssauthor[2048];
char rssduration[2048];
int rssepisode;
int rssseason;
char result[2048+1];
char sqlinsert[32768];
char sqlselect[32768];
std::string sqlinsert1;
std::string sqlselect1;
std::string debuglogdata1;
char *database = (char *) "mythtvcontroller";
bool recordexist=false;
time_t raw_tid;
struct tm *opret_dato;
char rssopretdato[200];
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
strcpy(rssprgtitle,"");
strcpy(rssprgfeedtitle,"");
strcpy(rssprgdesc,"");
strcpy(rssvideolink,"");
strcpy(rsstime,"");
strcpy(rssauthor,"");
strcpy(rssprgimage,"");
strcpy(rssprgimage1,"");
if (check_zerro_bytes_file(filename)>0) {
conn=mysql_init(NULL);
document = xmlReadFile(filename, NULL, 0); // open xml file
// if exist do all the parse and update db
// it use REPLACE in mysql to create/update records if changed in xmlfile
raw_tid=time(NULL);
opret_dato=localtime(&raw_tid);
strftime(rssopretdato,28,"%F %T",opret_dato);
if ((document) && (conn)) {
mysql_real_connect(conn, configmysqlhost,configmysqluser, configmysqlpass, database, 0, NULL, 0);
if (conn) {
mysql_query(conn,"set NAMES 'utf8'");
res = mysql_store_result(conn);
}
root = xmlDocGetRootElement(document);
first_child = root->children;
for (node = first_child; node; node = node->next) {
if (node->type==XML_ELEMENT_NODE) {
if ((strcmp((char *) node->name,"channel")==0) || (strcmp((char *) node->name,"feed")==0)) {
content = xmlNodeGetContent(node);
if (content) {
//strcpy(result,(char *) content);
}
subnode=node->xmlChildrenNode;
while(subnode) {
xmlrssid=xmlGetProp(subnode,( xmlChar *) "title");
content = xmlNodeGetContent(subnode);
if ((content) && (strcmp((char *) subnode->name,"title")==0)) {
content = xmlNodeGetContent(subnode);
strcpy(rssprgtitle,(char *) content);
}
// images
// rssprgimage
// paththumb
//
if ((content) && (strcmp((char *) subnode->name,"image")==0)) {
content = xmlNodeGetContent(subnode);
tmpdat=xmlGetProp(subnode,( xmlChar *) "href");
if (tmpdat) {
strcpy(rssprgimage,(char *) tmpdat);
strcpy(baseiconfile,(char *) tmpdat);
xmlFree(tmpdat);
}
}
if ((content) && (strcmp((char *) subnode->name,"thumbnail")==0)) {
content = xmlNodeGetContent(subnode);
tmpdat=xmlGetProp(subnode,( xmlChar *) "href");
if (tmpdat) {
strcpy(rssprgimage,(char *) tmpdat);
xmlFree(tmpdat);
}
}
// item type element
if ((content) && (strcmp((char *) subnode->name,"item")==0)) {
subnode2=subnode->xmlChildrenNode;
while(subnode2) {
if ((content) && (strcmp((char *) subnode2->name,"title")==0)) {
content = xmlNodeGetContent(subnode2);
strcpy(rssprgfeedtitle,(char *) content);
}
// get play url
if ((content) && (strcmp((char *) subnode2->name,"enclosure")==0)) {
content = xmlNodeGetContent(subnode2);
tmpdat=xmlGetProp(subnode2,( xmlChar *) "url");
if (tmpdat) {
strcpy(rssvideolink,(char *) tmpdat);
xmlFree(tmpdat);
}
}
// rssprgpubdate
if ((content) && (strcmp((char *) subnode2->name,"pubDate")==0)) {
content = xmlNodeGetContent(subnode2);
strcpy(rssprgpubdate,(char *) content);
}
// get length
if ((content) && (strcmp((char *) subnode2->name,"duration")==0)) {
content = xmlNodeGetContent(subnode2);
if (content) strcpy(rsstime,(char *) content);
}
// get episode
if ((content) && (strcmp((char *) subnode2->name,"episode")==0)) {
content = xmlNodeGetContent(subnode2);
if (content) rssepisode=atoi((char *) content);
}
// get season
if ((content) && (strcmp((char *) subnode2->name,"season")==0)) {
content = xmlNodeGetContent(subnode2);
if (content) rssseason=atoi((char *) content);
}
// get author
if ((content) && (strcmp((char *) subnode2->name,"author")==0)) {
content = xmlNodeGetContent(subnode2);
if (content) strcpy(rssauthor,(char *) content);
}
// get description
if ((content) && (strcmp((char *) subnode2->name,"description")==0)) {
content = xmlNodeGetContent(subnode2);
if (content) {
xmlrssid=xmlGetProp(subnode2,( xmlChar *) "description");
if (xmlrssid) strcpy(rssprgdesc,(char *) content);
xmlFree(xmlrssid);
}
}
subnode2=subnode2->next;
}
recordexist=false;
// check if record exist
if (strcmp(rssvideolink,"")!=0) {
snprintf(sqlinsert,sizeof(sqlinsert),"select feedtitle from internetcontentarticles where (feedtitle like '%s' and mediaURL like '%s')",rssprgtitle,rssvideolink);
mysql_query(conn,sqlinsert);
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
recordexist=true;
}
}
// creoate record if not exist
if (!(recordexist)) {
search_and_replace2(rssprgtitle);
search_and_replace2(rssprgfeedtitle);
search_and_replace2(rssprgdesc);
// write debug log
// snprintf(debuglogdata,sizeof(debuglogdata),"Podcast update title %-20s Date %s",rssprgtitle,rssprgpubdate);
debuglogdata1 = fmt::v8::format("Podcast update title {} date {}", rssprgtitle,rssprgpubdate);
write_logfile(logfile,(char *) debuglogdata1.c_str());
snprintf(sqlinsert,sizeof(sqlinsert),"REPLACE into internetcontentarticles(feedtitle,mediaURL,title,episode,season,author,path,description,paththumb,date,time) values(\"%s\",'%s',\"%s\",%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%d)",rssprgtitle,rssvideolink,rssprgfeedtitle,rssepisode,rssseason,rssauthor,"",rssprgdesc,rssprgimage,rssopretdato,0);
std::string sqlinsert1 = fmt::v8::format("REPLACE into internetcontentarticles(feedtitle,mediaURL,title,episode,season,author,path,description,paththumb,date,time) values('{}','{}','{}','{}','{}','{}','','{}','{}','{}')",rssprgtitle,rssvideolink,rssprgfeedtitle,rssepisode,rssseason,rssauthor,rssprgdesc,rssprgimage,rssopretdato,0);
if (mysql_query(conn,sqlinsert)!=0) {
printf("mysql REPLACE table error. %s\n",sqlinsert);
}
res = mysql_store_result(conn);
}
}
}
subnode=subnode->next;
}
// end while loop
}
// youtube type
// get title
if (strcmp((char *) node->name,"title")==0) {
strcpy(rssprgtitle,"");
content = xmlNodeGetContent(node);
if (content) strcpy(rssprgtitle,(char *) content);
}
if ((strcmp((char *) node->name,"link")==0) || (strcmp((char *) node->name,"entry")==0)) {
// reset for earch element loading
strcpy(rssvideolink,"");
strcpy(rssprgfeedtitle,"");
rssepisode=0;
rssseason=0;
strcpy(rssauthor,"");
strcpy(rssprgdesc,"");
strcpy(rssprgimage1,"");
strcpy(rssprgimage,"");
if (strcmp((char *) node->name,"entry")==0) {
subnode2=node->xmlChildrenNode;
while(subnode2) {
strcpy(rssprgimage,"");
if ((content) && (strcmp((char *) subnode2->name,"title")==0)) {
content = xmlNodeGetContent(subnode2);
strcpy(rssprgfeedtitle,(char *) content);
}
// get play url
if ((content) && (strcmp((char *) subnode2->name,"link")==0)) {
content = xmlNodeGetContent(subnode2);
tmpdat=xmlGetProp(subnode2,( xmlChar *) "href");
if (tmpdat) {
strcpy(rssvideolink,(char *) tmpdat);
xmlFree(tmpdat);
}
}
if ((content) && (strcmp((char *) subnode2->name,"group")==0)) {
subnode3=subnode2->xmlChildrenNode;
while(subnode3) {
if ((content) && (strcmp((char *) subnode2->name,"title")==0)) {
content = xmlNodeGetContent(subnode2);
strcpy(rssprgtitle,(char *) content);
}
if ((content) && (strcmp((char *) subnode2->name,"description")==0)) {
content = xmlNodeGetContent(subnode2);
strcpy(rssprgdesc,(char *) content);
}
// get icon gfx
if ((content) && (strcmp((char *) subnode3->name,"thumbnail")==0)) {
content = xmlNodeGetContent(subnode3);
tmpdat=xmlGetProp(subnode3,( xmlChar *) "url");
if (tmpdat) {
//if (debugmode & 4) printf("Get image url %s \n",tmpdat);
strcpy(rssprgimage1,(char *) tmpdat);
xmlFree(tmpdat);
}
}
subnode3=subnode3->next;
}
}
subnode2=subnode2->next;
}
recordexist=false;
snprintf(sqlinsert,sizeof(sqlinsert),"SELECT feedtitle from internetcontentarticles where (feedtitle like '%s' mediaURL like '%s' and title like '%s')",rssprgtitle,rssvideolink,rssprgfeedtitle);
sqlinsert1 = fmt::v8::format("SELECT feedtitle from internetcontentarticles where (feedtitle like '{}' mediaURL like '{}' and title like '{}')",rssprgtitle,rssvideolink,rssprgfeedtitle);
mysql_query(conn,sqlinsert);
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
recordexist=true;
}
}
if (!(recordexist)) {
search_and_replace2(rssprgtitle);
search_and_replace2(rssprgfeedtitle);
search_and_replace2(rssprgdesc);
// write debug log
std::string debugdata1;
debugdata1 = fmt::v8::format("Podcast update title {} Date {}",rssprgtitle,rssprgpubdate);
write_logfile(logfile,(char *) debuglogdata1.c_str());
sqlinsert1 = fmt::v8::format("REPLACE into internetcontentarticles(feedtitle,mediaURL,title,episode,season,author,path,description,paththumb,date,time) values('{}','{}','{}',{},{},'{}','{}','{}','{}','{}',{})",rssprgtitle,rssvideolink,rssprgfeedtitle,rssepisode,rssseason,rssauthor,"",rssprgdesc,rssprgimage1,rssopretdato,0);
if (mysql_query(conn,sqlinsert1.c_str())!=0) {
printf("mysql REPLACE table error. %s\n",sqlinsert);
}
res = mysql_store_result(conn);
}
}
}
}
}
xmlFreeDoc(document);
mysql_close(conn);
}
} else {
// write debug log
snprintf(debuglogdata,sizeof(debuglogdata),"Error reading %s xmlfile 0 bytes long.",filename);
write_logfile(logfile,(char *) debuglogdata);
}
return(1);
}
// ****************************************************************************************
//
// get nr of rss feed
//
// ****************************************************************************************
int stream_class::get_antal_rss_feeds_sources(MYSQL *conn) {
char sqlselect[4096];
MYSQL_RES *res;
MYSQL_ROW row;
int antal=0;
//printf("*************************************************************************************\n");
if (conn) {
snprintf(sqlselect,sizeof(sqlselect),"SELECT count(name) from mythtvcontroller.internetcontent");
mysql_query(conn,sqlselect);
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
antal=atoi(row[0]);
}
}
}
return(antal);
}
// ****************************************************************************************
//
// get antal podcast af type
//
// ****************************************************************************************
int get_podcasttype_antal(char *typedata) {
char sqlselect[4096];
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *database = (char *) "mythtvcontroller";
int nrofrec=0;
if (typedata) {
snprintf(sqlselect,sizeof(sqlselect),"SELECT count(title) from internetcontentarticles where feedtitle like '%s'",typedata);
conn=mysql_init(NULL);
if (conn) {
mysql_real_connect(conn, configmysqlhost,configmysqluser, configmysqlpass, database, 0, NULL, 0);
if (mysql_query(conn,sqlselect)!=0) {
printf("mysql select count error. on title %s\n",typedata);
}
res = mysql_store_result(conn);
while ((res) && (row = mysql_fetch_row(res)) != NULL) {
nrofrec=atoi(row[0]);
}
mysql_free_result(res);
mysql_close(conn);
}
}
return(nrofrec);
}
// ****************************************************************************************
//
// check if title exist
//
// ****************************************************************************************
int check_rss_feed_exist(MYSQL *conn,char *rssname) {
bool recexist=false;
char sqlselect[2048];
MYSQL_RES *res;
MYSQL_ROW row;
if (conn) {
snprintf(sqlselect,sizeof(sqlselect),"SELECT feedtitle from mythtvcontroller.internetcontentarticles where feedtitle like '%s' limit 1",rssname);
mysql_query(conn,sqlselect);
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
recexist=true;
}
}
}
return(recexist);
}
// ****************************************************************************************
//
// opdate show liste in view (The view)
//
// load felt 7 = mythtv gfx icon
// fpath=stream path
// atr = stream name
//
// ****************************************************************************************
int stream_class::opdatere_stream_oversigt(char *art,char *fpath) {
char sqlselect[2048];
std::string sqlselect1;
char tmpfilename[1024];
char lasttmpfilename[1024];
char downloadfilename[1024];
char downloadfilename1[1024];
char downloadfilenamelong[1024];
char homedir[1024];
// mysql vars
bool rss_update=false;
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *database = (char *) "mythtvcontroller";
bool online;
int getart=0;
bool loadstatus=true;
bool dbexist=false;
antal=0;
conn=mysql_init(NULL);
// Connect to database
if (conn) {
if (mysql_real_connect(conn, configmysqlhost,configmysqluser, configmysqlpass, database, 0, NULL, 0)==0) {
dbexist=false;
}
mysql_query(conn,"set NAMES 'utf8'");
res = mysql_store_result(conn);
// test about rss table exist
mysql_query(conn,"SELECT feedtitle from mythtvcontroller.internetcontentarticles limit 1");
res = mysql_store_result(conn);
if (res) {
while ((row = mysql_fetch_row(res)) != NULL) {
dbexist=true;
}
}
//
// create db if not exist
// and dump some default rss feeed in
//
if (!(dbexist)) {
printf("Creating/Update RSS/PODCAST for new rss feed\n");
write_logfile(logfile,(char *) "Update rss files.");
// thumbnail = name of an local image file
// commandline = Program to fetch content with
// updated = Time of last update
if ((!(dbexist)) && (mysql_query(conn,"CREATE database if not exist mythtvcontroller")!=0)) {
printf("mysql db create error.\n");
}
res = mysql_store_result(conn);
// create db
snprintf(sqlselect,sizeof(sqlselect),"CREATE TABLE IF NOT EXISTS mythtvcontroller.internetcontentarticles(feedtitle varchar(255),path text,paththumb text,title varchar(255),season smallint(5) DEFAULT 0,episode smallint(5) DEFAULT 0,description text,url text,type smallint(3),thumbnail text,mediaURL text,author varchar(255),date datetime,time int(11),rating varchar(255),filesize bigint(20),player varchar(255),playerargs text,download varchar(255),downloadargs text,width smallint(6),height smallint(6),language varchar(128),podcast tinyint(1),downloadable tinyint(1),customhtml tinyint(1),countries varchar(255),id int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");
if (mysql_query(conn,sqlselect)!=0) {
printf("mysql create table error.\n");
printf("SQL : %s\n",sqlselect);
}
res = mysql_store_result(conn);
// create db
snprintf(sqlselect,sizeof(sqlselect),"CREATE TABLE IF NOT EXISTS mythtvcontroller.internetcontent(name varchar(255),thumbnail varchar(255),type smallint(3),author varchar(128),description text,commandline text,version double,updated datetime,search tinyint(1),tree tinyint(1),podcast tinyint(1),download tinyint(1),host varchar(128),id int NOT NULL AUTO_INCREMENT PRIMARY KEY,INDEX Idx (name (15),thumbnail (15),type, author (15), description (15),commandline (15),version,updated,search ,tree,podcast,download,host (15))) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");
if (mysql_query(conn,sqlselect)!=0) {
printf("mysql create table error.\n");
printf("SQL : %s\n",sqlselect);
}
if (!(dbexist)) {
// create index
snprintf(sqlselect,sizeof(sqlselect),"CREATE INDEX `internetcontentarticles_feedtitle` ON `mythtvcontroller`.`internetcontentarticles` (feedtitle) COMMENT '' ALGORITHM DEFAULT LOCK DEFAULT");
if (mysql_query(conn,sqlselect)!=0) {
printf("mysql create index error.\n");
}
}
}
res = mysql_store_result(conn);
// ok Aftenshowet
// dr have removed the rss feed
if (check_rss_feed_exist(conn,(char *) "Aftenshowet")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('Aftenshowet',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error Aftenshowet.\n");
res = mysql_store_result(conn);
mysql_free_result(res);
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('Aftenshowet',NULL,NULL,'Aftenshowet',0,0,NULL,'https://www.dr.dk/mu/Feed/aftenshowet-9.xml?format=podcast&limit=500',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error Aftenshowet.\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;
write_logfile(logfile,(char *) "Update rss Aftenshowet.");
}
// ok Anders Lund Madsen
if (check_rss_feed_exist(conn,(char *) "Anders Lund Madsen i Den Yderste By")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('Anders Lund Madsen i Den Yderste By',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error Anders Lund Madsen.\n");
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('Anders Lund Madsen i Den Yderste By',NULL,NULL,'Anders lund massen i den udereste by',0,0,NULL,'http://www.dr.dk/mu/Feed/anders-lund-madsen-i-den-yderste-by.xml?format=podcast&limit=500',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error Anders Lund Madsen i Den Yderste By.\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;
write_logfile(logfile,(char *) "Update rss Anders Lund Madsen i Den Yderste By.");
}
// ok Best of YouTube
if (check_rss_feed_exist(conn,(char *) "Best of YouTube (video)")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('Best of YouTube (video)',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error Best of YouTube.\n");
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('Best of YouTube (video)',NULL,NULL,'Best of YouTube (video)',0,0,NULL,'http://feeds.feedburner.com/boyt',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error Best of YouTube (video).\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;
}
// ok Bonderøven
if (check_rss_feed_exist(conn,(char *) "Bonderøven")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('Bonderøven',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error Bonderøven.\n");
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('Bonderøven',NULL,NULL,'Bonderøven',0,0,NULL,'https://www.dr.dk/mu/Feed/bonderoven-alle.xml?format=podcast&limit=500',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
if (mysql_query(conn,sqlselect)!=0) printf("mysql insert error Bonderøven.\n");
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error Bonderøven.\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;
}
// virker ikke
if (check_rss_feed_exist(conn,(char *) "CNET")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('CNET',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error CNET.\n");
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('CNET',NULL,NULL,'CNET',0,0,NULL,'http://feed.cnet.com/feed/podcast/all/hd.xml',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error CNET.\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;
}
// ok Droner og kanoner
if (check_rss_feed_exist(conn,(char *) "Droner og kanoner")==0) {
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontent(name,thumbnail,type,author,description,commandline,version,updated,search,tree,podcast,download,host) VALUES ('Droner og kanoner',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) printf("mysql insert error Droner og kanoner\n");
sqlselect1 = "REPLACE INTO mythtvcontroller.internetcontentarticles (feedtitle,path,paththumb,title,season,episode,description,url,type,thumbnail,mediaURL,author,date,time,rating,filesize,player,playerargs,download,downloadargs,width,height,language,podcast,downloadable,customhtml,countries) VALUES ('Droner og kanoner',NULL,NULL,'Droner og kanoner',0,0,NULL,'https://www.dr.dk/mu/Feed/droner-og-kanoner.xml?format=podcast&limit=500',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)";
res = mysql_store_result(conn);
mysql_free_result(res);
if (mysql_query(conn,sqlselect1.c_str())!=0) {
printf("mysql insert error Droner og kanoner.\n");
printf("SQL: %s\n",sqlselect1.c_str());
}
rss_update=true;