#!/usr/bin/perl # # Version 0.3 Jun 2009 # # Author Stephen Kingham, Stephen.Kingham@kingtech.com.au # # https://www.kingtech.com.au # # License and distributed under the GNU General Public License (GPL) # # Copyright (C) 2009 Stephen Kingham # # 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. # # This programme is just a wrapper for # lame, # flac, and # mplayer # # Versions # 0.1 May 2009 - Can convert .wav, .mp3, and .flac, to mp3. # - It also copies all the other files over to the specified # destination and recreate the directory structure. # - If Folder.jpg does not exist it will create one by copying from an available .jpg file. # 0.2 Jun 2009 -Uses mplayer to convert .wma audio files. # 0.3 Jun 2009 - Uses eyeD3 to add album artwork to first mp3 file for iTunes to display the album art # - Create Folder.jpg as a 200x200 using the largest jpeg # - Only add the artwork if atleast one mp3 file was created, or # with -a add the artwork to all the mp3s. # - Added some LAME parameters to include VBR along with the CBR # #use warnings; #use diagnostics; #use strict; use File::Find; use File::Basename; # use Cwd; my $RootDir = getcwd; my $debug="off"; my $srcDirAbs=$RootDir . "/" . "music-raw"; # # Adsolute root Directory to source all the music from # my $srcFileRel=" "; # this is the source file less the root path, ie relative name my $srcFileAbs=" "; # Absulte filename of the file we are processing my $srcFileExtension=" "; # Just the extension of the filename, eg .wav my $srcFilePathAbs=" "; # the full path of the source file, ie without the filename my $srcFilename=" "; # just the filname of the source file without extension or path my $srcFileDirRel=" "; # the path to the file being processed less the root part of the directory # my $dstDirAbs=$RootDir . "/" . "music-mp3"; # # Absolute root directory to put all the mp3 files # my $dstFileAbs=" "; # Absulte filename of the file we are processing my $dstFileMP3Abs=" "; # Destination filename with the extension changed to .mp3 my $dstFileWAVAbs=""; # Destination filename with .wav extension as intermediate to converting to mp3 my $dstFileImage=""; # my @Args=(); # my $Overwrite = "No"; my $Owner = "www-data"; my $Group = "www-data"; my $bitRate = 0; my $VBR = "V0"; my $WasAtLeastOneMP3Created = "no"; my $AddArtWorkToAll="no"; my $Help="no"; # my $argnum = 0; my @paths = (); my $pathPart=""; my $i=0; my $albumName=""; my $artistName=""; my $Silent="No"; # foreach $argnum (0 .. $#ARGV) { # if ( $ARGV[$argnum] eq "-f" ) { $Overwrite="yes" }; if ( $ARGV[$argnum] eq "debug" ) { $debug="on" }; if ( $ARGV[$argnum] eq "-o" ) { $Owner=$ARGV[$argnum+1] }; if ( $ARGV[$argnum] eq "-g" ) { $Group=$ARGV[$argnum+1] }; if ( $ARGV[$argnum] eq "-s" ) { $srcDirAbs=$ARGV[$argnum+1] }; if ( $ARGV[$argnum] eq "-d" ) { $dstDirAbs=$ARGV[$argnum+1] }; if ( $ARGV[$argnum] eq "-b" ) { $bitRate=$ARGV[$argnum+1] }; if ( $ARGV[$argnum] eq "-S" ) { $Silent="Yes" }; if ( $ARGV[$argnum] eq "-a" ) { $AddArtWorkToAll="Yes" }; if ( $ARGV[$argnum] eq "-V0" ) { $VBR="-V0" }; if ( $ARGV[$argnum] eq "-V1" ) { $VBR="-V1" }; if ( $ARGV[$argnum] eq "-V2" ) { $VBR="-V2" }; if ( $ARGV[$argnum] eq "-V3" ) { $VBR="-V3" }; if ( $ARGV[$argnum] eq "-V4" ) { $VBR="-V4" }; if ( $ARGV[$argnum] eq "-V5" ) { $VBR="-V5" }; if ( $ARGV[$argnum] eq "-V6" ) { $VBR="-V6" }; if ( $ARGV[$argnum] eq "-h" || $ARGV[$argnum] eq "-help" ) { $Help="yes" }; }; # if ( $srcDirAbs eq $dstDirAbs ) { print "Destination directory must be different from the source directory\n\n"; $Help="yes"; } if ( $Help eq "yes" ) { print "This programme will create a new directory tree from a source directories, and\n"; print "will convert any audio files to mp3s. It will add to the mp3s the Album Title and the Artist\n"; print "as ID3 version v2.3 tags. It assumes the Album Title is the name of the directory, and the\n"; print "Artis is the parent directory.\n"; print "It will also create a Folder.jpg 200x200 pixels using the larges jpeg,\n"; print "which it will add to every mp3 as a ID3 version v2.3 tag.\n"; print "Copyright (C) 2009 Stephen Kingham\n"; print "More info at www.kingtech.com.au\n"; print "\n"; print "This program is free software; you can redistribute it and/or\n"; print "modify it under the terms of the GNU General Public License\n"; print "as published by the Free Software Foundation; either version 3\n"; print "of the License, or (at your option) any later version.\n"; print "\n"; print "This program is distributed in the hope that it will be useful,\n"; print "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"; print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"; print "GNU General Public License for more details.\n"; print "\n"; print "Version 0.3 Jun 2009\n\n"; print "usage [-f] [-o OWNER] [-g GROUP] [-s SOURE-DIR] [-d DESTINATION DIR] [-b BITRATE] [-S]\n"; print " -f overwrite all files in the destination [do not overwrite]\n"; print " -o OWNER change the owner of the files/directories to OWNER, [www-data]\n"; print " -g GROUP change the group of the files/directories to GROUP, [www-data]\n"; print " -s DIR The root directory to find all the source audio files [./music-raw]\n"; print " -d DIR The destination root directory to put the converted audio files ./music-mp3]\n"; print " -b BITRATE LAME parameter CBR bit rate do you want the mp3, [VBR is used as the default]\n"; print " -Vn LAME parameter VBR V0=high good for HiFi (245kbps), V3=iPOD (175kbps) [V0 is the default]\n"; print " -a Add artwork to all the mp3s\n"; print " -S Run silently, otherwise advise each action [do not run silent]\n"; print "Uses:\n"; print " LAME (http://www.mp3dev.org/),\n"; print " MPLAYER (http://www.mplayerhq.hu/design7/news.html),\n"; print " FLAC (http://flac.sourceforge.net), and\n"; print " eyeD3 (http://eyed3.nicfit.net/).\n"; exit 0; } # # if ($debug eq "on") { print "DEBUG:\n -f=$Overwrite\n debug=$debug\n -o=$Owner\n -g=$Group\n -s=$srcDirAbs\n -d=$dstDirAbs\n -b=$bitRate\n" }; # find will find every file, we start find sub { $srcFileAbs = $File::Find::name; if ($debug eq "on") { print "DEBUG: Start of a new file\n\nsrc file Abs=$srcFileAbs\n" }; # Split the source file to find the relative path/filename of the src file # Then turn that into the absulute destination filename (undef, $srcFileRel) = split ( $srcDirAbs, $srcFileAbs ); $dstFileAbs = $dstDirAbs . "/" . $srcFileRel; $dstFileAbs =~ s/\/\//\//g; if ($debug eq "on") { print "dst file Abs=$dstFileAbs\n" }; if ( -d $srcFileAbs ) { # So $srcFileAbs is a directory, we need to create the destination directory if ($debug eq "on") { print "Directory\n" }; # # create the directory in the new location if it does not already exist # if ( -d "$dstFileAbs" ) { if ($debug eq "on") { print "destination directory already exists.\n" }; } else { @Args = ("mkdir", $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "Created new destination directory\n" }; }; } else { # # So it is a file and not a directory, we need to copy the file to the new location and # convert any audio files to mp3's # if ($debug eq "on") { print "File\n" }; # # Find the file's extension ($srcFilename, $srcFilePathAbs, $srcFileExtension) = fileparse( $srcFileAbs, qr/\.[^.]*/); (undef, $srcFileDirRel) = split ( $srcDirAbs, $srcFilePathAbs ); if ($debug eq "on") { print "srcPath=$srcFilePathAbs , Filename=$srcFilename, extension=$srcFileExtension, Rel=$srcFileDirRel\n" }; # if ( $srcFileExtension eq ".wav" || $srcFileExtension eq ".WAV" || $srcFileExtension eq ".wma" || $srcFileExtension eq ".WMA" || $srcFileExtension eq ".m4a" || $srcFileExtension eq ".M4A" || $srcFileExtension eq ".mp4" || $srcFileExtension eq ".MP4" || $srcFileExtension eq ".mp3" || $srcFileExtension eq ".MP3" || $srcFileExtension eq ".flac" || $srcFileExtension eq ".FLAC" ) { # We found an audio file to convert if ($debug eq "on") { print "File is an audio file.\n" }; # $dstFileMP3Abs = $dstDirAbs . "/" . $srcFileDirRel . "/" . $srcFilename . ".mp3"; $dstFileMP3Abs =~ s/\/\//\//g; # check if the mp3 file already exists and proceed only if user wants it overwritten if ( -e $dstFileMP3Abs && $Overwrite eq "No" ) { if ($debug eq "on") { print "File already exists and we are going to leave it -f=$Overwrite.\n" }; } else { # Lets work out the Album and Artist name from the names of the directories # @paths = split(/\//, $srcFileDirRel); if ($debug eq "on") { print "srcFileDirRel=$srcFileDirRel all=@paths\n" }; $albumName=""; $artistName=""; $i=0; foreach $pathPart ( @paths ) { if ($debug eq "on") { print "i=$i path = $paths[$i] pathPart=$pathPart\n" }; if ($i > 0 ) { $albumName=$paths[$i]; # replace -- with - $albumName =~ s/--/-/g; $albumName =~ s/--/-/g; $albumName =~ s/--/-/g; $artistName=$paths[$i-1]; $artistName =~ s/--/-/g; $artistName =~ s/--/-/g; $artistName =~ s/--/-/g; } $i=$i+1; } if ($debug eq "on") { print "albumName=$albumName artistName=$artistName\n" }; # If the audio filw is an m4a or mp4 then we first convert it to a wav file # if ( $srcFileExtension eq ".m4a" || $srcFileExtension eq ".M4A" || $srcFileExtension eq ".mp4" || $srcFileExtension eq ".MP4" ) { # Need to a new destination filename with .wav $dstFileWAVAbs = $dstDirAbs . "/" . $srcFileDirRel . "/" . $srcFilename . ".wav"; $dstFileWAVAbs =~ s/\/\//\//g; @Args = ("nice", "faad", $srcFileAbs, "-o", $dstFileWAVAbs, "-q" ); if ($debug eq "on") {print "Going to @Args\n"}; if ($Silent eq "No") { print "Creating $dstFileWAVAbs intermediate step to make mp3\n" }; system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } $srcFileAbs = $dstFileWAVAbs; if ($debug eq "on") { print "New srcFileAbs=$srcFileAbs\n" }; } if ( $srcFileExtension eq ".flac" || $srcFileExtension eq ".FLAC" ) { # If .flac we first need to convert it to a .wav file # Need to a new destination filename with .wav $dstFileWAVAbs = $dstDirAbs . "/" . $srcFileDirRel . "/" . $srcFilename . ".wav"; $dstFileWAVAbs =~ s/\/\//\//g; # -d decode # -f overwrite destination file # -s run silently # -o write ouput to file @Args = ("nice", "flac", "-d", "-f", "-s", "-o", $dstFileWAVAbs, $srcFileAbs ); if ($debug eq "on") {print "Going to @Args\n"}; if ($Silent eq "No") { print "Creating $dstFileWAVAbs intermediate step to make mp3\n" }; system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } $srcFileAbs = $dstFileWAVAbs; if ($debug eq "on") { print "New srcFileAbs=$srcFileAbs\n" }; } # If audio file is .wma then we first have to convert to .wav # if ( $srcFileExtension eq ".wma" || $srcFileExtension eq ".WMA" ) { # If .wma we first need to convert it to a .wav file # Need to a new destination filename with .wav $dstFileWAVAbs = $dstDirAbs . "/" . $srcFileDirRel . "/" . $srcFilename . ".wav"; $dstFileWAVAbs =~ s/\/\//\//g; $dstFileWAVAbs =~ s/\,//g; # mplayer needs the w32codecs libdvdcss2 installed, using apt-get follow these instructions: # sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list --output-document=/etc/apt/sources.list.d/medibuntu.list # sudo apt-get update # sudo apt-get install medibuntu-keyring # sudo apt-get update # sudo apt-get install w32codecs libdvdcss2 # # mplayer arguments # -vo null = no video output # -vc dummy = no video codec # -af resample=44100 = set audio filter to typical CD quality # -ao pcm:waveheader = Audio Driver is PCM with the waveheader # file= = write the output to filename # -nolirc Turns off LIRC support. # -really-quiet = run without any output to shell # look at using -lavcopts acodec=wmav1 wmav1 or wmav2 @Args = ("nice", "mplayer", "-nolirc", "-really-quiet", "-vo", "null", "-vc", "null", "-af", "resample=44100", "-ao", "pcm:waveheader:file=$dstFileWAVAbs", "$srcFileAbs" ); if ($debug eq "on") {@Args = ("nice", "mplayer", "-nolirc", "-vo", "null", "-vc", "null", "-af", "resample=44100", "-ao", "pcm:waveheader:file=$dstFileWAVAbs", "$srcFileAbs" ) }; if ($debug eq "on") {print "DEBUG: Going to @Args\n"}; if ($Silent eq "No") { print "Creating $dstFileWAVAbs intermediate step to make mp3\n" }; system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } $srcFileAbs = $dstFileWAVAbs; if ($debug eq "on") { print "New srcFileAbs=$srcFileAbs\n" }; } # Now we use LAME to convert to mp3 # # -S run silent # -h highest quality # -b bit rate # (default) joint stereo if ( $artistName eq "" || $albumName eq "" ) { if ( $VBR eq "" ) { @Args = ("nice", "lame", "-S", "-h", "--tt", $srcFilename, "-b", $bitRate, $srcFileAbs, $dstFileMP3Abs); } else { @Args = ("nice", "lame", "-S", "-h", "--tt", $srcFilename, $VBR, $srcFileAbs, $dstFileMP3Abs); } } else { if ( $VBR eq "" ) { @Args = ( "nice", "lame", "-S", "-h", "--ta", $artistName, "--tl", $albumName, "--tt", $srcFilename, "-b" , $bitRate, $srcFileAbs, $dstFileMP3Abs); } else { @Args = ( "nice", "lame", "-S", "-h", "--ta", $artistName, "--tl", $albumName, "--tt", $srcFilename, $VBR, $ srcFileAbs, $dstFileMP3Abs); } } if ($debug eq "on") {print "Going to @Args\n"}; if ($Silent eq "No") { print "Creating $dstFileMP3Abs\n" }; system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "Converted file -f=$Overwrite.\n" }; # $WasAtLeastOneMP3Created="YES"; @mp3sToAddGraphicTo = ( @mp3sToAddGraphicTo, $dstFileMP3Abs ); # }; # So that changeing the owner and permissions work: $dstFileAbs = $dstFileMP3Abs; if ( -e $dstFileWAVAbs ) { @Args = ( "rm", $dstFileWAVAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } } # } else { # This is a not an audio file, if ( $srcFileExtension eq ".jpg" || $srcFileExtension eq ".JPG" || $srcFileExtension eq ".jpeg" || $srcFileExtension eq ".JPEG" ) { $dstFileImage = $dstDirAbs . "/" . $srcFileDirRel . "/" . "Folder.jpg"; $dstFileImage =~ s/\/\//\//g; if ( $dstFileImage ne $dstFileAbs ) { # The source file is not going to overwrite an existing destination Folder.jpg, # and it does not already exist # if ( -e $dstFileAbs && $Overwrite eq "No" ) { if ($debug eq "on") { print "File already exists (image) $dstFileAbs\n" }; if ($Silent eq "No") { print "File already exists (image) $dstFileAbs\n" }; } else { # Now we want to copy the original jpeg file to the new location # @Args = ("cp", "-f", $srcFileAbs, $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "Copied the file from $srcFileAbs $dstFileAbs -f=$Overwrite.\n" }; if ($Silent eq "No") { print "Copied $dstFileAbs\n" }; } } if ( -s $srcFileAbs > -s $dstFileImage || ( ! -e $dstFileImage ) ) { # The src image is larger than the existing Folder.jpg, or # destination Folder.jpg does not exist # if ( -e $dstFileImage && $Overwrite eq "No" ) { if ($debug eq "on") { print "A better Folder.jpg already exists.\n" }; if ($Silent eq "No" && $dstFileImage eq $dstFileAbs ) { print "Not moving Folder.jpg because a better Folder.jpg already exists.\n" }; } else { # @Args = ("convert", $srcFileAbs, "-resize", "200x200!", $dstFileImage ); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "Resized $srcFileAbs to 200x200 $dstFileImage -f=$Overwrite.\n" }; if ($Silent eq "No") { print "Resized $srcFileAbs to 200x200 Folder.jpg\n" }; # } } else { if ($debug eq "on") { print "A better Folder.jpg already exists.\n" }; if ($Silent eq "No" && $dstFileImage eq $dstFileAbs ) { print "Not moving Folder.jpg because a better Folder.jpg already exists.\n" }; } # } elsif ( -e $dstFileAbs && $Overwrite eq "No") { # So it is not an audio or graphic so it is some general file # if ($debug eq "on") { print "File already exists and we are going to leave it -f=$Overwrite.\n" }; if ($Silent eq "No") { print "File already exists $dstFileMP3Abs\n" }; } else { @Args = ("cp", "-f", $srcFileAbs, $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "Copied the file from $srcFileAbs $dstFileAbs -f=$Overwrite.\n" }; if ($Silent eq "No") { print "Copied $dstFileAbs\n" }; }; }; }; # Now we set the permissions and owner if ( $Owner ne "" ) { @Args = ("chown", "$Owner", $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } } # Now we set the permissions and owner if ( $Group ne "" ) { @Args = ("chgrp", "$Group", $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?\n"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } } @Args = ("chmod", "755", $dstFileAbs); system(@Args) == 0 or die "ERROR: system @Args failed: $?"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($debug eq "on") { print "\n\n"; #sleep 3; }; }, $srcDirAbs; if ( $AddArtWorkToAll eq "Yes" ) { find sub { $srcFileAbs = $File::Find::name; if ($debug eq "on") { print "DEBUG: file to add artwork to=$srcFileAbs\n" }; ($srcFilename, $srcFilePathAbs, $srcFileExtension) = fileparse( $srcFileAbs, qr/\.[^.]*/); $dstFileImage = $srcFilePathAbs . "Folder.jpg"; if ( $srcFileExtension eq ".mp3" && ! -e $dstFileImage) { if ($Silent eq "No") { print "There is no Folder.jpg in $srcFilePathAbs\n" }; } if ( $srcFileExtension eq ".mp3" && -e $dstFileImage) { # @Args = ("nice eyeD3 --to-v2.3 --add-image=\"$dstFileImage\":FRONT_COVER \"$srcFileAbs\" >/dev/null"); system(@Args) == 0 or die "ERROR: system @Args failed: $?"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($Silent eq "No") { print "Added $dstFileImage to $srcFileAbs\n" }; } }, $dstDirAbs; } else { if ( $WasAtLeastOneMP3Created eq "YES" ) { foreach $srcFileAbs ( @mp3sToAddGraphicTo ) { if ($debug eq "on") { print "DEBUG: Going to add album art to $srcFileAbs\n" }; ($srcFilename, $srcFilePathAbs, $srcFileExtension) = fileparse( $srcFileAbs, qr/\.[^.]*/); $dstFileImage = $srcFilePathAbs . "Folder.jpg"; if ( $srcFileExtension eq ".mp3" && ! -e $dstFileImage) { if ($Silent eq "No") { print "There is no Folder.jpg in $srcFilePathAbs\n" }; } if ( $srcFileExtension eq ".mp3" && -e $dstFileImage) { #@Args = ("nice", "eyeD3", "--add-image=Folder.jpg:FRONT_COVER", $srcFileAbs, ">/dev/null"); @Args = ("nice eyeD3 --to-v2.3 --add-image=\"$dstFileImage\":FRONT_COVER \"$srcFileAbs\" >/dev/null"); system(@Args) == 0 or die "ERROR: system @Args failed: $?"; if ($? == -1) { print "ERROR: failed to execute @Args\n $!\n"; } elsif ($? & 127) { printf "ERROR: @Args\n child died with signal %d, %s\n", ($? & 127), ($? & 128) ? 'with' : 'without'; exit 0; } else { if ($debug eq "on") { printf "@Args\n child exited with value %d\n", $? >> 8 }; } if ($Silent eq "No") { print "Added $dstFileImage to $srcFileAbs\n" }; } } } }