Bonjour à tous, je suis nouveau, et j'aimerai votre aide.

Pour commencer, je n'y connais absolument rien en programmation, et j'ai déjà demandé à des amis de l'aide, mais personne n'a réussi à résoudre mon problème.

Alors, je suis sous Windows, et utilise iTunes pour écouter de la musique. J'utilise XChat en tant que client IRC. Mon script, en perl, permet d'afficher ce que j'écoute, à l'aide d'une simple commande. Il marche bien, pas de problème, sauf un: il n'affiche pas les caractères japonais. J'ai cherché un peu partout sur le net, demandé à des gens que je connais, mais je n'ai rien trouvé, et je viens donc demander votre aide

Mon script en entier est le suivant:

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
 
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE;
 
my $version="1.0.1";
Xchat::register("iTunes-Info", $version, "DMS",sub{&unload();});
 
Xchat::print("\n\n\00312.:: iTunes-Info 2005 ::.\003\n");
Xchat::print("\00312:::  Version $version  :::\003\n");
Xchat::print("\00312:::    © DMS '05    :::\003\n\n"); 
 
Xchat::hook_command('iTunes_play','playHandler',{help_text => ''});
Xchat::hook_command('iTunes_pause','pauseHandler',{help_text => ''});
Xchat::hook_command('iTunes_stop','stopHandler',{help_text => ''});
Xchat::hook_command('iTunes_prev','prevHandler',{help_text => ''});
Xchat::hook_command('iTunes_next','nextHandler',{help_text => ''});
 
Xchat::hook_command('iTunesInfo','getInfo',{help_text => 'announce info to chanel'});
Xchat::hook_command('iTunesInfo_Set','iTunesInfoSet',{help_text => 'usage: iTunesInfo_Set [Field [Value]]'});
Xchat::hook_command('iTunesInfo_addFileLine','addFileLine',{help_text => 'add announce line for files'});
Xchat::hook_command('iTunesInfo_addStreamLine','addStreamLine',{help_text => 'add announce line for streams'});
Xchat::hook_command('iTunesInfo_showConf','showConfig',{help_text => 'show config'});
 
Xchat::hook_command('iTunesInfo_reloadTheme','loadTheme',{help_text => 'reloads theme'});
Xchat::hook_command('iTunesInfo_addButton','addButton',{help_text => 'reloads theme'});
 
 
Xchat::hook_print('Channel Message', 'chanMsg'); #uncomment this line if you don't want to announce by !mp3 command
Xchat::hook_print('Channel Msg Hilight', 'chanMsg'); #uncomment this line if you don't want to announce by !mp3 command
 
 
my @FILE_LINES;
my @STREAM_LINES;
my %VAR;
 
&init();
 
sub addButton{
	Xchat::command("addbutton iTunes itunesinfo");
	return Xchat::EAT_ALL;
}
 
sub playHandler{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	$iTunesApp->Play();
	return Xchat::EAT_ALL;
}
 
sub pauseHandler{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	$iTunesApp->Pause();
	return Xchat::EAT_ALL;
}
 
sub stopHandler{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	$iTunesApp->Stop();
	return Xchat::EAT_ALL;
}
 
sub prevHandler{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	$iTunesApp->PreviousTrack(); #BackTrack();
	return Xchat::EAT_ALL;
}
 
sub nextHandler{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	$iTunesApp->NextTrack();
	return Xchat::EAT_ALL;
}
 
sub showConfig{
	my $tBar=getBar(40);
	Xchat::print("\nITunesInfo-Configuration");
	my $line;
	foreach $line(@FILE_LINES){  IRC::print("	  File-Line: $line");}
	foreach $line(@STREAM_LINES){IRC::print("	Stream-Line: $line");}
	Xchat::print(" Stopedcommand: $VAR{STOPEDCOMMAND}");
	Xchat::print("       Barchar: $VAR{BARCHAR}");
	Xchat::print("  Barusedcolor: $VAR{BARUSEDCOLOR}");
	Xchat::print("  Barfreecolor: $VAR{BARFREECOLOR}");
	Xchat::print("     Samplebar: $tBar");
}
 
sub printSet{
	my $field=shift(@_);
	my $line;
	if (($field eq "FILE_LINE")||($field eq "STREAM_LINE")){
		if ($field eq "FILE_LINE"){foreach $line(@FILE_LINES){  IRC::print("	  File-Line: $line");}}
		if ($field eq "STREAM_LINE"){foreach $line(@STREAM_LINES){IRC::print("	Stream-Line: $line");}}
	}
	else {Xchat::print("$field = $VAR{$field}");}
}
 
