X-Git-Url: http://git.grml.org/?a=blobdiff_plain;ds=sidebyside;f=usr_bin%2Farename.pl;fp=usr_bin%2Farename.pl;h=465df5f7ebaea798535258bad3ca89d5884716ee;hb=19329328b4bf569b7273e0831f271187af73d665;hp=0000000000000000000000000000000000000000;hpb=ce32321423d0be102417d14d72d6a2f3594f5c33;p=grml-scripts.git diff --git a/usr_bin/arename.pl b/usr_bin/arename.pl new file mode 100755 index 0000000..465df5f --- /dev/null +++ b/usr_bin/arename.pl @@ -0,0 +1,793 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Getopt::Std; +use File::Basename; +use File::Copy; +use MP3::Tag; +use Ogg::Vorbis::Header; + +# documentation {{{ +=head1 NAME + +arename.pl - automatically rename audio files by tagging information + +=head1 SYNOPSIS + +arename.pl [OPTION(s)] FILE(s)... + +=head1 OPTIONS AND ARGUMENTS + +=over 8 + +=item B<-d> + +Go into dryrun mode. + +=item B<-f> + +Overwrite files if needed. + +=item B<-h> + +Display a short help text. + +=item B<-V> + +Display version infomation. + +=item B<-v> + +Enable verbose output. + +=item B<-p> EprefixE + +Define a prefix for destination files. + +=item B<-T> EtemplateE + +Define a compilation template. + +=item B<-t> EtemplateE + +Define a generic template. + +=item I + +Input files, that are subject for renaming. + +=back + +=head1 DESCRIPTION + +B is a tool that is able to rename audio files by looking at +a file's tagging information, from which it will assemble a consistent +destination file name. The format of that filename is configurable for the +user by the use of template strings. + +B currently supports two widely used audio formats, namely +MPEG Layer3 and ogg vorbis. The format, that B will assume +for each input file is determined by the file's filename-extension +(I<.mp3> vs. I<.ogg>). The extension check is case-insensitive. + +By default, B will refuse to overwrite destination files, +if the file in question already exists. You can force overwriting by +supplying the B<-f> option. + +=head1 FILES + +B uses up to two configuration files. As for most programs, +the script will try to read a configuration file, that is located in the +user's I. In addition to that, it will try to load I +configuration files, if it finds appropriately named files in the +I. + +=over 8 + +=item B<~/.arenamerc> + +per-user global configuration file. + +=item B<./.arename.local> + +per-directory local configuration file. + +=back + +=head2 File format + +The format of the aforementioned files is pretty simple. +It is parsed line by line. Empty lines, lines only containing whitespace +and lines, whose first non whitespace character is a hash character (I<#>) +are ignored. + +Each line consists of one or two parts. If there are two parts, +they are separated by whitespace. The first part of the line will be used +as the identifier of a setting (eg. I). The second part (read: the +rest of the line) is used as the value of the setting. (No quoting, or whatsoever +is required.) + +If a line consists of only one part, that means the setting is switched on. + +=head2 Configuration file example + + # switch on verbosity + verbose + + # the author is crazy! use a sane template by default. :-) + template &artist - &album (&year) - &tracknumber. &tracktitle + +=head1 SETTINGS + +The following settings are supported in all configuration files: + +=over 8 + +=item B + +Defines a template to use with files that provide a compilation tag +(for 'various artist' CDs, for example). This setting can still be +overwritten by the B<-T> command line option. (default value: +I) + +=item B + +Defines a default year, for files, that lack this information. +(default value: I) + +=item B + +Defines a prefix for destination files. This setting can still be +overwritten by the B<-p> command line option. (default value: I<.>) + +=item B + +Tagging information strings may contain slashes, which is a pretty bad +idea on most filesystems. Therefore, you can define a string, that replaces +slashes with the value of this setting. (default value: I<_>) + +=item B