#!/usr/bin/perl #Copyright (c) 2008, Zane C. Bowers #All rights reserved. # #Redistribution and use in source and binary forms, with or without modification, #are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. #IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, #INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, #BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR #OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF #THE POSSIBILITY OF SUCH DAMAGE. use strict; use warnings; use Getopt::Std; #print version sub main::VERSION_MESSAGE { print "pm3umpdl 1.0.0\n"; }; #exit after printing help or version $Getopt::Std::STANDARD_HELP_VERSION="TRUE"; #print help sub main::HELP_MESSAGE { print "\n". "-c Clear the playlist first.". "-f The pls file to load.\n". "-h Print this.\n". "-l If playing, start at the last.\n". "-p Play after load.\n"; }; my %opts; getopts("f:vhcp", \%opts); if (defined($opts{h})){ &main::VERSION_MESSAGE; &main::HELP_MESSAGE; exit; }; if (defined($opts{v})){ &main::VERSION_MESSAGE; exit; }; if (!defined($opts{f})){ print "No pls file specified."; exit 1; }; if (defined($opts{c})){ system('mpc', 'clear'); } open(m3ufile, $opts{f})||die("Could not open ".$opts{f}); my @decommented = grep {!/^#/} ; close(m3ufile); my $int=0; while (defined($decommented[$int])){ system('mpc', 'add', $decommented[$int]); $int++; }; if (defined($opts{p})){ if (defined{$opts{l}}){ my @playlist=`mpc`; system('mpc', 'play', $#playlist + 1) }; system('mpc', 'play'); }; #----------------------------------------------------------- # POD documentation section #----------------------------------------------------------- =pod =head1 NAME pm3umpdl - Loads a pls file into mpd, musicpd. =head1 SYNOPSIS pm3umpdl B<-f> [B<-c>] [B<-l>] [B<-p>] =head1 FLAGS =item -c If set, it will clear the playlist first. =item -f This arguement is required and is the file to load. =item -l If set, along with -p, this will play the last entry. =item -p If set, it =head1 REQUIREMENTS =item mpc http://www.musicpd.org/mpc.shtml =head1 VERSION 1.0.0 =head1 COPYRIGHT Copyright (c) 2008, Zame C. Bowers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS` OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =head1 SCRIPT CATEGORIES Networking =head1 OSNAMES unix =head1 README pm3umpdl - Loads a pls file into mpd, musicpd. =cut #----------------------------------------------------------- # End of POD documentation #-----------------------------------------------------------