diff options
author | Joey Hess <joey@kitenet.net> | 2011-01-03 13:48:11 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-01-03 13:48:11 -0400 |
commit | 39e2e14be33f2a39105e744ed567998745cb273b (patch) | |
tree | 3412de8657f4d909b45f93ad5651d139d7ac7e34 | |
parent | 1db0d9efcf5b8f950bfe9b9224acaaa230943c58 (diff) |
mpinsert: Add -p option to begin playing inserted songs. Closes: #608690
-rw-r--r-- | debian/changelog | 2 | ||||
-rwxr-xr-x | mpinsert | 21 |
2 files changed, 19 insertions, 4 deletions
diff --git a/debian/changelog b/debian/changelog index d7f1cc4..5360f34 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ mpdtoys (0.24) UNRELEASED; urgency=low * mprandomwalk: New toy to play random bits of all queued songs. + * mpinsert: Add -p option to begin playing inserted songs. + Closes: #608690 -- Joey Hess <joeyh@debian.org> Thu, 17 Jun 2010 01:47:42 -0400 @@ -40,6 +40,12 @@ Print the playlist position number that the first song was inserted at. =back +=item -p + +Play the song after inserting it. + +=back + =head1 AUTHOR Copyright 2007-2009 Joey Hess <joey@kitenet.net> @@ -52,12 +58,14 @@ http://kitenet.net/~joey/code/mpdtoys use Getopt::Long; my $shownum=0; +my $playnow=0; GetOptions( - "n" => \$shownum, + "n" => \$shownum, + "p" => \$playnow, ) || usage(); sub usage { - die "Usage: mpinsert [-n] [song ...]\n"; + die "Usage: mpinsert [-n] [song ...]\n"; } my @list=@ARGV; @@ -75,6 +83,7 @@ my $pl=$mpd->playlist; @list=reverse @list if $mpd->current; my @out; +my $firstsong; foreach my $item (@list) { if (! length $item) { die "no item specified to insert\n"; @@ -100,11 +109,15 @@ foreach my $item (@list) { $pl->move($#items, $pos); } - push @out, ($pos+1)."\n" if $shownum; + $firstsong=$pos unless defined $firstsong; + push @out, ($pos+1) if $shownum; } } if ($shownum) { @out=reverse @out if $mpd->current; - print $out[0] if @out; + print $out[0]."\n" if @out; +} +if ($playnow && defined $firstsong) { + $mpd->play($firstsong); } |