From 8545d94d183158243c15b373d7508ca1b5bafd0c Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 7 Jun 2017 10:33:45 +0200 Subject: bin: added the xspf_extractor binary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- bin/xspf_extractor | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 bin/xspf_extractor 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à +# +# 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 . + +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 < + +Options: + --version|-v Print the version of this program. + --help|-h Print this message. +EOF + + exit $code; +} + +sub version { + print < +License GPLv3+: GNU GPL version 3 or later . +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); +} -- cgit v1.2.3