App-Pimpd
view release on metacpan or search on metacpan
BEGIN {
use Pod::Usage;
if( (!@ARGV) or ($ARGV[0] =~ m/--?h(?:elp)?\z/) ) {
usage();
exit;
}
}
use App::Pimpd;
use App::Pimpd::Player;
use App::Pimpd::Info;
use App::Pimpd::Shell;
use App::Pimpd::Commands;
use App::Pimpd::Transfer;
use App::Pimpd::Validate;
use App::Pimpd::Collection::Search;
use App::Pimpd::Collection::Album;
use App::Pimpd::Playlist;
use App::Pimpd::Playlist::Search;
use App::Pimpd::Playlist::Favorite;
use App::Pimpd::Playlist::Randomize;
use Term::ExtendedColor qw(fg);
use Getopt::Long;
GetOptions(
'np|now-playing' => sub { print current(), "\n"; },
'i|info' => \&info,
'lsa|songs' => sub { _lsa(@ARGV); },
'l|laa|albums' => sub {
print "$_\n" for albums_by_artist(join(' ',@ARGV));
},
'randomize' => sub { print "$_\n" for randomize(@ARGV); },
'ra|random-album' => sub { print "$_\n" for randomize_albums(@ARGV); },
'rt|random-track' => sub { _rt(); },
'af|add' => sub { _add_files(@ARGV); },
'a|apl|add-playlist' => sub { add_playlist(@ARGV); },
'lsplaylists' => sub { print "$_\n" for list_all_playlists(); },
'pls|playlist' => sub { show_playlist(); },
'da|delete-album' => sub { delete_album(); },
'p|play' => sub { play(@ARGV); },
's|stop' => sub { stop(); },
'k|kill' => sub { player_destruct(); },
'sh|shell' => sub { \&spawn_shell(@ARGV); },
'rma|rmalbum' => sub { remove_album_from_playlist(@ARGV); },
'cp|copy' => sub { cp(@ARGV ? @ARGV : $config{target_directory}) },
'cpa|copy-album' => sub {
cp_album(@ARGV ? @ARGV : $config{target_directory})
},
'fav|favorite|love' => sub { add_to_favlist(@ARGV); }, # FIXME
'loved' => sub {
if(already_loved($mpd->current->file)) {
printf("%s, %s by %s is loved.\n",
fg('bold', 'Yes'),
fg($c[10], $mpd->current->title),
fg($c[2], fg('bold', $mpd->current->artist)),
);
}
else {
printf("%s, %s by %s is not loved yet.\n",
fg('bold', 'No'),
fg($c[10], $mpd->current->title),
fg($c[2], fg('bold', $mpd->current->artist)),
);
}
},
'unlove' => sub { remove_favorite(@ARGV); },
'aa|add-album' => sub {
add_to_playlist( map{ $_->file } get_album_songs(@ARGV) );
},
'slove' => sub {
my @files = search_favlist(@ARGV);
print "$_\n" for @files;
},
'spl|search-playlist|splaylist' => sub { _search_playlist(@ARGV); },
'sap|search-all-pls' => sub { search_all_playlists(@ARGV); },
'sdb|search-db' => sub { print "$_\n" for search_db_quick(@ARGV); },
'sar|search-artist' => sub { print "$_\n" for search_db_artist(@ARGV); },
'sal|search-album' => sub { print "$_\n" for search_db_album(@ARGV); },
'set|search-title' => sub { print "$_\n" for search_db_title(@ARGV); },
'next' => sub { next_track(); },
'prev' => sub { previous_track(); },
'clear' => sub { clear_playlist(); },
'crop' => sub { crop(@ARGV); },
'crossfade|xfade' => sub { crossfade(@ARGV); },
'pause' => sub { toggle_pause; },
'repeat' => sub { toggle_repeat; },
'random' => sub { toggle_random; },
'status' => sub { print status(), "\n"; },
'stats' => sub { stats(); },
'host' => sub {
# FIXME one way, or another...
my($host, $port, $password, $stream) = @ARGV;
App::Pimpd::mpd_init($host, $port, $password);
},
'debug' => sub { _debug(); },
'h|help' => \&usage,
'version' => sub { print "$APP v$VERSION\n" and exit 0; },
'man' => sub { pod2usage( verbose => 3 ); },
);
sub _rt {
play_pos_from_playlist(random_track_in_playlist());
print current(), "\n";
return;
}
# Wrapper for songs_on_album()
sub _lsa {
my($album, $artist) = @_;
$album or $album = $mpd->current->album;
print $_->file, "\n" for songs_on_album($album, $artist);
( run in 0.694 second using v1.01-cache-2.11-cpan-39bf76dae61 )