html/rhythmbox.pl


   1 #=================================================================================
   2 #
   3 # rhythmbox.pl
   4 # script that allows you to control rhythmbox from irssi
   5 #
   6 #=================================================================================
   7 # INITIAL SECTION
   8 #=================================================================================
   9 use Irssi;
  10 use Irssi::Irc;
  11 use strict;
  12 use vars qw($VERSION %IRSSI);
  13 
  14 $VERSION = "1.30";
  15 
  16 %IRSSI = (
  17 	authors     =>  'Fogel',
  18 	contact     =>  'fogel@fogel.netmark.pl',
  19 	name        =>  'rhythmbox',
  20 	description =>  'Rhythmbox now playing script',
  21 	license     =>  'BSD',
  22 	url         =>  "www.fogel.com.pl",
  23 );
  24 #=================================================================================
  25 # NOW PLAYING SECTION
  26 #=================================================================================
  27 sub now_playing {
  28 
  29 	my ($data, $server, $witem) = @_;
  30 
  31 
  32 	my $title = `rhythmbox-client --print-playing-format %tt`;
  33 	my $artist = `rhythmbox-client --print-playing-format %ta`;
  34 	my $number = `rhythmbox-client --print-playing-format %tn`;
  35 	my $duration = `rhythmbox-client --print-playing-format %td`;
  36 	my $elapsed = `rhythmbox-client --print-playing-format %te`;
  37 	my $album_title = `rhythmbox-client --print-playing-format %at`;
  38 	my $album_artist = `rhythmbox-client --print-playing-format %aa`;
  39 	my $album_year = `rhythmbox-client --print-playing-format %ay`;
  40 	my $album_genre = `rhythmbox-client --print-playing-format %ag`;
  41 	my $disc_number = `rhythmbox-client --print-playing-format %an`;
  42 
  43 	if ($number =~ m/^\d*$/i) {
  44 		
  45 		my $output = "np: $artist - $title ($elapsed / $duration)"; # here set desired format of output
  46 
  47 		if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {
  48 
  49 			$witem->command("me $output")
  50 		} else {
  51 			Irssi::print("This is not a channel/query window");
  52 		}
  53 
  54 	} else {
  55 		Irssi::print("rhythmbox is not playing anything at the moment.");
  56 	}
  57 }
  58 #=================================================================================
  59 # RHYTHMBOX CONTROL SECTION
  60 #=================================================================================
  61 sub pause {
  62 	system("rhythmbox-client --pause");
  63 }
  64 
  65 sub play {
  66 	system("rhythmbox-client --play");
  67 }
  68 
  69 sub next {
  70         system("rhythmbox-client --next");
  71 }
  72 
  73 sub previous {
  74         system("rhythmbox-client --previous");
  75 }
  76 
  77 sub volume_up {
  78         system("rhythmbox-client --volume-up");
  79 } 
  80 
  81 sub volume_down {
  82         system("rhythmbox-client --volume-down");
  83 } 
  84 
  85 sub volume {
  86         my $vol = `rhythmbox-client --print-volume`;
  87 	Irssi::print("rhythmbox volume: $vol");
  88 }
  89 
  90 sub mute {
  91         system("rhythmbox-client --mute");
  92 }
  93 
  94 sub unmute {
  95         system("rhythmbox-client --unmute");
  96 }
  97 #=================================================================================
  98 # HELP DISPLAY SECTION SECTION
  99 #=================================================================================
 100 sub help {
 101 	
 102 	Irssi::print("rhythmbox.pl - rhythmbox control script for irssi");
 103 	Irssi::print("Copyright Michal \"Fogel\" Fogelman");
 104 	Irssi::print("List of commands:");
 105 	Irssi::print("/np - now playing - show others what are you listening to");
 106 	Irssi::print("/pause, /play");
 107 	Irssi::print("/prev, /next - previous/next track");
 108 	Irssi::print("/vup, /vdown - volume up/down");
 109 	Irssi::print("/volume - displays current volume level");
 110 	Irssi::print("/mute, /unmute");
 111 }
 112 #=================================================================================
 113 # COMMAND BINDINGS
 114 #=================================================================================
 115 Irssi::command_bind('np', 'now_playing');
 116 Irssi::command_bind('pause', 'pause');
 117 Irssi::command_bind('play', 'play');
 118 Irssi::command_bind('next', 'next');
 119 Irssi::command_bind('prev', 'previous');
 120 Irssi::command_bind('vup', 'volume_up');
 121 Irssi::command_bind('vdown', 'volume_down');
 122 Irssi::command_bind('vol', 'volume');
 123 Irssi::command_bind('mute', 'mute');
 124 Irssi::command_bind('unmute', 'unmute');
 125 
 126 Irssi::command_bind('rhythmbox_help', 'help');
 127 #=================================================================================
 128 # END OF FILE
 129 #=================================================================================