html/Cirssi.pl


   1 use strict;
   2 use vars qw($VERSION %IRSSI);
   3 # Consolidate Irssi Player
   4 #
   5 # Copyright (C) 2009 Dani Soufi
   6 #
   7 # This program is free software: you can redistribute it and/or modify
   8 # it under the terms of the GNU General Public License as published by
   9 # the Free Software Foundation, either version 3 of the License, or
  10 # (at your option) any later version.
  11 #
  12 # This program is distributed in the hope that it will be useful,
  13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 # GNU General Public License for more details.
  16 #
  17 # You should have received a copy of the GNU General Public License
  18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 #
  20 # Change Log:
  21 # v2.0.0:
  22 #       - Start/Play(Toggle)/Stop/Pause/Unpause/Next/Previous/Volume MOC Player control functions are added.
  23 #       - MOC Player support is implemented.
  24 # v1.1.2:
  25 #       - The script is now meant to be a bit more intelligent in dealing with song tags and different user song display settings.
  26 #       - Display album name in --details if it exists.
  27 # v1.1.0:
  28 #       - Script's name is renamed to Consolidate Irssi Player on global basis to expand it's use in the future.
  29 #       - Removed cmd_shuffle{} and cmd_repeat{} functions since they aren't supported anymore by Audacious2.
  30 #       - Added use --details flag for bitrate and frequency details in current playing song.
  31 #       - Added Jump to specific song in the playing list according to track number.
  32 #       - Added Volume control support from Irssi.
  33 #       - Updated the script to work with the newest Audacious v2 and audtool2 available.
  34 # v1.0.4:
  35 #       - Added Repeat on/off capability
  36 #       - Added Shuffle on/off capability
  37 #       - Fixed script output handling for audacious version in case audacious isn't running
  38 #       - If encountered a problem with audacious version, try changing `audacious --version` to `audtool -v`
  39 # v1.0.3:
  40 #       - Added Playlist functionality
  41 #       - Added Song details (Bitrate/Frequency/Length/Volume)
  42 #       - Current song notice with song details (Optional)
  43 # v1.0.2:
  44 #       - The script now handles warning support if you got audacious not running
  45 #       - Added track number, current time elapse and total track time
  46 #       - Added Stop functionality
  47 # v1.0.1:
  48 #       - Added ability to autonotify the channel after skipping a song (optional)
  49 #       - Added Skip/Play/Pause/Resume calls
  50 #
  51 # How To Use?
  52 # Copy your script into ~/.irssi/scripts/ directory
  53 # Load your script with /script load audacious in your Irssi Client
  54 # Type '/audacious help' in any channel for script commands
  55 # For autoload insert your script into ~/.irssi/scripts/autorun/ directory
  56 # Even better would be if you placed them in ~/.irssi/scripts/ and created symlinks in autorun directory
  57 #
  58 use Irssi;
  59 use IPC::Open3;
  60 
  61 $VERSION = '2.0.0';
  62 %IRSSI = (
  63    authors      =>   "Dani Soufi (compengi)",
  64    contact      =>   "IRC: Freenode network, #ubuntu-lb",
  65    name         =>   "Consolidate Irssi Player",
  66    description  =>   "Controls Audacious2 and MOCP from Irssi",
  67    license      =>   "GNU General Public License",
  68    url          =>   "http://bazaar.launchpad.net/~compengi/%2Bjunk/Cirssi/annotate/head%3A/Cirssi.pl",
  69    changed      =>   "Thu Aug 14 22:43 CET 2009",
  70 );
  71 
  72 #################################################################################
  73 # Please do not change anything below this, unless you know what you are doing. #
  74 #################################################################################
  75 
  76 sub cmd_aud_song {
  77    my ($data, $server, $witem) = @_;
  78 	# Get current song information.
  79    if ($witem && ($witem->{type} eq "CHANNEL")) {
  80 
  81    # Read output.
  82    my ( $wtr, $rdr, $err );
  83    my $pid = open3( $wtr, $rdr, $err,
  84                     'audtool2', '--current-song-tuple-data', 'file-name') or die $!;
  85 
  86    # Make it global.
  87    my $file;
  88    {
  89                 local $/;
  90                 $file = <$rdr>;
  91                 $file =~ s/\.(?i:mp3|cda|aa3|ac3|aif|ape|med|mpu|wave|mpc|oga|wma|ogg|wav|aac|flac)\n//;
  92    }
  93 
  94     if ($data ne "--details") {
  95       if (`ps -C audacious2` =~ /audacious/) {
  96         my $position = `audtool2 --playlist-position`;
  97         # I'm the most nasty variable ever.
  98         my $song = `audtool2 --current-song`;
  99         my $current = `audtool2 --current-song-output-length`;
 100         my $total = `audtool2 --current-song-length`;
 101         my $artist = `audtool2 --current-song-tuple-data artist`;
 102         my $album = `audtool2 current-song-tuple-data album`;
 103         my $title = `audtool2 --current-song-tuple-data title`;
 104         chomp($song);
 105         chomp($position);
 106         chomp($current);
 107         chomp($total);
 108         chomp($artist);
 109         chomp($album);
 110         chomp($title);
 111 
 112         # If we notice that the user sorted his playlist
 113         # by song title, we will try to be nice and parse
 114         # the existing artist for him.
 115         if ($song !~ /$artist/) {
 116           # If $song is different from $album,
 117           # we add the artist to output line.
 118           # Else strip the album from $song.
 119           if ($song !~ /$album/) {
 120             # If we have no song tags, $song will be set to the file's name.
 121             # In this case, we drop the file's extension know to us and print it.
 122             if ($song =~ /$file/) {
 123               $witem->command("/me is listening to: $file ($current/$total)");
 124             }
 125             else {
 126             $witem->command("/me is listening to: $artist - $song ($current/$total)");
 127             }
 128           }
 129           else {
 130             $song =~ s/$album - //im;
 131             $witem->command("/me is listening to: $artist - $song ($current/$total)");
 132           }
 133         }
 134         else {
 135           $witem->command("/me is listening to: $artist - $title ($current/$total)");
 136         }
 137       }
 138       else {
 139         $witem->print("Audacious is not currently running.");
 140       }
 141     }
 142     if ($data eq "--details") {
 143         # Show more details in the output.
 144       if (`ps -C audacious2` =~ /audacious/) {
 145         my $position = `audtool2 --playlist-position`;
 146         # I'm a nasty variable.
 147         my $song = `audtool2 --current-song`;
 148         my $current = `audtool2 --current-song-output-length`;
 149         my $total = `audtool2 --current-song-length`;
 150         my $bitrate = `audtool2 --current-song-bitrate-kbps`;
 151         my $frequency = `audtool2 --current-song-frequency-khz`;
 152         my $album = `audtool2 current-song-tuple-data album`;
 153         my $artist = `audtool2 --current-song-tuple-data artist`;
 154         my $title = `audtool2 --current-song-tuple-data title`;
 155         chomp($song);
 156         chomp($position);
 157         chomp($current);
 158         chomp($total);
 159         chomp($bitrate);
 160         chomp($frequency);
 161         chomp($album);
 162         chomp($artist);
 163         chomp($title);
 164 
 165         # Check against an empty string.
 166         # If it's empty, we don't print it.
 167         if ($album ne "") {
 168           # Make sure $song doesn't match $artist.
 169           # Else we print the $song as it is.
 170           if ($song !~ /$artist/) {
 171             # If $song is different from $album,
 172             # we add the artist to output line.
 173             # Else strip the album from $song.
 174             if ($song !~ /$album/) {
 175               if ($song =~ /$file/) {
 176                 $witem->command("/me is listening to: $artist - $song from $album ($current/$total) [$bitrate Kbps/$frequency KHz]");
 177               }
 178             }
 179             else {
 180               $witem->command("/me is listening to: $artist - $title from $album ($current/$total) [$bitrate Kbps/$frequency KHz]");
 181             }
 182           }
 183           elsif ($song =~ /\[ $album \]/) {
 184             $witem->command("/me is listening to: $artist - $title from $album ($current/$total) [$bitrate Kbps/$frequency KHz]");
 185           }
 186           else {
 187             $song =~ s/$album - //im;
 188             $witem->command("/me is listening to: $song from $album ($current/$total) [$bitrate Kbps/$frequency KHz]");
 189           }
 190         }
 191         elsif ($song =~ /$file/) {
 192           $witem->command("/me is listening to: $file ($current/$total) [$bitrate Kbps/$frequency KHz]");
 193         }
 194         else {
 195           $witem->command("/me is listening to: $artist - $title ($current/$total) [$bitrate Kbps/$frequency KHz]");
 196         }
 197       }
 198       else {
 199         $witem->print("Audacious is not currently running.");
 200       }
 201     }
 202    return 1;
 203   }
 204 }
 205 
 206 sub cmd_aud_next {
 207    my ($data, $server, $witem) = @_;
 208 	# Skip to the next track.
 209    if ($witem && ($witem->{type} eq "CHANNEL")) {
 210     if (`ps -C audacious2` =~ /audacious/) {
 211       my $next = `audtool2 --playlist-advance`;
 212 
 213       $witem->print("Skipped to next track.");
 214     }
 215     else {
 216       $witem->print("Can't skip to next track. Check your Audacious.");
 217     }
 218    return 1;
 219    }
 220 }
 221 
 222 sub cmd_aud_previous {
 223    my ($data, $server, $witem) = @_;
 224 	# Skip to the previous track.
 225    if ($witem && ($witem->{type} eq "CHANNEL")) {
 226     if (`ps -C audacious2` =~ /audacious/) {
 227       my $reverse = `audtool2 --playlist-reverse`;
 228 
 229       $witem->print("Skipped to previous track.");
 230    }
 231     else {
 232       $witem->print("Can't skip to next track. Check your Audacious.");
 233     }
 234    return 1;
 235    }
 236 }
 237 
 238 sub cmd_aud_play {
 239    my ($data, $server, $witem) = @_;
 240 	# Start playback.
 241    if ($witem && ($witem->{type} eq "CHANNEL")) {
 242     if (`ps -C audacious2` =~ /audacious/) {
 243       my $play = `audtool2 --playback-play`;
 244 
 245       $witem->print("Started playback.");
 246    }
 247     else {
 248       $witem->print("Playback can't be performed now.");
 249     }
 250    return 1;
 251    }
 252 }
 253 
 254 sub cmd_aud_pause {
 255    my ($data, $server, $witem) = @_;
 256 	# Pause playback.
 257    if ($witem && ($witem->{type} eq "CHANNEL")) {
 258     if (`ps -C audacious2` =~ /audacious/) {
 259       my $pause = `audtool2 --playback-pause`;
 260 
 261       $witem->print("Paused playback.");
 262    }
 263     else {
 264       $witem->print("Pause can be only performed when Audacious is running.");
 265     }
 266    return 1;
 267    }
 268 }
 269 
 270 sub cmd_aud_stop {
 271    my ($data, $server, $witem) = @_;
 272 	# Pause playback.
 273    if ($witem && ($witem->{type} eq "CHANNEL")) {
 274     if (`ps -C audacious2` =~ /audacious/) {
 275       my $stop = `audtool2 --playback-stop`;
 276 
 277       $witem->print("Stopped playback.");
 278    }
 279     else {
 280       $witem->print("This way you can't start Audacious.");
 281     }
 282    return 1;
 283    }
 284 }
 285 
 286 sub cmd_aud_volume {
 287    my ($data, $server, $witem) = @_;
 288         # Set volume and make sure the value is an integer
 289 	# that lays between 0 and 100.
 290    if ($witem && ($witem->{type} eq "CHANNEL")) {
 291     if (`ps -C audacious2` =~ /audacious/) {
 292 
 293      if ($data eq "") {
 294       $witem->print("Use /audacious volume <value> to set a specific volume value");
 295      }
 296      elsif ($data < 0 or $data > 100) {
 297        $witem->print("Given value is out of range [0-100].");
 298        return 0;
 299      }
 300      elsif ($data =~ /^[\d]+$/) {
 301        system 'audtool2','--set-volume', $data;
 302        my $volume = `audtool2 --get-volume`;
 303        chomp($volume);
 304        $witem->print("Volume is changed to $volume%%");
 305      }
 306      else {
 307        $witem->print("Please use a value [0-100] instead.");
 308      }
 309    }
 310     else {
 311       $witem->print("Volume can't be set in the current state.");
 312     }
 313    return 1;
 314    }
 315 }
 316 
 317 sub cmd_aud_jump {
 318    my ($data, $server, $witem) = @_;
 319         # Jump to a specific track, making sure that
 320 	# the selected track number exists.
 321    if ($witem && ($witem->{type} eq "CHANNEL")) {
 322     if (`ps -C audacious2` =~ /audacious/) {
 323 
 324      if ($data eq "") {
 325       $witem->print("Use /audacious jump <track> number to jump to it in your playlist.");
 326      }
 327      elsif ($data =~ /^[\d]+$/) {
 328        # Many thanks to Khisanth for this awesome fix!
 329        my ( $wtr, $rdr, $err );
 330        my $pid = open3( $wtr, $rdr, $err,
 331        	                'audtool2', '--playlist-jump', $data) or die $!;
 332        my $output;
 333        {
 334           local $/;
 335           $output = <$rdr>;
 336        }
 337        if ($output =~ /invalid/) {
 338         $witem->print("Track #$data isn't found in your playlist.");
 339        }
 340        else {
 341          $witem->print("Jumped to track #$data.");
 342        }
 343      }
 344      else {
 345        $witem->print("Please use a valid integer.");
 346      }
 347     }
 348     else {
 349      $witem->print("Start your audacious first.");
 350     }
 351    return 1;
 352    }
 353 }
 354 
 355 sub cmd_aud_playlist {
 356    my ($data, $server, $witem) = @_;
 357 	# Displays entire playlist loaded.
 358    if (`ps -C audacious2` =~ /audacious/) {
 359     my $display = `audtool2 --playlist-display`;
 360     chomp($display);
 361 
 362     Irssi::print("$display");
 363    }
 364    else {
 365     $witem->print("Start your player first.");
 366     }
 367    return 1; 
 368 }
 369 
 370 sub cmd_aud_details {
 371    my ($data, $server, $witem) = @_;
 372 	# Displays current song's details.
 373    if ($witem && ($witem->{type} eq "CHANNEL")) {
 374     if (`ps -C audacious2` =~ /audacious/) {
 375      my $bitrate = `audtool2 --current-song-bitrate-kbps`;
 376      my $frequency = `audtool2 --current-song-frequency-khz`;
 377      my $length = `audtool2 --current-song-length`;
 378      my $volume = `audtool2 --get-volume`;
 379      chomp($bitrate);
 380      chomp($frequency);
 381      chomp($length);
 382      chomp($volume);
 383 
 384     $witem->print("Current song details: rate: $bitrate kbps - freq: $frequency KHz - l: $length min - vol: $volume%%");
 385    }
 386    else {
 387     $witem->print("Your player doesn't seem to be running");
 388     }
 389    return 1;
 390   }
 391 }
 392 
 393 sub cmd_aud_version {
 394    my ($data, $server, $witem) = @_;
 395 	# Displays version information to the channel.
 396    if ($witem && ($witem->{type} eq "CHANNEL")) {
 397     if ($data eq "--audtool") {
 398       my $audtool = `audtool2 --version`;
 399       chop $audtool;
 400 
 401       $witem->command("/me is running: Consolidate Irssi Player v$VERSION with $audtool");
 402     }
 403     elsif ($data eq "--audacious") {
 404       my $audacious = `audacious2 --version`;
 405       chop $audacious;
 406 
 407       $witem->command("/me is running: Consolidate Irssi Player v$VERSION with $audacious"); 
 408     }
 409    return 1;
 410   }
 411 }
 412 
 413 sub cmd_audacious {
 414    my ($data, $server, $witem) = @_;
 415     if ($data =~ m/^[(song)|(next)|(previous)|(play)|(pause)|(stop)|(help)|(volume)|(jump)|(playlist)|(details)|(about)]/i) {
 416       Irssi::command_runsub('audacious', $data, $server, $witem);
 417     }
 418     else {
 419       Irssi::print("Use /audacious <option> or check /help audacious for the complete list");
 420     }
 421 }
 422 
 423 sub cmd_aud_help {
 424    my ($data, $server) = @_;
 425 	# Displays usage screen.
 426       Irssi::print("* /audacious song                 - Displays the current playing song in a channel.");
 427       Irssi::print("* /audacious song --details       - Displays bitrate and frequency with the current playing song.");
 428       Irssi::print("* /audacious next                 - Skips to the next song.");
 429       Irssi::print("* /audacious previous             - Skips to the previous song.");
 430       Irssi::print("* /audacious play                 - Starts playback.");
 431       Irssi::print("* /audacious pause                - Pauses playback.");
 432       Irssi::print("* /audacious stop                 - Stops playback.");
 433       Irssi::print("* /audacious volume <value>       - Sets volume [0-100].");
 434       Irssi::print("* /audacious jump <track>         - Jumps to specified track.");
 435       Irssi::print("* /audacious playlist             - Displays entire playlist.");
 436       Irssi::print("* /audacious details              - Displays current song's details.");
 437       Irssi::print("* /audacious version --audtool    - Displays version of the script and audtool in the channel.");
 438       Irssi::print("* /audacious version --audacious  - Displays version of the script and audacious in the channel.");
 439 }
 440 
 441 sub cmd_moc_song {
 442    my ($data, $server, $witem) = @_;
 443     if ($witem && ($witem->{type} eq "CHANNEL")) {
 444 
 445      if (`ps -C mocp` =~ /mocp/) {
 446 
 447        my $mocp = `mocp -i`;
 448        $mocp =~ /^State: (.*)$/m;
 449        my $state = $1;
 450        $mocp =~ /.*Title: (.*).*/;
 451        my $title = $1;
 452        $mocp =~ /.*TotalTime: (.*).*/;
 453        my $totaltime = $1;
 454        $mocp =~ /.*CurrentTime: (.*).*/;
 455        my $currenttime = $1;
 456 
 457       if ($data ne "--details") {
 458        if ($state eq '' || $state eq 'STOP') {
 459         $witem->print("MOC is not playing.");
 460        }
 461        else {
 462          $witem->command("/me is listening to: $title ($currenttime/$totaltime)");
 463        }
 464       }
 465  
 466       if ($data eq "--details") {
 467        if ($state eq '' || $state eq 'STOP') {
 468         $witem->print("MOC is not playing.");
 469        }
 470        else {
 471          $mocp =~ /.*Bitrate: (.*).*/;
 472          my $bitrate = $1;
 473          $mocp =~ /.*Rate: (.*).*/;
 474          my $rate = $1;
 475          $witem->command("/me is listening to: $title ($currenttime/$totaltime) [$bitrate/$rate]");
 476        }
 477       }
 478      }
 479      else {
 480        $witem->print("MOC is not started.");
 481      }
 482      return 1;
 483     }
 484 }
 485 
 486 sub cmd_moc_next {
 487   my ($data, $server, $witem) = @_;
 488       # Advance to next track in playlist.
 489   if ($witem && ($witem->{type} eq "CHANNEL")) {
 490 
 491    if (`ps -C mocp` =~ /mocp/) {
 492     my $mocp = `mocp -i`;
 493     $mocp =~ /^State: (.*)$/m;
 494     my $state = $1;
 495 
 496     if ($state eq '' || $state eq 'STOP') {
 497         $witem->print("MOC is not playing.");
 498     }
 499     else {
 500       my $next = `mocp -f`;
 501       $witem->print("Skipped to next track.");
 502     }
 503    }
 504    else {
 505      $witem->print("Can't skip to next track. Check your MOC Player.");
 506    }
 507    return 1;
 508   }
 509 }
 510 
 511 sub cmd_moc_previous {
 512   my ($data, $server, $witem) = @_;
 513       # Skip to previous track in playlist.
 514   if ($witem && ($witem->{type} eq "CHANNEL")) {
 515 
 516    if (`ps -C mocp` =~ /mocp/) {
 517     my $mocp = `mocp -i`;
 518     $mocp =~ /^State: (.*)$/m;
 519     my $state = $1;
 520 
 521     if ($state eq '' || $state eq 'STOP') {
 522         $witem->print("MOC is not playing.");
 523     }
 524     else {
 525       my $next = `mocp -r`;
 526       $witem->print("Skipped to previous track.");
 527     }
 528    }
 529    else {
 530      $witem->print("Can't skip to previous track. Check your MOC Player.");
 531    }
 532    return 1;
 533   }
 534 }
 535 
 536 sub cmd_moc_play_toggle {
 537    my ($data, $server, $witem) = @_;
 538        # Start playback.
 539    if ($witem && ($witem->{type} eq "CHANNEL")) {
 540 
 541     if (`ps -C mocp` =~ /mocp/) {
 542      my $mocp = `mocp -i`;
 543      $mocp =~ /^State: (.*)$/m;
 544      my $state = $1;
 545 
 546      if ($state eq '' || $state eq 'STOP') {
 547          $witem->print("MOC is not playing.");
 548      }
 549      elsif ($state eq 'PLAY') {
 550        my $play_toggle = `mocp -G`;
 551        $witem->print("Paused playing song.");
 552      }
 553      else {
 554        my $play = `mocp -G`;
 555        $witem->print("Started playback.");
 556      }
 557    }
 558    else {
 559       $witem->print("Playback can't be performed now.");
 560     }
 561     return 1;
 562    }
 563 }
 564 
 565 sub cmd_moc_pause {
 566    my ($data, $server, $witem) = @_;
 567 	# Pause playback.
 568    if ($witem && ($witem->{type} eq "CHANNEL")) {
 569 
 570     if (`ps -C mocp` =~ /mocp/) {
 571      my $mocp = `mocp -i`;
 572      $mocp =~ /^State: (.*)$/m;
 573      my $state = $1;
 574 
 575      if ($state eq '' || $state eq 'STOP') {
 576          $witem->print("MOC is not playing.");
 577      }
 578      elsif ($state eq 'PAUSE') {
 579        $witem->print("The song is already paused.");
 580      }
 581      else {
 582        my $pause = `mocp -P`;
 583        $witem->print("Paused playback.");
 584      }
 585    }
 586    else {
 587       $witem->print("Pause can be only performed when your MOC Player is running.");
 588     }
 589    return 1;
 590    }
 591 }
 592 
 593 sub cmd_moc_unpause {
 594    my ($data, $server, $witem) = @_;
 595 	# Unpause playback, if and only if the previous song was paused.
 596    if ($witem && ($witem->{type} eq "CHANNEL")) {
 597 
 598     if (`ps -C mocp` =~ /mocp/) {
 599      my $mocp = `mocp -i`;
 600      $mocp =~ /^State: (.*)$/m;
 601      my $state = $1;
 602 
 603      if ($state eq '' || $state eq 'STOP') {
 604          $witem->print("MOC is not playing.");
 605      }
 606      elsif ($state eq 'PAUSE') {
 607        my $pause = `mocp -U`;
 608        $witem->print("Unpaused playback.");
 609      }
 610      else {
 611        $witem->print("Can't unpause your playing song.");
 612      }
 613    }
 614    else {
 615       $witem->print("Unpause can be only performed when your MOC Player is running.");
 616     }
 617    return 1;
 618    }
 619 }
 620 
 621 sub cmd_moc_stop {
 622    my ($data, $server, $witem) = @_;
 623 	# Stop the current playing song.
 624    if ($witem && ($witem->{type} eq "CHANNEL")) {
 625 
 626     if (`ps -C mocp` =~ /mocp/) {
 627      my $mocp = `mocp -i`;
 628      $mocp =~ /^State: (.*)$/m;
 629      my $state = $1;
 630 
 631      if ($state eq '' || $state eq 'STOP') {
 632          $witem->print("MOC is not playing.");
 633      }
 634      else {
 635        my $stop = `mocp -s`;
 636        $witem->print("Stopped playback.");
 637      }
 638    }
 639     else {
 640       $witem->print("This way you can't stop a song. Double check your player.");
 641     }
 642    return 1;
 643    }
 644 }
 645 
 646 sub cmd_moc_volume {
 647    my ($data, $server, $witem) = @_;
 648         # Set volume and make sure the value is an integer
 649 	# that lays between 0 and 100.
 650    if ($witem && ($witem->{type} eq "CHANNEL")) {
 651     if (`ps -C mocp` =~ /mocp/) {
 652 
 653      if ($data eq "") {
 654       $witem->print("Use /mocp volume <value> to set a specific volume value");
 655      }
 656      elsif ($data < 0 or $data > 100) {
 657        $witem->print("Given value is out of range [0-100].");
 658        return 0;
 659      }
 660      elsif ($data =~ /^[\d]+$/) {
 661        system 'mocp','-v', $data;
 662        $witem->print("Volume is changed to $data%%");
 663      }
 664      else {
 665        $witem->print("Please use a value [0-100] instead.");
 666      }
 667    }
 668     else {
 669       $witem->print("Volume can't be set when MOC Player is not functioning.");
 670     }
 671    return 1;
 672    }
 673 }
 674 
 675 sub cmd_moc {
 676    my ($data, $server, $witem) = @_;
 677     if ($data =~ m/^[(song)|(next)|(previous)|(play)|(pause)|(unpause)|(stop)|(help)|(volume)]/i) {
 678       Irssi::command_runsub('mocp', $data, $server, $witem);
 679     }
 680     else {
 681       Irssi::print("Use /mocp <option> or check /help mocp for the complete list");
 682     }
 683 }
 684 
 685 sub cmd_moc_help {
 686    my ($data, $server) = @_;
 687 	# Displays usage screen.
 688       Irssi::print("* /mocp song                 - Displays the current playing song in a channel.");
 689       Irssi::print("* /mocp song --details       - Displays bitrate and frequency with the current playing song.");
 690       Irssi::print("* /mocp next                 - Skips to the next song.");
 691       Irssi::print("* /mocp previous             - Skips to the previous song.");
 692       Irssi::print("* /mocp play                 - Starts playback.");
 693       Irssi::print("* /mocp pause                - Pauses playback.");
 694       Irssi::print("* /mocp stop                 - Stops playback.");
 695       Irssi::print("* /mocp volume <value>       - Sets volume [0-100].");
 696 }
 697 
 698 Irssi::command_bind ('audacious song', 'cmd_aud_song');
 699 Irssi::command_bind ('audacious next', 'cmd_aud_next');
 700 Irssi::command_bind ('audacious previous', 'cmd_aud_previous');
 701 Irssi::command_bind ('audacious play', 'cmd_aud_play');
 702 Irssi::command_bind ('audacious pause', 'cmd_aud_pause');
 703 Irssi::command_bind ('audacious stop', 'cmd_aud_stop');
 704 Irssi::command_bind ('audacious help', 'cmd_aud_help');
 705 Irssi::command_bind ('audacious volume', 'cmd_aud_volume');
 706 Irssi::command_bind ('audacious jump', 'cmd_aud_jump');
 707 Irssi::command_bind ('audacious playlist', 'cmd_aud_playlist');
 708 Irssi::command_bind ('audacious details', 'cmd_aud_details');
 709 Irssi::command_bind ('audacious version', 'cmd_aud_version');
 710 Irssi::command_bind ('audacious', 'cmd_audacious');
 711 Irssi::command_bind ('mocp song', 'cmd_moc_song');
 712 Irssi::command_bind ('mocp next', 'cmd_moc_next');
 713 Irssi::command_bind ('mocp previous', 'cmd_moc_previous');
 714 Irssi::command_bind ('mocp play', 'cmd_moc_play_toggle');
 715 Irssi::command_bind ('mocp pause', 'cmd_moc_pause');
 716 Irssi::command_bind ('mocp unpause', 'cmd_moc_unpause');
 717 Irssi::command_bind ('mocp stop', 'cmd_moc_stop');
 718 Irssi::command_bind ('mocp help', 'cmd_moc_help');
 719 Irssi::command_bind ('mocp volume', 'cmd_moc_volume');
 720 Irssi::command_bind ('mocp', 'cmd_moc');
 721 
 722 Irssi::print("Consolidate Irssi Player v$VERSION is loaded successfully");