diff options
| author | Miquel Sabaté Solà <msabate@suse.com> | 2017-06-07 10:33:45 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <msabate@suse.com> | 2017-06-07 10:33:45 +0200 |
| commit | 8545d94d183158243c15b373d7508ca1b5bafd0c (patch) | |
| tree | dfc41dc204621e6af4feb5e7984380a24c04b2bc /bin | |
| parent | 3110b04d191df6ea35ae0671a0c01be89844ec74 (diff) | |
| download | dotfiles-8545d94d183158243c15b373d7508ca1b5bafd0c.tar.gz dotfiles-8545d94d183158243c15b373d7508ca1b5bafd0c.zip | |
bin: added the xspf_extractor binary
This simple script copies the files described in an XSPF file into a
directory. For now it's quite simplistic and assumes quite a lot of stuff...
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/xspf_extractor | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/bin/xspf_extractor b/bin/xspf_extractor new file mode 100755 index 0000000..1bb3631 --- /dev/null +++ b/bin/xspf_extractor @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w +# Copyright (C) 2017 Miquel Sabaté Solà <mikisabate@gmail.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use strict; + +# Check that XML::LibXML is installed, and die if it isn't. This can be +# installed in openSUSE with the 'perl-XML-LibXML' package. +my $xml = eval { + require XML::LibXML; + Term::ReadKey->import(); + 1; +}; +if (!$xml) { + print "Please install the 'XML::LibXML' module!\n"; + exit 1; +} + +use Getopt::Long; +use File::Copy; +use XML::LibXML; + +# Prevent any UTF-8 oddities. +use utf8; +binmode(STDOUT, ":utf8"); + +## +# Helper methods. + +sub help { + my ($code) = @_; + + print <<EOF; +Usage: $0 <options> <XSPF file> <directory> + +Options: + --version|-v Print the version of this program. + --help|-h Print this message. +EOF + + exit $code; +} + +sub version { + print <<EOF; +xspf_extractor version 0.1 +Copyright (C) 2017 Miquel Sabaté Solà <mikisabate\@gmail.com> +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF + + exit 0; +} + +## +# Parse flags and check that everything is alright. + +my %opt; + +GetOptions(\%opt, "help|h", "version|v"); + +help(0) if $opt{"help"}; +version() if $opt{"version"}; + +my ($file, $dir) = @ARGV; +if (!defined($file) || !defined($dir)) { + print "You must provide the source file and the directory\n"; + help(1); +} + +if (! -e $file) { + print "Source XSPF file '$file' does not exist!\n"; + exit 1; +} + +if (! -d $dir) { + print "Destination directory '$dir' does not exist!\n"; + exit 1; +} + +## +# Parse the given XSPF document. + +my $dom = XML::LibXML->new->parse_file($file); +for my $node ($dom->getElementsByTagName('track')) { + my $location = $node->getElementsByTagName("location")->get_node(0)->textContent; + copy($location, $dir); +} |
