IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

JS Programme Télévision


Sujet :

JavaScript

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2020
    Messages : 114
    Points : 92
    Points
    92
    Par défaut JS Programme Télévision
    Bonjour à tous

    je viens vers vous avec de nouvelles questions

    ce code fonctionne avec un programme qui s'appelle Sarah 3.16 ce JS tout du moins ce plugin a la faculté de donner le programme télé à des heures précises de la journée ou de la soirée

    je pense que le script est obsolète

    d'où ma question d'où viendrait l'erreur?

    merci à vous tous et toute l'équipe de DVP

    voici une partie du code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    var TVBouquet = function (period, day, tblbouquet, pos, count, TVprogs, callback, callbacknext) {
     
    	if (!callback) return;
    	if (pos == count) return callbacknext(TVprogs);
    	if (debug == 'true') console.log("period: " + period);
    	var url = 'http://www.programme.tv/'
    '_________________________________________________________________________________	
    var scrapDay = function(body, bouquet, TVprogs, callback) {
    	var cherio = require('cheerio')
    	var $ = cherio.load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
     
    	$('div[class=progchaine]').each(function(index) {
    		var channelName = $(this).find('.chaine a').attr('title').replace('Programme ', '');
    		var flagfound = false;
    		if  (msg.MyChannelId(channelName) == true) {
    			for (var i = 0; i< TVprogs.length; i++) {
    				if (TVprogs[i].channelName == channelName) {
    					flagfound = true;
    					break;
    				}
    			}
    			if (!flagfound) {
    				var $1 = cherio.load($(this), { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
    				$1('li').each(function(i, elem) {
    					var hourStart = $(this).find('.heure').text();
    					var title = trim($1(this).find('.titre').text());
    					if (title && title != '') {
    						var type = trim($1(this).find('.type-tag').text());
    						if (type)
    							var duration = trim($1(this).find('.details p').text());
    						else {
    							type = 'otherType';
    							var duration = $(this).find('.duree').text();
    						}
    						if (duration && duration != '') {
    							duration = duration.replace(type + ' - ', '');
    							if (duration.indexOf('min') != -1) 
    								duration = '00:' + duration.replace(' min','');
    							duration = duration.replace('h', ':').replace('H', ':');
    							duration = ((duration.indexOf (':') == 1) ? '0'+ duration : duration);
    						} else {
    							if (type == 'Film') {
    								duration = default_FilmDuration;
    							} else {
    								duration = default_Duration;
    							}
    						}
    						var channelId = msg.ChannelId(channelName);		
    						TVprogs.push({"bouquet" : bouquet, "type": type, "channelId" : channelId, "channelName" : channelName, "hourStart" : hourStart, "title" : title, "duration" : duration});
    					}
    				});
    			}
    		}
    	});
     
    	callback(TVprogs);
    }

  2. #2
    Expert confirmé
    Avatar de Doksuri
    Profil pro
    Développeur Web
    Inscrit en
    Juin 2006
    Messages
    2 451
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 451
    Points : 4 600
    Points
    4 600
    Par défaut
    salut,
    il faudrait deja commencer a reduire le champ de recherche dans ton code, tu te doutes bien qu'on va pas se lire les 600 lignes
    si on regarde rapidement, on peu voir que le site apelle est en http (quand on y vas avec le navigateur, c'est du https)
    apres, si tu tests un simple appel en JS sur ce site, tu pourras constater qu'il y a une errer CORS. erreur typique : le site en question n'autorise pas les appels exterieurs

    solution 1 : qui a, environ 0% de chance d'aboutir : demander au site d'autoriser les appels externes
    solution 2 : trouver une API (ou flux quelconque) disponible
    solution 3 : trouver un autre service qui propose une liste accessible publiquement

    ps : 600 lignes pour recuperer un programme TV, ca me parait enorme
    La forme des pyramides prouve que l'Homme a toujours tendance a en faire de moins en moins.

    Venez discuter sur le Chat de Développez !

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2020
    Messages : 114
    Points : 92
    Points
    92
    Par défaut
    Bonjour Doksuri et merci de ta réponse, effectivement il est énorme et encore je l'ai réduit


    je vais le réduire encore car je pense savoir approximativement ou ce trouve l'erreur sans en être sûre

  4. #4
    Expert confirmé
    Avatar de Doksuri
    Profil pro
    Développeur Web
    Inscrit en
    Juin 2006
    Messages
    2 451
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 451
    Points : 4 600
    Points
    4 600
    Par défaut
    je t'ai deja dit que l'erreur vennait du CORS (cross-domain)
    La forme des pyramides prouve que l'Homme a toujours tendance a en faire de moins en moins.

    Venez discuter sur le Chat de Développez !

  5. #5
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2020
    Messages : 114
    Points : 92
    Points
    92
    Par défaut
    J'ai un autres fichiers JS qui lui va chercher l'info sur le même site et la ça fonctionne.

    D'où mon interrogation.

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2020
    Messages : 114
    Points : 92
    Points
    92
    Par défaut
    Merci Doksuri

    j'ai trouvé en partie grace à toi

    le problème venez de l'url

    je mets le code complet et corrigé pour ceux que cela interesse

    encore merci vous Longue Vie à DVP

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /*
    	Plugin TV programs
     
    	Date: 
    	Version: 1.0: 
    	Creation of the module
    */
     
     
    // Global variables
    var SARAH
    	 , debug
    	 , msg
    	 , lang
    	 , fs = require('fs')
    	 , ConfPeriod
    	 , ConfDay
    	 , ConfBouquet
    	 , sarahClient
    	 , clientRecord
    	 , default_FilmDuration
    	 , default_Duration
    	 , configType
    	 , roomConfig
    	 , defaultRoom
    	 , moment = require('./lib/moment/moment');
     
     
    // Init Sarah	 
    exports.init = function(sarah){
    	SARAH = sarah;
    	initTvSchedule(SARAH);
    }
     
     
    // Init Senariz	
    var initTvSchedule = function(SARAH, callback) {
     
    	var config = SARAH.ConfigManager.getConfig();
     
    	debug  = config.modules.tvSchedule['debug'] || 'false';
    	lang = config.modules.tvSchedule['language'] || 'FR_fr';
    	ConfPeriod = config.modules.tvSchedule['period'] || 'actuellement';
    	ConfDay = config.modules.tvSchedule['jour'] || 'aujourd\'hui';
    	ConfBouquet = config.modules.tvSchedule['bouquet'] || 'documentaire,generaliste,cinema,sport,tnt';
    	default_FilmDuration = config.modules.tvSchedule['default_FilmDuration'] || '02:30';
    	default_Duration = config.modules.tvSchedule['default_Duration'] || '01:30';
    	sarahClient = config.modules.tvSchedule['client'] || 'ALL';
    	defaultRoom = config.modules.tvSchedule['defaultRoom'] || 'SARAH1';
    	roomConfig = config.modules.tvSchedule['roomConfig'] || 'firstIn';
    	configType = function () {
    		switch (roomConfig) {
    			case 'motionSensor': return {motionSensor:true, firstIn: "false", autoDestroy: "true"};
    			case 'firstIn': return {motionSensor:false, firstIn: "true", autoDestroy: "false"};
    			case 'ALL': return {motionSensor:false, firstIn: "false", autoDestroy: "true"};
    		}
    	};
     
    	msg = require('./lib/lang/' + lang);
    	// callback if required
    	if (callback) callback();
    }
     
     
     
     
    // Cron
    exports.cron = function(callback, task){
     
    	var tvCron = require('./lib/db/tvScheduledb')({
    		sarah: SARAH,
    		lang: lang,
    		sarahClient: sarahClient,
    		fifo: configType().firstIn,
    		autoDestroy: configType().autoDestroy,
    		debug: debug});
     
    	var tblbouquet = ConfBouquet.split(','),
    		TVprogs = [],
    		period = getTimePeriod(moment().format("HH:mm"));	
     
    	TVBouquet(period, ConfDay, tblbouquet, 0, tblbouquet.length, TVprogs, TVBouquet, function (TVProgs) { 
    		tvCron.Tvcron(TVProgs);
    	});		
     
    	// return fucking callback
    	callback({});
    }
     
     
     
     
     
    // Sarah actions
    exports.action = function(data, callback, config, SARAH){
     
    	// ? Are you nuts ? leave back home.
    	if (data.command === undefined)
    		return callback({});
     
    	// mode debug
    	if (debug == 'true') console.log(msg.localized('debug'));
     
    	// table of actions
    	var tblActions = {
    		// What // actuellement, soiree, soiree2, jour 
    		tvProgram: function() { var tblbouquet = ConfBouquet.split(','),
    								TVprogs = [],
    								period = ((!data.period) ? ConfPeriod : data.period); 
    								day = ((!data.day) ? ConfDay : data.day); 
    								if (data.weekday && period.indexOf('-') == -1) 
    									SARAH.speak(msg.err_localized('errornoperiod')); 
    								else {
    									var tts = msg.localized('programs') + " ";
    									if (data.day) { tts += data.day + " " };
    									if (period.indexOf('-') != -1) { tts += msg.ttsSearch(-period)}
    									else if (period == 'actuellement') { tts +=  msg.ttsSearch(13)}
    									else if (period == 'soiree') { tts += msg.ttsSearch(14)}
    									else if (period == 'soiree2') { tts +=  msg.ttsSearch(15)}
    									tts += msg.ttsSearch(0);
    									SARAH.speak(tts,function(){
    										if (exists('mute') == true)
    											SARAH.call('mute', {command : 'autoMute', values : {Cmd: 'askme', Options: {timeout: false}}});
    										TVBouquet(period, day, tblbouquet, 0, tblbouquet.length, TVprogs, TVBouquet, function (TVProgs) { 
    											askTVType (TVProgs, msg.localized('askTVType'), day);
    										});
    									}); 
    								}
    								},	
    		tvExec: function() { TVExec(data.title, data.hour, data.duration, data.channelID, data.channelName)},
    		removeRemember: function() {removeRemembers()},
    		recordedProgram: function() {recordedProgram()},
    		// Set current room by motion Sensor or manual by order , it can be set by the motionSensor plugin
    		// Used for recording program
    		setRoom: function() {if (data.room) {
    								tvSchedule_config ('set_infos', tvSchedule_set_infos('currentRoom', data.room))
    							}}
    	};
     
    	if (debug == 'true') console.log("data.command: " + data.command);
    	tblActions[data.command]();
     
    	// return fucking callback
    	callback({});
    }
     
     
     
    var removeRemembers = function() {
     
    	var tvCron = require('./lib/db/tvScheduledb')({
    		sarah: SARAH,
    		lang: lang,
    		sarahClient: sarahClient,
    		fifo: configType().firstIn,
    		autoDestroy: configType().autoDestroy,
    		debug: debug});
    	tvCron.removeRemembers();
    }
     
     
     
    var recordedProgram = function() {
     
    	var tvCron = require('./lib/db/tvScheduledb')({
    		sarah: SARAH,
    		lang: lang,
    		sarahClient: sarahClient,
    		fifo: configType().firstIn,
    		autoDestroy: configType().autoDestroy,
    		debug: debug});
    	tvCron.isRecords();
    }
     
     
     
    var isPlayerOn = function (callback) {
     
    	var freebox = require('../freebox/freebox.js');
    	freebox.PlayerStatus (function(state) {  
    		callback (state);
    	});
    }
     
     
     
     
    var TVExec = function (title, hour, duration, channelID, channelName) {
     
    	isPlayerOn ( function (state) {
    		switch (state) {
    			case true: 
    				if (configType().motionSensor == true) {
    					// Search client name
    					var path = require('path'),
    						ini = require('./lib/ini/ini');
    					var inifile = path.resolve('%CD%', './custom.ini').replace('\\%CD%', ''),
    						client = ini.parse(fs.readFileSync(inifile, 'utf-8')).common.client;
    					if (client) { 
    						if (client.toLowerCase() != tvSchedule_get_infos().currentRoom.toLowerCase()) {
    							break;
    						} else
    							if (debug == 'true') console.log("tvSchedule client for tv program: " + client);
    					} else 
    						console.log('tvSchedule client for tv program error: Unable to retrieve the client name');
    				} else if (configType().motionSensor == false && configType().firstIn == 'true') {
    					if (debug == 'true') console.log("tvSchedule client for tv program: First");
    				} else if (configType().motionSensor == false && configType().firstIn == 'false') {
    					if (debug == 'true') console.log("tvSchedule client for tv program: All");
    				}
    				if (exists('mute') == true)
    					SARAH.trigger('mute',{key:'askme'});
    				SARAH.askme(msg.localized('TVProgramFound').replace('%s',title).replace('%c',channelName) , { 
    						'oui vas-y' : 'yes',
    						'oui s\'il te plait' : 'yes',
    						'non enregistre' : 'record',
    						'enregistre-le' : 'record',
    						'qu\'est ce que je peux dire' : 'sommaire',
    						'non merci': 'cancel',
    						'non c\'est bon': 'cancel'
    				}, 0, function(answer, end){
    					switch (answer) {
    					case 'sommaire':
    						SARAH.speak(msg.localized('tvFoundSommaire'),function(){
    							setTimeout(function(){
    								TVExec(title, hour, duration, channelID, channelName, client);
    								end();
    							}, 3000);
    						}); 
    						break;
    					case 'yes':
    						SARAH.speak(msg.localized('setTVProgram').replace('%s',title),function(){
    							SARAH.call('freebox', {command: 'setChannel', ID:channelID}, function(cb){ 
    								end(true);
    							});
    						}); 
    						break; 
    					case 'record':
    						SARAH.speak(msg.localized('askRecordProgram'),function(){
    							SARAH.call('freebox', {command: 'recordProgram', hour: hour, duration: duration, ID: channelID, afterRecord: true}, function(cb){ 
    								end(true);
    							});
    						}); 
    						break; 
    					case 'cancel':
    					default:
    						SARAH.speak(msg.localized('backtoType'),function(){	
    							end(true);
    						}); 
    						break;			
    					}					
    				});
    				break;
    			case false:	
    				// in all cases, remove the cron line before
    				var programName = msg.localized('rememberProgram').replace('%s',title).replace('%d',hour);
    				SARAH.call('scenariz', {command: 'remmoveCron', program: programName, name: programName}, function(cb){
    					SARAH.call('freebox', {command: 'recordProgram', hour: hour, duration: duration, ID: channelID}, function(cb){
    						setTimeout(function(){
    							var tvCron = require('./lib/db/tvScheduledb')({
    								sarah: SARAH,
    								lang: lang,
    								sarahClient: sarahClient,
    								fifo: configType().firstIn,
    								autoDestroy: configType().autoDestroy,
    								debug: debug});
    							tvCron.RememberRecord(title,
    												  hour,
    												  duration,
    												  channelID,
    												  channelName);
    						}, 20000);
    					});
    				});
    				break;
    			default:
    				console.log(msg.err_localized('backtoType'));
    				break;
    		}
    	});
    }
     
     
     
     
    var exists = function(cmd){
     
      var config = SARAH.ConfigManager.getConfig();
      if (config.modules[cmd])
        return true;
     
      return false;
    }
     
     
     
     
    var TVBouquet = function (period, day, tblbouquet, pos, count, TVprogs, callback, callbacknext) {
     
    	if (!callback) return;
    	if (pos == count) return callbacknext(TVprogs);
    	if (debug == 'true') console.log("period: " + period);
    	var url = 'https://www.programme.tv/'
     
    	moment.locale('fr');
    	moment().weekday(1);
    	var flagDay = false;
    	if (day == 'aujourd\'hui') {
    		if (period ==  ConfPeriod) 
    			url += period + '/' + tblbouquet[pos]; 
    		else if (period == 'soiree')
    			url += tblbouquet[pos];
    		else if (period == 'soiree2') {
    			var currentday = msg.dayOfWeek(parseInt(moment().weekday()));
    			url += tblbouquet[pos] + '/'  + period + '/' + currentday + '.php';
    		} else  {	
    			var currentday = msg.dayOfWeek(parseInt(moment().weekday()));
    			flagDay = true;
    			url += tblbouquet[pos] + '/jour/'  + currentday + period + '.php';
    		}
    	} else {
    		if (period == 'soiree' || period == 'soiree2') {
    			url += tblbouquet[pos] + '/' + period +  '/' + day + '.php';
    		} else {
    			flagDay = true;
    			url += tblbouquet[pos] + '/jour/'  + day + period + '.php';
    		}
    	}
     
    	if (debug == 'true') console.log("url: " + url);
     
    	getTVProg (url, function (body) { 
    		if (!body) {
    			SARAH.speak(msg.err_localized('errorgetProg'));
    			callback();
    		} else {
    			if (!flagDay)
    				scrap (body, tblbouquet[pos], TVprogs, function (TVprogs) { 
    					callback(period, day, tblbouquet, ++pos, count, TVprogs, callback, callbacknext);			
    				});
    			else
    				scrapDay (body, tblbouquet[pos], TVprogs, function (TVprogs) { 
    					callback(period, day, tblbouquet, ++pos, count, TVprogs, callback, callbacknext);			
    				});
    		}
    	}); 
    }
     
     
    var askTVType = function (TVProgs, tts, day) {
    	SARAH.askme(tts, { 
    			'qu\'est ce que je peux dire' : 'sommaire',
    			'les documentaires': 'Documentaire',
    			'le Sport': 'Sport',
    			'les Téléfilms' : 'Téléfilm',
    			'la jeunesse' : 'Jeunesse',
    			'les Divertissements': 'Divertissement',
    			'l\'Information': 'Information',
    			'la Culture' : 'Culture',
    			'les Séries' : 'Série',
    			'le cinéma': 'Film',
    			'les non classé': 'otherType',
    			'non merci': 'cancel',
    			'terminé': 'cancel',
    			'merci sarah' : 'Sarahcancel'
    	}, 0, function(answer, end){
    		if (debug == 'true') console.log("TVType answer: " + answer);
    		if (answer != 'cancel' && answer != 'sommaire' && answer != false && answer.toLowerCase() != 'sarahcancel') {
    			var count = 0;
    			var tblTVType=[];
    			for (var i=0; i < TVProgs.length; i++) {
    				if (TVProgs[i].type == answer){
    					TVProgs[i].hourStart = TVProgs[i].hourStart.replace('H',':').replace('h',':');
    					var date = moment().format("YYYY-MM-DD"),	
    						currentHour = moment().format("YYYY-MM-DDTHH:mm"),
    						progHour = moment(date+'T'+ TVProgs[i].hourStart);
    					if (moment(progHour).isBefore(currentHour) == true && TVProgs[i].duration) {
    						var hour = TVProgs[i].duration.split(':').shift(),
    						    mn = ((hour != '00') 
    								? (parseInt(hour) * 60) + parseInt(TVProgs[i].duration.split(':').pop())
    								: parseInt(TVProgs[i].duration.split(':').pop())),
    						    endprog = moment(progHour).add(mn, 'minutes').format("YYYY-MM-DDTHH:mm");
     
    						if (moment(endprog).isAfter(currentHour) == true) {
    							tblTVType.push(TVProgs[i]);
    							++count;
    						}
    					} else {
    						tblTVType.push(TVProgs[i]);
    						++count;
    					}
    				} 
    			}
    			if (count == 0) {
    				var noProg = ((answer == 'otherType') ? msg.localized('unclassed') : answer);
    				answer = 'noprog';
    			}
    		}
    		switch (answer) {
    			case 'noprog':
    				SARAH.speak(msg.localized('noProg').replace('%s',noProg),function(){
    					askTVType(TVProgs, msg.localized('askTVTypeNext'), day);
    					end();
    				}); 
    				break;
    			case 'sommaire':
    				SARAH.speak(msg.localized('Sommaire'),function(){
    					setTimeout(function(){
    						askTVType(TVProgs, msg.localized('askTVType'), day);
    						end();
    					}, 3000);
    				}); 
    				break;
    			case 'Documentaire':
    			case 'Jeunesse':
    			case 'Sport':
    			case 'Téléfilm':
    			case 'Film':
    			case 'Information':
    			case 'Culture':
    			case 'Divertissement':
    			case 'otherType':
    			case 'Série':
    				var tts;
    				if (answer == 'Jeunesse' || answer == 'Sport' || answer == 'Information' || answer == 'Culture'|| answer == 'Divertissement') {
    					if (answer == 'Jeunesse' || answer == 'Sport' || answer == 'Culture' || answer == 'Divertissement') {
    						tts = msg.localized('nbprogs1').replace('%d',count).replace('%s',answer);
    					} else {
    						tts = msg.localized('nbprogs2').replace('%d',count).replace('%s',answer);		
    					}
    				} else if (answer == 'otherType') {
    					tts = msg.localized('nbprogs3').replace('%d',count);
    				} else
    					tts = msg.localized('nbprogs').replace('%d',count).replace('%s',answer);
     
    				SARAH.speak(tts, function() {
    					speechTVProgs(true, TVProgs, tblTVType,0,tblTVType.length,day,speechTVProgs);
    					end();
    				});	
    				break;
    			case 'SARAHcancel':
    			case 'Sarahcancel':
    				SARAH.speak(msg.random_localized('terminateSarahAsk'), function() { 
    					end(true);
    				});	
    				break;
    			case 'cancel':
    			default:
    				SARAH.speak(msg.localized('terminateAsk'), function() { 
    					end(true);
    				});	
    				break;
    		}
    	});
    }
     
     
     
     
    var speechTVProgs = function(flagtts, TVProgs, tblTVType, pos, count, day, callback) {
     
    	if (!callback) return;
    	if (pos == count) { 
    		askTVType(TVProgs, msg.localized('askTVTypeNext'),day);
    		return;
    	}
    	/* TVProgs.forEach(function (prog) {
    				console.log('type: ' + prog.type);
    				console.log('channelId: ' + prog.channelId);
    				console.log('channelName: ' + prog.channelName);
    				console.log('hourStart: ' + prog.hourStart);
    				console.log('title: ' + prog.title);
    				console.log('subtitle: ' + prog.subtitle);
    				console.log('resume: ' + prog.resume);
    	});*/
     
    	if (debug == 'true') console.log("Channel: " + tblTVType[pos].channelName);
    	if (debug == 'true') console.log("Title: " + tblTVType[pos].title);
    	if (debug == 'true') console.log('hourStart: ' + tblTVType[pos].hourStart);
     
    	tblTVType[pos].hourStart = tblTVType[pos].hourStart.replace('H',':').replace('h',':');
    	var flagStarted = false;
    	if (day == msg.localized('today')) {
    		var date = moment().format("YYYY-MM-DD"),	
    			currentHour = moment().format("YYYY-MM-DDTHH:mm"),
    			progHour = moment(date+'T'+ tblTVType[pos].hourStart);
     
    		var diffMn = parseInt(progHour.diff(currentHour,"minutes"));
    		if (debug == 'true') console.log("Difference of minutes: " + diffMn);	
     
    		if (diffMn == 0) {
    			flagStarted = true;
    			var ttsHour = msg.localized('now') + ' ' + tblTVType[pos].hourStart;
    		} else if (diffMn < 0) {
    			flagStarted = true;
    			diffMn = diffMn * -1;
    			var hour = Math.floor(diffMn/60),
    				Minutes = diffMn%60,
    				ttsHour =  msg.localized('a') + ' ' + tblTVType[pos].hourStart + ' ' + msg.localized('startedBefore').replace('%d', ((hour > 0) ? hour + ' ' + msg.localized('hour') : '') + ((Minutes > 0) ? ' ' + Minutes + ' ' +  msg.localized('minute') : ''));
    		} else if (diffMn > 0) {
    			var ttsHour = msg.localized('a') + ' ' + tblTVType[pos].hourStart;
    		}
    	} else 
    		var ttsHour = msg.localized('a') + ' ' + tblTVType[pos].hourStart;
     
    	var tts;
    	if (flagtts == true)
    		tts = msg.localized('sur') + ' ' + tblTVType[pos].channelName + ' ' + ttsHour + ' ' + tblTVType[pos].title + ((tblTVType[pos].subtitle) ? ' ' + tblTVType[pos].subtitle : '');
    	else
    		tts = msg.localized('nextThing');
     
    	SARAH.askme(tts, { 
    			'qu\'est ce que je peux dire' : 'sommaire',
    			'répète': 'again',
    			'encore': 'again',
    			'donne-moi le résumé': 'resume',
    			'suivant' : 'next',
    			'à quelle heure' : 'hour',
    			'précédent' : 'previous',
    			'programme-le': 'programme',
    			'met-le': 'setIt',
    			'rappelle-le moi': 'recorder',
    			'reviens aux types': 'done',
    			'terminé' : 'cancel',
    			'annule' : 'cancel',
    			'merci sarah' : 'Sarahcancel'
    	}, 0, function(answer, end){
    		switch (answer) {
    			case 'sommaire':
    				SARAH.speak(msg.localized('speechTVProgsSommaire'),function(){
    					setTimeout(function(){
    						callback (true, TVProgs, tblTVType, pos, count, day, callback);
    						end();
    					}, 2000);
    				}); 
    				break;	
    			case 'recorder':
    				TvCron(tblTVType[pos], function () {
    						setTimeout(function(){
    							callback (false, TVProgs, tblTVType, pos, count, day, callback);
    							end();
    						}, 3000);
    				});
    				break;	
    			case 'setIt':
    				if (day == msg.localized('today')) {
    					SARAH.speak(msg.localized('setProgram').replace('%s',tblTVType[pos].title),function(){
    						setTimeout(function(){
    							SARAH.call('freebox', {command: 'setChannel', ID:tblTVType[pos].channelId.toString()}, function(cb){ 
    								setTimeout(function(){
    									callback (false, TVProgs, tblTVType, pos, count, day, callback);
    									end();
    								}, 1000);
    							});
    						});
    					}); 
    				} else {
    					SARAH.speak(msg.localized('notimeSetProgram').replace('%s',tblTVType[pos].title),function(){
    						setTimeout(function(){
    							callback (false, TVProgs, tblTVType, pos, count, day, callback);
    							end();
    						}, 2000);	
    					});
    				}
    				break; 
    			case 'programme':
    				if (!flagStarted) {
    					recordProgram (tblTVType[pos].title, tblTVType[pos].channelId, tblTVType[pos].hourStart, day, function () {
    						setTimeout(function(){
    							callback (false, TVProgs, tblTVType, pos, count, day, callback);
    							end();
    						}, 3000);
    					});
    				} else {
    					end();
    					SARAH.askme(msg.localized('alreadyStarted'), { 
    							'oui vas-y' : 'yes',
    							'oui s\'il te plait' : 'yes',
    							'non merci': 'cancel',
    							'terminé' : 'cancel',
    							'annule' : 'cancel'
    					}, 0, function(answerNext, end){
    						switch (answerNext) {
    						case 'yes':
    							SARAH.call('freebox', {command: 'setChannel', ID:tblTVType[pos].channelId.toString()}, function(cb){ 
    								setTimeout(function(){
    									callback (false, TVProgs, tblTVType, pos, count, day, callback);
    									end();
    								}, 1000);
    							});
    							break; 
    						case 'cancel':
    						default:
    							callback (false, TVProgs, tblTVType, pos, count, day, callback);
    							end();
    							break;			
    						}					
    					});
    				}
    				break;
    			case 'again':
    				callback (true, TVProgs, tblTVType, pos, count, day, callback);
    				end();
    				break;
    			case 'hour':
    				SARAH.speak((ttsHour),function(){
    					setTimeout(function(){
    						callback (false, TVProgs, tblTVType, pos, count, day, callback);
    						end();
    					}, 2000);
    				}); 
    				break;
    			case 'resume':
    				SARAH.speak(((tblTVType[pos].resume) ? tblTVType[pos].resume : msg.localized('noresume')),function(){
    					setTimeout(function(){
    						callback (false, TVProgs, tblTVType, pos, count, day, callback);
    						end();
    					}, 2000);
    				}); 
    				break;
    			case 'done':
    				SARAH.speak(msg.localized('backtoType'), function() { 
    					callback (true, TVProgs, tblTVType, count, count, day, callback);
    					end();
    				});	
    				break;
    			case 'previous':
    				if (pos == 0)
    					SARAH.speak(msg.localized('minpos'), function() { 
    						setTimeout(function(){
    							callback (true, TVProgs, tblTVType, pos, count, day,callback);
    							end();
    						}, 1500);
    					});
    				else {
    					callback (true, TVProgs, tblTVType, --pos, count, day, callback);
    					end();
    				}
    				break;
    			case 'next':
    				if (pos + 1 == tblTVType.length) {
    					var type = ((tblTVType[pos].type == 'otherType') ? msg.localized('unclassed') : tblTVType[pos].type);
    					SARAH.speak(msg.localized('endList').replace('%s',type) ,function(){
    						setTimeout(function(){
    							callback (true, TVProgs, tblTVType, ++pos, count, day, callback);	
    							end();
    						}, 1500);
    					});
    				} else {
    					callback (true, TVProgs, tblTVType, ++pos, count, day, callback);
    					end();
    				}
    				break;	
    			case 'SARAHcancel':
    			case 'Sarahcancel':
    				SARAH.speak(msg.random_localized('terminateSarahAsk'), function() { 
    					callback();
    					end(true);
    				});	
    				break;
    			case 'cancel':
    			default:
    				SARAH.speak(msg.random_localized('terminateAsk'), function() { 
    					callback();
    					end(true);
    				});	
    				break;
    		}
    	});
     
    }
     
     
    var TvCron = function (program, callback) {
     
    	if (program.title) {
    		var tvCron = require('./lib/db/tvScheduledb')({
    					sarah: SARAH,
    					lang: lang,
    					sarahClient: sarahClient,
    					fifo: configType().firstIn,
    					autoDestroy: configType().autoDestroy,
    					debug: debug});
    		tvCron.TvSave(program.title,
    					program.channelId,
    					program.channelName);
    		callback();	
    	} else {
    		SARAH.speak(msg.err_localized('errorcron'), function() {
    			callback();	
    		});
    	}
    }
     
     
     
     
    var recordProgram = function (title, channelId, hourStart, day, callback) {
     
    	hourStart = hourStart.replace('H',':').replace('h',':');
    	var plugins= SARAH.ConfigManager.getConfig(),
    		flagfound = false;
    	var pending = Object.keys(plugins.modules).length;
    	Object.keys(plugins.modules).forEach(function(plugin) {
    		if (plugin=='scenariz') 
    			flagfound = true;
     
    		if (!--pending) {
    			switch (flagfound) {
    			case true:	
    				var days = setPosDay(day);
    				var ExecTask = {command:'ScenarizCron', 
    								clients: sarahClient, 
    								program: msg.localized('recordProgram').replace('%s',title).replace('%d',hourStart),
    								name: msg.localized('recordProgram').replace('%s',title).replace('%d',hourStart),
    								exec : 'true',
    								start: hourStart + days,
    								ttsCron: msg.localized('speechProgram').replace('%s',title).replace('%d',hourStart),
    								autodestroy : 'true',
    								plug: 'freebox',
    								key: 'command=setChannel~ID=' + channelId.toString()
    								};
    				SARAH.call('scenariz', ExecTask, function(cb){ 
    					setTimeout(function(){
    						callback();
    					}, 500);
    				});
    				break;
    			default:
    				SARAH.speak(msg.err_localized('errorRecordProgram').replace('%s',title), function() {
    					setTimeout(function(){
    						callback();
    					}, 2000);
    				});
    				break;	
    			}
    		}
    	});
    }
     
     
    var setPosDay = function (day) {
     
    	if (day == msg.localized('today')) day = msg.dayOfWeek(parseInt(moment().weekday()))
    	switch (day) {
    	case msg.dayOfWeek(0): return "-1000000";
    	case msg.dayOfWeek(1): return "-0100000";
    	case msg.dayOfWeek(2): return "-0010000";
    	case msg.dayOfWeek(3): return "-0001000";
    	case msg.dayOfWeek(4): return "-0000100";
    	case msg.dayOfWeek(5): return "-0000010";
    	case msg.dayOfWeek(6): return "-0000001";
    	default:  			   return "-1111111";
    	}
    }
     
     
     
     
    var getTVProg = function (url,callback) {
     
    	var request = require('request');
    	request({ 'uri' : url }, function (err, response, body) {
    		//fs = require('fs')
    		//fs.writeFileSync(__dirname + '/body.json', JSON.stringify(body), 'utf8')
    		if (err || response.statusCode != 200) {
    		  console.log('tvProg error: ' + err);
    		  return callback();
    		} else 
    			callback(body);
    	});
    }
     
     
     
     
    var scrapDay = function(body, bouquet, TVprogs, callback) {
    	var cherio = require('cheerio')
    	var $ = cherio.load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
     
    	$('div[class=progchaine]').each(function(index) {
    		var channelName = $(this).find('.chaine a').attr('title').replace('Programme ', '');
    		var flagfound = false;
    		if  (msg.MyChannelId(channelName) == true) {
    			for (var i = 0; i< TVprogs.length; i++) {
    				if (TVprogs[i].channelName == channelName) {
    					flagfound = true;
    					break;
    				}
    			}
    			if (!flagfound) {
    				var $1 = cherio.load($(this), { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
    				$1('li').each(function(i, elem) {
    					var hourStart = $(this).find('.heure').text();
    					var title = trim($1(this).find('.titre').text());
    					if (title && title != '') {
    						var type = trim($1(this).find('.type-tag').text());
    						if (type)
    							var duration = trim($1(this).find('.details p').text());
    						else {
    							type = 'otherType';
    							var duration = $(this).find('.duree').text();
    						}
    						if (duration && duration != '') {
    							duration = duration.replace(type + ' - ', '');
    							if (duration.indexOf('min') != -1) 
    								duration = '00:' + duration.replace(' min','');
    							duration = duration.replace('h', ':').replace('H', ':');
    							duration = ((duration.indexOf (':') == 1) ? '0'+ duration : duration);
    						} else {
    							if (type == 'Film') {
    								duration = default_FilmDuration;
    							} else {
    								duration = default_Duration;
    							}
    						}
    						var channelId = msg.ChannelId(channelName);		
    						TVprogs.push({"bouquet" : bouquet, "type": type, "channelId" : channelId, "channelName" : channelName, "hourStart" : hourStart, "title" : title, "duration" : duration});
    					}
    				});
    			}
    		}
    	});
     
    	callback(TVprogs);
    }
     
     
    var scrap = function(body, bouquet, TVprogs, callback) {
     
      var $ = require('cheerio').load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
     
      $('#programs li:not(.pub)').each(function(index) {
        var channelName = $(this).find('.bheader a').attr('title').replace('Programme ', '');
        var flagfound = false;
    	if  (msg.MyChannelId(channelName) == true) {
    		for (var i = 0; i< TVprogs.length; i++) {
    			if (TVprogs[i].channelName == channelName) {
    				flagfound = true;
    				break;
    			}
    		}
    		if (!flagfound) {
    			var hourStart = $(this).find('.hour').text();
    			var title = $(this).find('.bcontent a').attr('title');
    			if (title == '' || title == undefined) 
    				title = $(this).find('.bcontent h3').text(); 
    			var subtitle = $(this).find('.bcontent .subtitle a').attr('title');
    			if (subtitle == '' || subtitle == undefined)  
    				subtitle = trim($(this).find('.bcontent .subtitle').text()); 
    			subtitle = subtitle.replace(title, '');
    			var type = $(this).find('.type').text();
    			if(!type) type = 'otherType';
    			var	resume = trim($(this).find('.bcontent .resume').text()); 
    			var channelId = msg.ChannelId(channelName);
    			TVprogs.push({"bouquet" : bouquet, "type": type, "channelId" : channelId, "channelName" : channelName, "hourStart" : hourStart, "title" : title, "subtitle" : subtitle, "resume" : resume});
    		}
    	} 
      });
     
      callback(TVprogs);
     
    }
     
     
     
    var getTimePeriod = function (hour) {
     
    	var date = moment().format("YYYY-MM-DD"),
    		TvProgHour = date+ 'T' + hour,
    	    zero = moment().hour(0).minute(0).format("YYYY-MM-DDTHH:mm"),
    		deux = moment().hour(2).minute(0).format("YYYY-MM-DDTHH:mm"),
    		quatre = moment().hour(4).minute(0).format("YYYY-MM-DDTHH:mm"),
    		six = moment().hour(6).minute(0).format("YYYY-MM-DDTHH:mm"),
    		huit = moment().hour(8).minute(0).format("YYYY-MM-DDTHH:mm"),
    		dix = moment().hour(10).minute(0).format("YYYY-MM-DDTHH:mm"),
    		douze = moment().hour(12).minute(0).format("YYYY-MM-DDTHH:mm"),
    		quatorze = moment().hour(14).minute(0).format("YYYY-MM-DDTHH:mm"),
    		seize = moment().hour(16).minute(0).format("YYYY-MM-DDTHH:mm"),
    		dixhuit = moment().hour(18).minute(0).format("YYYY-MM-DDTHH:mm"),
    		vingt = moment().hour(20).minute(0).format("YYYY-MM-DDTHH:mm"),
    		vingtdeux = moment().hour(22).minute(0).format("YYYY-MM-DDTHH:mm"),
    		minuit = moment(vingtdeux).add(2, 'hours').format("YYYY-MM-DDTHH:mm");
     
    	if ((moment(TvProgHour).isAfter(zero) == true && moment(TvProgHour).isBefore(deux) == true) || moment(TvProgHour).isSame(zero)== true )
    		return '-1';
    	if ((moment(TvProgHour).isAfter(deux) == true && moment(TvProgHour).isBefore(quatre) == true) || moment(TvProgHour).isSame(deux)== true ) 
    		return '-2';
    	if ((moment(TvProgHour).isAfter(quatre) == true && moment(TvProgHour).isBefore(six) == true) || moment(TvProgHour).isSame(quatre)== true ) 
    		return '-3';
    	if ((moment(TvProgHour).isAfter(six) == true && moment(TvProgHour).isBefore(huit) == true) || moment(TvProgHour).isSame(six)== true ) 
    		return '-4';
    	if ((moment(TvProgHour).isAfter(huit) == true && moment(TvProgHour).isBefore(dix) == true) || moment(TvProgHour).isSame(huit)== true ) 
    		return '-5';
    	if ((moment(TvProgHour).isAfter(dix) == true && moment(TvProgHour).isBefore(douze) == true) || moment(TvProgHour).isSame(dix)== true )
    		return '-6';
    	if ((moment(TvProgHour).isAfter(douze) == true && moment(TvProgHour).isBefore(quatorze) == true) || moment(TvProgHour).isSame(douze)== true ) 
    		return '-7';
    	if ((moment(TvProgHour).isAfter(quatorze) == true && moment(TvProgHour).isBefore(seize) == true) || moment(TvProgHour).isSame(quatorze)== true )
    		return '-8';
    	if ((moment(TvProgHour).isAfter(seize) == true && moment(TvProgHour).isBefore(dixhuit) == true) || moment(TvProgHour).isSame(seize)== true )
    		return '-9';
    	if ((moment(TvProgHour).isAfter(dixhuit) == true && moment(TvProgHour).isBefore(vingt) == true) || moment(TvProgHour).isSame(dixhuit)== true )
    		return '-10';
    	if ((moment(TvProgHour).isAfter(vingt) == true && moment(TvProgHour).isBefore(vingtdeux) == true) || moment(TvProgHour).isSame(vingt)== true ) 
    		return '-11';
    	if ((moment(TvProgHour).isAfter(vingtdeux) == true && moment(TvProgHour).isBefore(minuit) == true) || moment(TvProgHour).isSame(vingtdeux)== true )
    		return '-12';
    }
     
     
     
     
     
    function trim(sString) {
        while (sString.substring(0,1) == ' ' || sString.substring(0,1) == '\t' || 
          sString.substring(0,1) == '\r' || sString.substring(0,1) == '\n')
        {
            sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' ' || 
          sString.substring(sString.length-1, sString.length) == '\t' || 
          sString.substring(sString.length-1, sString.length) == '\r' || 
          sString.substring(sString.length-1, sString.length) == '\n')
        {
            sString = sString.substring(0,sString.length-1);
        }
        return sString;
    }
     
     
    var tvSchedule_config = function (action, config) {
    	// config = {currentRoom: null};
    	var _configjson = {
    		 file:  function () {return __dirname + '/tvScheduleConfig.json'},
    		 get_infos: function () {try {
    									   var json = JSON.parse(fs.readFileSync(this.file(),'utf8')) 
    									 } catch (err) 
    									 {
    										 config = {currentRoom: defaultRoom};
    										 this.set_infos();
    										 return;
    									 } 
    									 return json},
    		 set_infos: function () {fs.writeFileSync(this.file(), JSON.stringify(config), 'utf8')}
    	};
     
    	if (typeof config === 'function') 
    		return config(_configjson[action]());
    	else
    		return _configjson[action]();
    }
     
     
    var tvSchedule_get_infos = function (){
    	var conf = tvSchedule_config('get_infos');
    	return ((!conf) ? tvSchedule_config('get_infos') : conf );
    }
     
     
    var tvSchedule_set_infos = function (type, value) {
     
    	var _infos = {
    		currentRoom : value
    	};
     
    	return _infos;
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Programme de boot qui passe la main à Windows
    Par Bob dans le forum Assembleur
    Réponses: 7
    Dernier message: 25/11/2002, 03h08
  2. [Kylix] Probleme d'execution de programmes...
    Par yopziggy dans le forum EDI
    Réponses: 19
    Dernier message: 03/05/2002, 14h50
  3. communication entre programmes
    Par jérôme dans le forum C
    Réponses: 12
    Dernier message: 16/04/2002, 08h05
  4. Comment débuter en programmation ?
    Par Marc Lussac dans le forum Débuter
    Réponses: 0
    Dernier message: 08/04/2002, 11h29
  5. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo