#!/usr/bin/perl -w ################################################## ## __AnGeL__DeViL__ AUTO iTunes Script ## ## by __AnGeL__ on #ravenna1@ircnet ## ## http://www.vipsnet/xchat/ ## ################################################## # V 1.1 ## Thanks to many other scripters: ## this script uses many modifications of other scripts i found usefull ;) $script = "iTunes - AnGeL & DeViL"; $sversion=1.1; $sdate = "04-22-2006"; IRC::register("iTunes - AnGeL & DeViL", "v. $sversion", "",""); IRC::print (" ................................\n.:: $script ::.\n::: script v$sversion - ($sdate) :::\n::: Help: /itunes help :::\n ................................\n\n"); IRC::add_command_handler ("itunes", "itunes"); Xchat::hook_print("Channel Message", "notice_handler"); ## USEFULL VARS $active = 0; $old_song=""; $auto_share=0; $home = qx(osascript -e 'return system attribute "HOME"'); chomp($home); if(!(-e "$home/.xchat2/angel_script_itunes.conf")){ open(FILE,">$home/.xchat2/angel_script_itunes.conf"); print FILE "## config file for AnGeL & DeViL X-Chat script\n"; print FILE "itunes_chans="; print FILE "\n"; close FILE; } # share song suboutines sub share_it { my ($nick) = @_; my $get_path = "tell application \"iTunes\" set j to the location of current track set j to posix path of j end tell set j to \"".'\"'."\" & j & \"".'\"'."\" as string return j"; my $file = `osascript -e \'$get_path\'`; chomp($file); $file = $nick ."\t". $file; &auto_get_file($file); } sub auto_share { if ($auto_share==0) { $auto_share=1; IRC::print("Auto Share ON"); } else { $auto_share=0; IRC::print("Auto Share OFF"); } sub notice_handler() { $col_nicks=Xchat::get_prefs("text_color_nicks"); $m_nick = $_[0][0]; if ($col_nicks==1){ $m_nick = substr $m_nick, 3; } $m_line = $_[0][1]; if($m_line =~ "!GETSONG") { if ($auto_share==1){ &share_it($m_nick); } } } return 1; } sub auto_get_file() { my ($file) = @_; @args=split('\t',$file); IRC::command("/DCC SEND ".$args[0]." $args[1]"); return 1; } #iTunes manage display chan list sub itunes_add_spam_chan { my $channel = shift; if (!($channel =~ m/^#/)) { $channel = "#".$channel; } open(FILE_OLD,"<$home/.xchat2/angel_script_itunes.conf"); @filearray=; close FILE_OLD; open(FILE_NEW,"+>$home/.xchat2/angel_script_itunes.conf"); @filearray_new=; for ($i=0;$i<=@filearray;$i++) { if ($filearray[$i] =~ m/^itunes_chans/) { if (!($filearray[$i]=~ m/$channel/)) { $filearray[$i]=~ s/\n//i; $filearray_new[$i]=$filearray[$i] . $channel . ";"; } else { $filearray_new[$i]=$filearray[$i]; } } else { $filearray_new[$i]=$filearray[$i];} print FILE_NEW $filearray_new[$i]; } close FILE_NEW; IRC::print("Added channel $channel to iTunes Spam List!"); return 1; } sub itunes_del_spam_chan() { ($data) = @_; IRC::print("Usage: /itunes del [#]\n"), return -1 if $data =~ /^\s*$/; { $channel = shift; if (!($channel =~ m/^#/)) { $channel = "#".$channel; } open(FILE_OLD,"<$home/.xchat2/angel_script_itunes.conf"); @filearray=; close FILE_OLD; IRC::print("Removed channel $channel from iTunes Spam List!"); open(FILE_NEW,"+>$home/.xchat2/angel_script_itunes.conf"); @filearray_new=; for ($i=0;$i<=@filearray;$i++) { if ($filearray[$i] =~ m/^itunes_chans/) { $filearray[$i]=~ s/\n//i; $filearray[$i]=~ s/$channel;//i; } $filearray_new[$i]=$filearray[$i]; print FILE_NEW $filearray_new[$i]; } close FILE_NEW; return 1; } } sub itunes_list_spam_chan { open(FILE,"<$home/.xchat2/angel_script_itunes.conf"); @filearray=; close FILE; for ($i=0;$i<=@filearray;$i++) { if ($filearray[$i] =~ m/^itunes_chans/) { $filearray[$i]=~ s/\n//i; $chanlist_tmp = substr($filearray[$i],13); @chanlist=split(';',$chanlist_tmp); } } $listchans=join(',',@chanlist); IRC::print("List of channels on which you will spam iTunes song:\n\n $listchans\n\n"); return 1; } #iTunes display sub check_itunes_song { my $get_track = qq(tell application "iTunes" set this_name to the name of current track set this_artist to the artist of current track set this_length to the time of current track set this_album to the album of current track end tell return this_name & tab & this_artist & tab & this_length & tab & this_album); $get_track = join ("' -e '",$get_track); $temp = qx(osascript -e '$get_track'); $temp =~ s/\n//g; $temp =~ s/\tmissing value\t/\t\t/g; $temp =~ s/\tmissing value$/\t/g; ($track,$player,$duration,$album) = split(/\t/,$temp); if($player eq ""){ $player = "Unknown Artist"; } if($track =~ /^\s*$/){ $track = "is listening to nothing at all"; } if($album ne "") { $album = "[from: $album Album] "; } $line = "" . $player." in '".$track ."' " . $album ."(". $duration.")"; $track = $line; &output($track); } sub output(){ ($current_song) = @_; $current_song =~ s/\t/ \- /g; open(FILE,"<$home/.xchat2/angel_script_itunes.conf"); @filearray=; close FILE; for ($i=0;$i<=@filearray;$i++) { if ($filearray[$i] =~ m/^itunes_chans/) { $filearray[$i]=~ s/\n//i; $chanlist_tmp = substr($filearray[$i],13); @chanlist=split(';',$chanlist_tmp); } } if ($current_song ne $old_song) { $old_song=$current_song; if($auto_share>0){ $getit="type !GETSONG to get current song!!"; } if (@chanlist <= 0) { IRC::command("/ME Playing: $current_song [A&D iTunes on X-Chat] $getit"); } else { for ($i=0;$i<@chanlist;$i++){ $channel=$chanlist[$i]; IRC::command_with_channel("/MSG $channel MP3: $current_song [A&D iTunes on X-Chat] $getit",$channel); } } } return 1; } sub itunes_show() { ($play)=@_; if ($play =~ m/play/) { if ($active==0){ $active++; $myhook =Xchat::hook_timer(5000, "check_itunes_song"); } } elsif ($play =~ m/stop/) { if ($active==1){ Xchat::unhook($myhook); $old_song=""; } } elsif ($play =~ m/show/) { $old_song=""; &check_itunes_song; } return 1; } sub update_itunes { system "curl http://www.vipsnet.net/xchat/mac/ad_iTunes.vers -o Plugins/ad_iTunes.vers"; open(TEMP,"Plugins/ad_iTunes.vers"); @temp_file=; close (TEMP); system "rm -f Plugins/ad_iTunes.vers"; $getvers=$temp_file[0]; if ($getvers > $sversion){ IRC::print("There is a *new* version of this script --> auto upgrading... [ $sversion -> $getvers ]"); system "curl http://www.vipsnet.net/xchat/mac/ad_iTunes.pl -o Plugins/ad_iTunes.pl"; IRC::print("\n\nRELOADING Script...."); IRC::command("/unload Plugins/ad_iTunes.pl"); IRC::command("/load Plugins/ad_iTunes.pl"); } else { IRC::print("This script is *up-to-date*\n\n"); } return 1; } sub itunes { $arg = shift(@_); for ($arg) { if (/help/) { IRC::print ("\n\n _______________________________________________________________________________________\n\n /itunes help..............to show this help /itunes play/stop.........to turn on/off itunes current song display /itunes show..............to display itunes current song like on play, but manually /itunes send .......to send current song to /itunes autosend..........to activate public !GETSONG on/off /itunes reload............to reload iTunes-Xchat plugin /itunes update............to update iTunes-Xchat plugin /itunes add [#]..to add a channel to spam list /itunes del [#]..to del a chan from spam list /itunes list..............to show active spam chan list _______________________________________________________________________________________\n\n"); return 1; } elsif (/play/) { &itunes_show("play"); return 1; } elsif (/stop/) { &itunes_show("stop"); return 1; } elsif (/show/) { &itunes_show("show"); return 1; } elsif (/add/) { @args=split(' ',$arg); my ($data) = shift(@args); IRC::print("Usage: /itunes add [#]\n"), return -1 if $data =~ /^\s*$/; { &itunes_add_spam_chan(@args); } return 1; } elsif (/del/) { @args=split(' ',$arg); my ($data) = shift(@args); IRC::print("Usage: /itunes del [#]\n"), return -1 if $data =~ /^\s*$/; { &itunes_del_spam_chan(@args); } return 1; } elsif (/list/) { &itunes_list_spam_chan; return 1; } elsif (/update/) { &update_itunes; return 1; } elsif (/autosend/) { &auto_share; return 1; } elsif (/send/) { @args=split(' ',$arg); my ($data) = shift(@args); IRC::print("Usage: /itunes add [#]\n"), return -1 if $data =~ /^\s*$/; { &share_it(@args); } return 1; } elsif (/reload/) { IRC::print("\n\nRELOADING Script...."); IRC::command("/unload Plugins/ad_iTunes.pl"); IRC::command("/load Plugins/ad_iTunes.pl"); return 1; } } return 1; } &update_itunes;