sub printSetHelp(){
	Xchat::print("Available Settings for iTunesInfo");
	Xchat::print("BARCHAR - Char used in progresbar");
	Xchat::print("BARUSEDCOLOR - Colorcode for used part of bar (e.g. 03)");
	Xchat::print("BARFREECOLOR - Colorcode for rest part of bar (e.g. 16)");
	Xchat::print("STOPEDCOMMAND - command to announce to channel if iTunes is stoped/paused");
	Xchat::print("FILE_LINE - comand to announce if file is played (all other will be removed, better use \"iTunesInfo_addFileLine\")");
	Xchat::print("STREAM_LINE - command to annoince if stream is played (all other will be removed, better use \"iTunesInfo_addStreamLine\")");
}
 
 
 
sub iTunesInfoSet{
	if (!$_[0][1]){printSetHelp();return Xchat::EAT_ALL;}
	my $field=uc($_[0][1]);
 
	if (($field ne "FILE_LINE")&&($field ne "STREAM_LINE")&&($field ne "BARCHAR")&&($field ne "BARFREECOLOR")&&($field ne "BARUSEDCOLOR")&&($field ne "POSTCOMMAND")&&($field ne "STOPEDCOMMAND")){
		Xchat::print("not a valid field");return Xchat::EAT_ALL;
	}
 
	if (!$_[0][2]){printSet($field);return Xchat::EAT_ALL;}
	my $val=$_[1][2];
 
	if (($field eq "FILE_LINE")||($field eq "STREAM_LINE")){
		if ($field eq "FILE_LINE"){clearArr("FILE_LINES"); push(@FILE_LINES,$val);}
		if ($field eq "STREAM_LINE"){clearArr("STREAM_LINES"); push(@STREAM_LINES,$val);}
	}
	else {$VAR{$field}=$val;}
	my $themefile=Xchat::get_info("xchatdir");$themefile="$themefile/iTunesInfo.theme.txt";
	my $db= readFile($themefile);
	open (DB, ">$themefile");
	my $line;
	foreach $line(split "\n", $db){
       	my($var,$value)=(split "=", $line);
    	print DB "$var=$value\n" if ($var ne $field);
	}
    print DB "$field=$val\n";
    close(DB);
    IRC::print("\00312.:: $field changed to $val ::.\003\n");
 
	return Xchat::EAT_ALL;
}
 
sub addFileLine{
	my $val=$_[1][1];
	push(@FILE_LINES,$val);
	addLine("FILE_LINE",$val);
	Xchat::print("Fileline added");
}
 
sub addStreamLine{
	my $val=$_[1][1];
	push(@STREAM_LINES,$val);
	addLine("STREAM_LINE",$val);
	Xchat::print("Streamline added");
}
 
sub addLine{
	my $field=shift(@_);
	my $val=shift(@_);
	my $themefile=Xchat::get_info("xchatdir");$themefile="$themefile/iTunesInfo.theme.txt";
	my $db= readFile($themefile);
	open (DB, ">$themefile");
	my $line;
	foreach $line(split "\n", $db){
    	print DB "$line\n";
	}
    print DB "$field=$val\n";
}
 
sub chanMsg{
	my $msg=$_[0][1];
	$msg =~ s/^\s+//;
    $msg =~ s/\s+$//; 
	my $nick=uc(Xchat::get_info("nick"));
	#Xchat::print("msg: \"$msg\"");
	if ((uc($msg) eq "!MP3")||(uc($msg) eq "!MP3 $nick")){
		getInfo();
	}
 
	return Xchat::EAT_NONE;
}
 
