Toby Inkster avatar Toby Inkster committed 677259c

CLI improvements

Comments (0)

Files changed (6)

lib/App/SoundSwarm/Command/current.pm

+package App::SoundSwarm::Command::current;
+
+use strict;
+use warnings;
+use App::SoundSwarm -command;
+use PerlX::Maybe;
+
+sub abstract
+{
+	return "show information about the current track";
+}
+
+sub command_names
+{
+	return qw( current current_track current_song nowplaying np );
+}
+
+sub usage_desc
+{
+	my $class  = shift;
+	my ($name) = $class->command_names;
+	return "%c $name %o";
+}
+
+sub opt_spec
+{
+	require SoundSwarm;
+	return (
+		[ "port=i"          => "TCP port to connect to (default ${\SoundSwarm::PLAYER_PORT()})" ],
+		[ "host=s"          => "host to connect to" ],
+		[ "library-port=i"  => "TCP port to connect to (default ${\SoundSwarm::LIBRARY_PORT()})" ],
+		[ "library-host=s"  => "host to connect to" ],
+	);
+}
+
+sub execute
+{
+	require SoundSwarm::Client::Player;
+	require SoundSwarm::Client::Library;
+	require Path::Class;
+	
+	my ($self, $opt, $args) = @_;
+	
+	my $player = "SoundSwarm::Client::Player"->new({
+		maybe port => $opt->port,
+		maybe host => $opt->host,
+	});
+	my $song = $player->current_song;
+	print $song, "\n";
+	
+	my $library = "SoundSwarm::Client::Library"->new({
+		maybe port => $opt->library_port,
+		maybe host => $opt->library_host,
+	});
+	
+	my $results = $library->search_tracks({ filename => $song });
+	my ($result) = grep $_->{filename} eq $song, @$results;
+	for my $key (qw( Artist Album Title )) {
+		next unless defined(my $val = $result->{lc $key});
+		printf("% 8s : %s\n", $key, $val);
+	}
+}
+
+1;
+

lib/App/SoundSwarm/Command/enqueue.pm

 {
 	require SoundSwarm;
 	return (
-		[ "port"    => "TCP port to connect to (default ${\SoundSwarm::QUEUE_PORT()})" ],
-		[ "host"    => "host to connect to" ],
+		[ "port=i"  => "TCP port to connect to (default ${\SoundSwarm::QUEUE_PORT()})" ],
+		[ "host=s"  => "host to connect to" ],
 		[ "stdin|i" => "read filenames from STDIN instead of command line parameters" ],
 	);
 }
 
