Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 98 lines (75 sloc) 2.103 kB
#!/usr/bin/perl
our $APP = 'cpmpd';
our $VERSION = 0.2;
use strict;
use Getopt::Long;
use Pod::Usage;
#FIXME throw this crap in a config file
my $base = '/mnt/Music_1';
my $target = "$ENV{HOME}/ToTransfer";
my $user = 'scp1';
my $host = '192.168.1.100';
my $port = 19216;
my $scp = '/usr/bin/scp';
chomp(my $file = `mpc -h $host --format %file%|head -1`);
my $path = "$base/$file";
my ($basename) = $path =~ m;.+/(.+)$;;
my ($album) = $path =~ m;(.+)/.+$;;
my ($albname) = $album =~ m;.+/(.+)$;;
our($opt_album) = undef;
our(@opt_search);
if(!@ARGV) {
get_track();
}
GetOptions(
'album' => \&get_album,
'track' => \&get_track,
'dest:s' => \$target,
'search=s{1,}' => \@opt_search,
'help' => sub { pod2usage(verbose => 1); exit(0); },
'man' => sub { pod2usage(verbose => 3); exit(0); },
);
search(@opt_search) if(@opt_search);
sub get_album {
printf("\e[38;5;208m\e[1m$albname\e[0m => \e[1m$target\e[0m\n");
transfer($album);
}
sub get_track {
printf("\e[38;5;196m\e[1m$basename\e[0m => \e[1m$target\e[0m\n");
transfer($path);
}
sub search {
my @search = @_;
my $query = join(' ', @search);
chomp(my @result = `mpc -h $host search $query`);
if(@result) {
map{$_ = "$base/$_"} @result;
transfer(@result);
}
exit(0);
}
sub transfer {
my @files = @_;
#FIXME skip .{jpg,nfo,sfv,m3u} etc. grep for {mp3,flac}?
# use find on remote host? what about albums/single tracks?
for(@files) {
$_ =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g;
system("$scp -P $port -r $user\@$host:\"$_\" $target");
}
exit(0);
}
=pod
=head1 NAME
mpdcp - copy music from a (remote) MPD server
=head1 DESCRIPTION
mpdcp is cool
=head1 OPTIONS
--dest set target destination
--album copy the now playing album to target
--track copy the now playing track to target
--search search the MPD db and copy results to target
--help show the help and exit
--man show the manpage and exit
=head1 COPYRIGHT
Copyright (C) Magnus Woldrich 2010
=cut
Jump to Line
Something went wrong with that request. Please try again.