sub getInfo{
	my $iTunesApp = Win32::OLE->new("iTunes.Application");
	if(!$iTunesApp){Xchat::print("No iTunes App found");return Xchat::EAT_ALL;}
	my $itState=$iTunesApp->PlayerState();
	#if ($itState==0){Xchat::print("stopped");}
	#if ($itState==1){Xchat::print("playling");}
	#if ($itState==2){Xchat::print("Fast forward");}
	#if ($itState==3){Xchat::print("rewind");}
 
 
	$ENV{version}=$iTunesApp->Version();
 
	if ($itState==0){
		#Xchat::print(themeLine($VAR{STOPEDCOMMAND}));
		Xchat::command(themeLine($VAR{STOPEDCOMMAND}));
		return Xchat::EAT_ALL;
	}
 
	my $itPos=$iTunesApp->{'PlayerPosition'};
	$ENV{play_time_min}  = timeString($itPos,0);
	$ENV{play_time}      = timeString($itPos,1);
	$ENV{play_time_auto} = timeString($itPos,2);
 
	my $itTrack=$iTunesApp->CurrentTrack();
	my $kind=$itTrack->{'Kind'}; 
 
	$ENV{title}=$itTrack->{'Name'};
	$ENV{bitrate}=$itTrack->{'BitRate'};
	$ENV{rate}=$itTrack->{'SampleRate'};
	$ENV{played}=$itTrack->{'PlayedCount'};
	$ENV{rating}=$itTrack->{'Rating'}; #percent
	$ENV{bpm}=$itTrack->{'BPM'};	
 
	if ($kind==3){ # STREAM
		#Xchat::print(themeStream());
		Xchat::command(themeStream());
		return Xchat::EAT_ALL;
	}
 
	$ENV{artist}=$itTrack->{'Artist'};
	$ENV{album}=$itTrack->{'Album'};
	$ENV{comment}=$itTrack->{'Comment'};
	#Composer
 
	my $len=$itTrack->{'Duration'};#seconds
	$ENV{length_min}  = timeString($len,0);
	$ENV{length}      = timeString($len,1);
	$ENV{length_auto} = timeString($len,2);
 
	$ENV{percent}=0;
	if ($len ne 0){ $ENV{percent}=int(($itPos/$len)*100);} 
	$ENV{bar}=&getBar($ENV{percent});
 
	$ENV{genre}=$itTrack->{'Genre'};
 
	$ENV{year}=$itTrack->{'Year'};
 
	$ENV{disc}=$itTrack->{'DiscNumber'};
	$ENV{discs}=$itTrack->{'DiscCount'};
 
	my $size=$itTrack->{'Size'}; #bytes
	$ENV{mbsize} = int($size / 1024 / 10.24 + 0.5) / 100;
	my $ext="b";
	$ENV{size_auto}=$size;
	if ($ENV{size_auto}>1024){$ext="kb";$ENV{size_auto}=int($ENV{size_auto}/1024);}
	if ($ENV{size_auto}>1024){$ext="mb";$ENV{size_auto}=int($ENV{size_auto}/1024);}
	$ENV{size_auto}="$ENV{size_auto}$ext";
 
	#Xchat::print(themeFile());
	Xchat::command(themeFile());
 
	return Xchat::EAT_ALL;
}
 
sub readFile{
		my $path=shift(@_);
		my $data;
        if (!open(DB, "<","$path")){Xchat::print("file not found: $path");return "";}
        my @stats=stat(DB);
        read (DB,$data,$stats[7]);
        close (DB);
        return $data;
}
 
sub clearArr{
	my $name=shift(@_);
	my $elem;
	if ($name eq "FILE_LINES") {foreach $elem (@FILE_LINES){pop(@FILE_LINES);}}
	if ($name eq "STREAM_LINES") {foreach $elem (@STREAM_LINES){pop(@STREAM_LINES);}}
}
 
sub loadTheme{
	#FILELINES, STREAMLINES, BARCHAR, BARFREECOLOR, BARUSEDCOLOR, POSTCOMMAND, STOPEDCOMMAND, PAUSECOMMAND
	#clearArr(@FILE_LINES);clearArr(@STREAM_LINES);
	clearArr("FILE_LINES");clearArr("STREAM_LINES");
	my $themefile=Xchat::get_info("xchatdir");$themefile="$themefile/iTunesInfo.theme.txt";
	my $line;
	foreach $line (split "\n", readFile($themefile)){
		my($var0, $value)=(split "=", $line);
		$value=replace($value,"%C",chr(3));
		$value=replace($value,"%B",chr(2));
		#$value=replace($value,"%U",chr(37));
		#$value=replace($value,"%O",chr(17));
		#$value=replace($value,"%R",chr(26));
		if (index($var0,"LINE") >= 0){
			if ($var0 eq "FILE_LINE"){push (@FILE_LINES, $value);}
			if ($var0 eq "STREAM_LINE"){push (@STREAM_LINES, $value);}
		}
		else {$VAR{$var0}=$value;}
	}
	$VAR{BARCHAR}="|" if (!$VAR{BARCHAR});
	$VAR{BARFREECOLOR}="03" if (!$VAR{BARFREECOLOR});
	$VAR{BARUSEDCOLOR}="16" if (!$VAR{BARUSEDCOLOR});
	#$VAR{POSTCOMMAND}="say" if (!$VAR{POSTCOMMAND});
	$VAR{STOPEDCOMMAND}="say iTunes %version stopped" if (!$VAR{STOPEDCOMMAND});
	#$VAR{PAUSECOMMAND}="say iTunes %version stopped" if (!$VAR{PAUSECOMMAND});
	#$VAR{}="" if (!$VAR{});
	if (!@FILE_LINES) {IRC::print("no file-line found\n");push(@FILE_LINES,"me is listening to 13%title by 13%artist from 13%album %bar %percent");}
	if (!@STREAM_LINES) {IRC::print("no stream-line found\n");push(@STREAM_LINES,"say i'm listening to %title since %playtime_auto");}
	return Xchat::EAT_ALL;
 
}
 