-sub validate_args
-{
-	my ($self, $opt, $args) = @_;
-	for (@$args) {
-	}
-}
-
 sub execute
 {
 	require SoundSwarm::Client::Queue;
 	
 	my @files =
 		map { "$_" }
-		map { -d $_ ? _expand_dir($_) : Path::Class::File->new($_)->absolute }
-		(delete $opt->{stdin} ? <> : @$args);
+		map { -d $_ ? _expand_dir($_) : "Path::Class::File"->new($_)->absolute }
+		map { chomp($_); $_ }
+		(delete $opt->{stdin} ? (my @tmp = <STDIN>) : @$args);
 	
 	for (@files)
 	{
 		$self->usage_error("not a file: $_") unless -f $_;
-		($queue ||= SoundSwarm::Client::Queue->new(%$opt))->enqueue($_);
+		($queue ||= "SoundSwarm::Client::Queue"->new(%$opt))->enqueue($_);
 	}
 }
 
 {
 	require Path::Class;
 	
-	my $dir = Path::Class::Dir->new($_);
+	my $dir = "Path::Class::Dir"->new($_);
 	my @return;
 	$dir->recurse(callback => sub
 	{

lib/App/SoundSwarm/Command/next.pm

+package App::SoundSwarm::Command::next;
+
+use strict;
+use warnings;
+use App::SoundSwarm -command;
+use PerlX::Maybe;
+
+sub abstract
+{
+	return "show information about the next track in the queue";
+}
+
+sub command_names
+{
+	return qw( next );
+}
+
+sub usage_desc
+{
+	my $class  = shift;
+	my ($name) = $class->command_names;
+	return "%c $name %o";
+}
+
+sub opt_spec
+{
+	require SoundSwarm;
+	return (
+		[ "port=i"          => "TCP port to connect to (default ${\SoundSwarm::QUEUE_PORT()})" ],
+		[ "host=s"          => "host to connect to" ],
+		[ "library-port=i"  => "TCP port to connect to (default ${\SoundSwarm::LIBRARY_PORT()})" ],
+		[ "library-host=s"  => "host to connect to" ],
+	);
+}
+
+sub execute
+{
+	require SoundSwarm::Client::Queue;
+	require SoundSwarm::Client::Library;
+	
+	my ($self, $opt, $args) = @_;
+	
+	my $player = "SoundSwarm::Client::Queue"->new({
+		maybe port => $opt->port,
+		maybe host => $opt->host,
+	});
+	my $song = $player->list->[0];
+	print $song, "\n";
+	
+	my $library = "SoundSwarm::Client::Library"->new({
+		maybe port => $opt->library_port,
+		maybe host => $opt->library_host,
+	});	
+	my $results = $library->search_tracks({ filename => $song });
+	
+	my ($result) = grep $_->{filename} eq $song, @$results;
+	for my $key (qw( Artist Album Title )) {
+		next unless defined(my $val = $result->{lc $key});
+		printf("% 8s : %s\n", $key, $val);
+	}
+}
+
+1;
+

lib/App/SoundSwarm/Command/queue.pm

 {
 	require SoundSwarm;
 	return (
-		[ "port"    => "TCP port to connect to (default ${\SoundSwarm::QUEUE_PORT()})" ],
-		[ "host"    => "host to connect to" ],
+		[ "port=i"  => "TCP port to connect to (default ${\SoundSwarm::QUEUE_PORT()})" ],
+		[ "host=s"  => "host to connect to" ],
 	);
 }
 
 	require Path::Class;
 	
 	my ($self, $opt, $args) = @_;
-	my $queue = SoundSwarm::Client::Queue->new(%$opt);
+	my $queue = "SoundSwarm::Client::Queue"->new(%$opt);
 	
 	print "$_\n" for @{ $queue->list };
 }

lib/App/SoundSwarm/Command/search.pm

+package App::SoundSwarm::Command::search;
+
+use strict;
+use warnings;
+use App::SoundSwarm -command;
+use PerlX::Maybe;
+
+sub abstract
+{
+	return "search for files in the library";
+}
+
+sub command_names
+{
+	return qw( search s );
+}
+
+sub usage_desc
+{
+	my $class  = shift;
+	my ($name) = $class->command_names;
+	return "%c $name %o";
+}
+
+sub opt_spec
+{
+	require SoundSwarm;
+	return (
+		[ "port=i"          => "TCP port to connect to (default ${\SoundSwarm::LIBRARY_PORT()})" ],
+		[ "host=s"          => "host to connect to" ],
+		[ "filename|f=s@"   => "search filenames" ],
+		[ "title|t=s@"      => "search track titles" ],
+		[ "artist|a=s@"     => "search artists" ],
+		[ "album|l=s@"      => "search albums" ],
+	);
+}
+
+sub execute
+{
+	require SoundSwarm::Client::Library;
+	
+	my ($self, $opt, $args) = @_;
+	
+	$self->usage_error("please search for something specific")
+		unless $opt->filename || $opt->title || $opt->artist || $opt->album;
+	
+	my $library = "SoundSwarm::Client::Library"->new({
+		maybe port => $opt->port,
+		maybe host => $opt->host,
+	});
+	
+	my $results = $library->search_tracks({
+		maybe filename => $opt->filename,
+		maybe title    => $opt->title,
+		maybe artist   => $opt->artist,
+		maybe album    => $opt->album,
+	});
+	
+	print "$_->{filename}\n" for @$results;
+}
+
+1;
+

lib/App/SoundSwarm/Command/skip.pm

+package App::SoundSwarm::Command::skip;
+
+use strict;
+use warnings;
+use App::SoundSwarm -command;
+
+sub abstract
+{
+	return "skip the current track";
+}
+
+sub command_names
+{
+	return qw( skip skidoodle );
+}
+
+sub usage_desc
+{
+	my $class  = shift;
+	my ($name) = $class->command_names;
+	return "%c $name %o";
+}
+
+sub opt_spec
+{
+	require SoundSwarm;
+	return (
+		[ "port=i"  => "TCP port to connect to (default ${\SoundSwarm::PLAYER_PORT()})" ],
+		[ "host=s"  => "host to connect to" ],
+	);
+}
+
+sub execute
+{
+	require SoundSwarm::Client::Player;
+	
+	my ($self, $opt, $args) = @_;
+	my $player = "SoundSwarm::Client::Player"->new(%$opt);
+	print $player->skip->{status}, "\n";
+}
+
+1;
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.