sub init{
	loadTheme();
}
 
sub timeString{
	my $secs=shift(@_);
	my $mode=shift(@_);
	my $mm=int($secs / 60);
	my $ss=$secs%60;
	if ($mode==0) {return sprintf('%d:%02d',$mm,$ss);}
	my $hh=int($mm/60);$mm=$mm%60;
	if (($mode==1)||($hh>0)) {return sprintf('%d:%02d:%02d',$hh,$mm,$ss);}
	return sprintf('%02d:%02d',$mm,$ss);
}
 
sub getBar{
	my $percent=shift(@_);
	my $b1=int($percent/10);
	my $b2=(10-$b1);
 
	my $bar="\002\003$VAR{BARUSEDCOLOR}";
	for (my $i=0;$i < $b1;$i=$i+1){$bar="$bar$VAR{BARCHAR}";}
	$bar="$bar\003$VAR{BARFREECOLOR}";
	for (my $i=0;$i < $b2;$i=$i+1){$bar="$bar$VAR{BARCHAR}";}
	$bar="$bar\003\002";
	return $bar
}
 
sub count{
	my @arr=@_;my $i=0;
	foreach $a (@arr){$i=$i+1;}
	return $i;
}
 
sub randLine{
	my @lines=@_;
	my $lcount=count(@lines);
	my $line=int(rand($lcount));
	return $lines[$line];
}
 
sub themeFile{return themeLine(randLine(@FILE_LINES));}
sub themeStream{return themeLine(randLine(@STREAM_LINES));}
 
sub themeLine{
	my $line=shift(@_);
	#$line=replace($line,"%",$ENV{});
	$line=replace($line,"%version",$ENV{version});
	$line=replace($line,"%playtime_min",$ENV{play_time_min});
	$line=replace($line,"%playtime_auto",$ENV{play_time_auto});
	$line=replace($line,"%playtime",$ENV{play_time});
	$line=replace($line,"%title",$ENV{title});
	$line=replace($line,"%bitrate",$ENV{bitrate});
	$line=replace($line,"%srate",$ENV{rate});
	$line=replace($line,"%played",$ENV{played});
	$line=replace($line,"%rating",$ENV{rating});
	$line=replace($line,"%bpm",$ENV{bpm});
 
	$line=replace($line,"%artist",$ENV{artist});
	$line=replace($line,"%album",$ENV{album});
	$line=replace($line,"%comment",$ENV{comment});
	$line=replace($line,"%len_min",$ENV{length_min});
	$line=replace($line,"%len_auto",$ENV{length_auto});
	$line=replace($line,"%len",$ENV{length});
 
	$line=replace($line,"%percent",$ENV{percent});
	$line=replace($line,"%bar",$ENV{bar});
	$line=replace($line,"%genre",$ENV{genre});
	$line=replace($line,"%year",$ENV{year});
	$line=replace($line,"%discs",$ENV{discs});
	$line=replace($line,"%disc",$ENV{disc});
	$line=replace($line,"%size_mb",$ENV{mbsize});
	$line=replace($line,"%size_auto",$ENV{size_auto});
 
 
	my $c10=chr(10);
	my $c13=chr(13);
	my $CC=chr(3);my $CB=chr(2);my $CU=chr(37);my $CO=chr(17);my $CR=chr(26);
	my $c1310="$c13$c10";
	$line=replace($line,$c1310,"; ");
	$line=replace($line,$c10,"; ");
	$line=replace($line,$c13,"; ");
	$line=replace($line,"%B",$CB);$line=replace($line,"%C",$CC);$line=replace($line,"%O",$CO);$line=replace($line,"%U",$CU);$line=replace($line,"%R",$CR);
	return $line;
}
 
sub replace{
	my $text=shift(@_);
	my $pattern=shift(@_);
	my $newText=shift(@_);
	my $left=""; 
	my $right="";
	while (index($text,$pattern) ne -1){
		$left=substr($text,0,index($text,$pattern));
		$right=substr($text,index($text,$pattern)+length($pattern));
		$text="$left$newText$right";
	}
	return $text;
}
J'espere que vous aurez une solution à me proposer, et je vous remercie d'avance