| 1 |
#!/usr/bin/env perl |
| 2 |
######################################################################## |
| 3 |
# |
| 4 |
# LICENSE |
| 5 |
# |
| 6 |
# Copyright (C) 2005 Felix Suwald |
| 7 |
# |
| 8 |
# |
| 9 |
# |
| 10 |
# This program is free software; you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License as published by |
| 12 |
# the Free Software Foundation; either version 2 of the License, or (at |
| 13 |
# your option) any later version. |
| 14 |
# |
| 15 |
# |
| 16 |
# This program is distributed in the hope that it will be useful, but |
| 17 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 |
# General Public License for more details. |
| 20 |
# |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU General Public License |
| 23 |
# along with this program; if not, write to the Free Software |
| 24 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, |
| 25 |
# USA. |
| 26 |
# |
| 27 |
######################################################################## |
| 28 |
# |
| 29 |
# TODO 4.1 |
| 30 |
# |
| 31 |
# Check filesystem on mixed mode CDs and copy data content (video, jpgs) |
| 32 |
# to the sound directory. |
| 33 |
# |
| 34 |
# Should postprocessing of wav files be enabled, e.g. using sox for |
| 35 |
# adding fade on lead-in or lead-out, create an option wavcmd? |
| 36 |
# |
| 37 |
# Different cover (sizes) for different formats / qualities. |
| 38 |
# |
| 39 |
# Allow operator to "back_encode" track names to "lower" formats, i.e. |
| 40 |
# to ascii in case files shall be moved to different systems. |
| 41 |
# |
| 42 |
# Change ripopt to an array for a more conveniant switch of rippers. |
| 43 |
# |
| 44 |
# If option verify is used, why not test decoding of flac files and |
| 45 |
# inform operator if decoding fails on some tracks. Or just, in case |
| 46 |
# flac is used, test decoding. |
| 47 |
# |
| 48 |
# Add support for opus, speex, ttaenc or bonk and xspf playlist files. |
| 49 |
# |
| 50 |
# Ensure all comments of a playlist file are copied to a new playlist |
| 51 |
# file when re-encoding. |
| 52 |
# |
| 53 |
######################################################################## |
| 54 |
# |
| 55 |
# CODE |
| 56 |
# |
| 57 |
# ripit.pl - Rips audio CD and encodes files, following steps can be |
| 58 |
# performed (unsorted list): |
| 59 |
# 1) Query CDDB data or text for album/artist/track info |
| 60 |
# 2) Rip the audio files from the CD |
| 61 |
# 3) Encode the wav files |
| 62 |
# 4) ID3 tag the encoded files |
| 63 |
# 5) Extract possible hidden tracks |
| 64 |
# 6) Optional: Create a playlist (M3U) file. |
| 65 |
# 7) Optional: Prepares and sends a CDDB submission. |
| 66 |
# 8) Optional: saves the CDDB file |
| 67 |
# 9) Optional: creates a toc (cue) file to burn a CD in DAO |
| 68 |
# with text |
| 69 |
# 10) Optional: analyze the wavs for gaps and splits them into |
| 70 |
# chunks and/or trim lead-in/out (experimental) |
| 71 |
# 11) Optional: merges wavs for gapless encoding |
| 72 |
# 12) Optional: normalizes the wavs before encoding. |
| 73 |
# 13) Optional: adds coverart to tags of sound files and |
| 74 |
# copies albumcover to encoding directories. |
| 75 |
# 14) Optional: calculates album gain for sound files. |
| 76 |
# 15) Optional: creates a md5sum for each type of sound files. |
| 77 |
# |
| 78 |
# |
| 79 |
# Version 4.0.0_rc_20161009 - October 9th 2016 - Felix Suwald, thanks for input: |
| 80 |
# N. Heberle |
| 81 |
# D. Armstrong |
| 82 |
# T. Kukuk (encoding detection) |
| 83 |
# S. Oosthoek (CD-text) |
| 84 |
# S. Noé |
| 85 |
# P. Reinholdtsen |
| 86 |
# |
| 87 |
# Version 3.9.0 - July 14th 2010 - Felix Suwald, thanks for input: |
| 88 |
# F. Sundermeyer |
| 89 |
# S. Noé |
| 90 |
# Version 3.8.0 - September 28th 2009 - Felix Suwald |
| 91 |
# |
| 92 |
# Version 3.7.0 - May 6th 2009 - Felix Suwald, thanks for input: |
| 93 |
# C. Blank |
| 94 |
# A. Gillis |
| 95 |
# and to all the bug-reporters! |
| 96 |
# Version 3.6.0 - June 16th 2007 - Felix Suwald, thanks for input: |
| 97 |
# C. Blank |
| 98 |
# G. Edwards |
| 99 |
# G. Ross |
| 100 |
# Version 3.5.0 - June 6th 2006 - Felix Suwald, credits to |
| 101 |
# E. Riesebieter (deb-package) |
| 102 |
# C. Walter (normalize option) |
| 103 |
# S. Warten (general support & loop) |
| 104 |
# S. Warten (signal handling) |
| 105 |
# Version 3.4 - December 3rd 2005 - Felix Suwald, credits to |
| 106 |
# M. Bright (infolog file) |
| 107 |
# M. Kaesbauer (lcdproc) and |
| 108 |
# C. Walter (config file). |
| 109 |
# Version 2.5 - November 13th 2004 - Felix Suwald |
| 110 |
# Version 2.2 - October 18th 2003 - Mads Martin Joergensen |
| 111 |
# Version 1.0 - February 16th 1999 - Simon Quinn |
| 112 |
# |
| 113 |
# |
| 114 |
######################################################################## |
| 115 |
# |
| 116 |
# User configurable variables: |
| 117 |
# Keep these values and save your own settings in a config file with |
| 118 |
# option --save! |
| 119 |
# |
| 120 |
my $cddev = "/dev/cdrom";# Path of CD device. |
| 121 |
my $scsi_cddev = ""; # Path of CD device for non audio commands. |
| 122 |
my $outputdir = ""; # Where the sound should go to. |
| 123 |
my $ripopt = ""; # Options for audio CD ripper. |
| 124 |
my $offset = 0; # Sample offset to be used for drive. |
| 125 |
my $accuracy = 0; # Check accuracy of rip using Morituri. |
| 126 |
my $verify = 1; # Rip track $verify times or until identical |
| 127 |
# rip has been detected / riped. |
| 128 |
my $span = ""; # Options for track spans. |
| 129 |
my $ripper = 1; # 0 - dagrab, 1 - cdparanoia, |
| 130 |
# 2 - cdda2wav, 3 - tosha, 4 - cdd. |
| 131 |
my @coder = (0); # 0 - Lame, 1 - Oggenc, 2 - Flac, |
| 132 |
# 3 - Faac, 4 - mp4als, 5 - Musepack, |
| 133 |
# 6 - Wavpack, 7 - ffmpeg, |
| 134 |
# comma separated list. |
| 135 |
my $coverart = 0; # Add cover meta data, (1 yes, 0 no), |
| 136 |
# comma separated list in same order as |
| 137 |
# list of encoders. |
| 138 |
my $coverpath = ""; # Path to cover to be added to sound files. |
| 139 |
my $copycover = ""; # Path to album cover source. |
| 140 |
my $coverorg = 0; # Check for album art at coverartarchive.org |
| 141 |
my $bitrate = 128; # Bitrate for lame, if --vbrmode used, |
| 142 |
# bitrate is equal to the -b option. |
| 143 |
my $maxrate = 0; # Bitrate for lame using --vbrmode, |
| 144 |
# maxrate is equal to the -B option. |
| 145 |
my @quality = (5,3,5,100,0,5);# Quality for lame in vbr mode (0-9), best |
| 146 |
# quality = 0, quality for oggenc (1-10), |
| 147 |
# best = 10; or compression level for Flac |
| 148 |
# (0-8), lowest = 0, quality for Faac |
| 149 |
# (10-500), best = 500, no values for |
| 150 |
# Wavpack and ffmpeg. |
| 151 |
my $qualame = 5; # Same as above, more intuitive. Use quotes |
| 152 |
my $qualoggenc= 3; # if values shall be comma separated lists. |
| 153 |
my $quaflac = 5; # |
| 154 |
my $quafaac = 100; # |
| 155 |
my $quamp4als = 0; # |
| 156 |
my $quamuse = 5; # |
| 157 |
my $lameopt = ""; # |
| 158 |
my $oggencopt = ""; # |
| 159 |
my $flacopt = ""; # |
| 160 |
my $flacdecopt = "-s"; # Options if flac files shall be used for |
| 161 |
# re-encoding. |
| 162 |
my $faacopt = ""; # |
| 163 |
my $mp4alsopt = ""; # |
| 164 |
my $museopt = ""; # |
| 165 |
my $wavpacopt = "-y"; # |
| 166 |
my $ffmpegopt = ""; # |
| 167 |
my $ffmpegsuffix = ""; # The suffix of the encoder used |
| 168 |
my $musenc = "mpcenc"; # The default Musepack encoder. |
| 169 |
my $mp3gain = ""; # The mp3 album gain command with options. |
| 170 |
my $vorbgain = ""; # The vorbis album gain command with options. |
| 171 |
my $flacgain = ""; # The flac album gain command with options. |
| 172 |
my $aacgain = ""; # The aac album gain command with options. |
| 173 |
my $mpcgain = ""; # The mpc album gain command with options. |
| 174 |
my $wvgain = ""; # The wv album gain command with options. |
| 175 |
my $lcd = 0; # Use lcdproc (1 yes, 0 no). |
| 176 |
my $chars = "XX"; # Exclude special chars in file names. |
| 177 |
my $verbose = 3; # Normal output: 3, no output: 0, minimal |
| 178 |
# output: 1, normal without encoder msgs: 2, |
| 179 |
# normal: 3, verbose: 4, extremely verbose: 5 |
| 180 |
my $commentag = ""; # Comment ID3 tag. |
| 181 |
my $genre = ""; # Genre of Audio CD for ID3 tag. |
| 182 |
my $year = ""; # Year of Audio CD for ID3 tag. |
| 183 |
my @flactags = (); # Add special flac tags. |
| 184 |
my @mp3tags = (); # Add special mp3 tags. |
| 185 |
my @oggtags = (); # Add special ogg tags using vorbiscomment. |
| 186 |
my $utftag = 1; # Keep Lame-tags in utf or decode them to |
| 187 |
# ISO8895-1 (1 yes, 0 no). |
| 188 |
my $vatag = 0; # Detect VA style for tagging (1 yes, 0 no, |
| 189 |
# 2 backward style (trackname / artist)). |
| 190 |
my $vastring = "\\bVA\\b|Variou*s|Various Artists|Soundtrack|OST"; |
| 191 |
my $eject = 0; # Eject the CD when done (1 yes, 0 no). |
| 192 |
my $ejectcmd = "eject"; # Command to use for eject |
| 193 |
my $ejectopt = "{cddev}"; # Options to above |
| 194 |
my $quitnodb = 0; # Quit if no CDDB entry found (1 yes, 0 no). |
| 195 |
my $overwrite = "n"; # Overwrite existing directory / rip |
| 196 |
# (n no, y yes, e eject if directory exists) |
| 197 |
my $halt = 0; # Shutdown machine when finished |
| 198 |
# (1 yes, 0 no). |
| 199 |
my $nice = 0; # Set nice for encoding process. |
| 200 |
my $nicerip = 0; # Set nice for ripping process. |
| 201 |
my $savenew = 0; # Saved passed parameters to new config |
| 202 |
# file (1 yes, 0 no). |
| 203 |
my $savepara = 0; # Save parameters passed in config file |
| 204 |
# (1 yes, 0 no). |
| 205 |
my $config = 1; # Use config file to read parameters |
| 206 |
# (1 yes, 0 no). |
| 207 |
my $confdir = ""; # Full path to the users config file. |
| 208 |
my $confname = "config"; # File name of config file. |
| 209 |
my $submission= 1; # Send CDDB submission |
| 210 |
# (1 yes, 0 no). |
| 211 |
my $parano = 1; # Use paranoia mode in cdparanoia |
| 212 |
# (1 yes, 0 no). |
| 213 |
my $playlist = 1; # Do create the m3u playlist file |
| 214 |
# (1 yes, 0 no, 2 no full path in file name). |
| 215 |
my $book = 0; # Merge all tracks into a single file and |
| 216 |
# write a chapter file (1 yes, 0 no). |
| 217 |
my $resume = 0; # Resume a previously started session |
| 218 |
# (1 yes, 0 no). |
| 219 |
my $infolog = ""; # Full path to a text file logging system |
| 220 |
# calls and process information. |
| 221 |
my $interaction = 1; # If 0 do not ask anything, take the 1st |
| 222 |
# CDDB entry found or use default names! |
| 223 |
# (1 yes, 0 no). |
| 224 |
my $underscore = 0; # Use _ instead of spaces in file names |
| 225 |
# (1 yes, 0 no). |
| 226 |
my $lowercase = 0; # Lowercase file names |
| 227 |
# (1 yes for all (1+2), 0 no, 2 only files |
| 228 |
# of tracktemplate, 3 only dirs of |
| 229 |
# dirtemplate). |
| 230 |
my $uppercasefirst = 0; # Uppercase first char in file names |
| 231 |
# (1 yes, 0 no). |
| 232 |
my $archive = 0; # Save CDDB files in ~/.cddb dir |
| 233 |
# (1 yes, 0 no). |
| 234 |
my $mb = 0; # Use the Musicbrainz DB instead of freedb |
| 235 |
# (1 yes, 0 no). |
| 236 |
my $mbrels = 0; # Use the Musicbrainz relationship "work" & |
| 237 |
# check for featured artists (1 yes, 0 no). |
| 238 |
my $mirror = "freedb"; # The host (a freedb mirror) that |
| 239 |
# shall be used instead of freedb. |
| 240 |
my $transfer = "cddb"; # Transfer mode, cddb or http, will set |
| 241 |
# default port to 8880 or 80 (for http). |
| 242 |
my $vbrmode = ""; # Variable bitrate, only used with lame, |
| 243 |
# (new or old), see lame manpage. |
| 244 |
my $proto = 6; # CDDB protocol level for CDDB query. |
| 245 |
my $proxy = ""; # Set proxy. |
| 246 |
my $CDDB_HOST = "freedb.org"; # Set cddb host |
| 247 |
my $mailad = ""; # Users return e-mail address. |
| 248 |
my @threads = 1; # Number of encoding processes for each box |
| 249 |
my @sshlist = (); # List of remote machines. |
| 250 |
my $scp = 0; # Use scp to access files (1 yes, 0 no). |
| 251 |
my $local = 1; # Encode on locale machine (1 yes, 0 no). |
| 252 |
my $wav = 0; # Keep the wav files (1 yes, 0 no). |
| 253 |
my $encode = 1; # Encode the wav files (1 yes, 0 no). |
| 254 |
my $rip = 1; # Rip the CD files (1 yes, 0 no). |
| 255 |
my $cue = 0; # Create a cue-sheet with single tracks |
| 256 |
# (1 yes, 0 no). |
| 257 |
my $cdcue = 0; # Create a cue-file from CD (1 yes, 0 no). |
| 258 |
my $cdid = ""; # The disc-id passed by operator if flac or |
| 259 |
# or wav shall be re-encoded including tag |
| 260 |
# update. |
| 261 |
my $cdtoc = 0; # Create a cd.toc for CDRDAO (1 yes, 0 no). |
| 262 |
my $inf = 0; # Create inf files for wodim (1 yes, 0 no). |
| 263 |
my $loop = 0; # Restart ripit as soon as the previous CD |
| 264 |
# is done. This option will force ejection! |
| 265 |
# (1 yes, 0 no, 2 immediate restart after |
| 266 |
# ripping, experimental, use with caution!). |
| 267 |
my $ghost = 0; # Check and extract ghost songs from all |
| 268 |
# tracks (1 yes, 0 no). |
| 269 |
my $prepend = 2.0; # Extend ghost songs by 2 seconds at the |
| 270 |
# beginning. |
| 271 |
my $extend = 2.0; # Extend ghost songs by 2 seconds at the |
| 272 |
# end. |
| 273 |
my $dpermission = "0755"; # Directory permissions. |
| 274 |
my $fpermission = ""; # Audio and text file permissions. |
| 275 |
my $md5sum = 0; # Generate MD5 sums for every sound file |
| 276 |
# not deleted (1 yes, 0 no). |
| 277 |
my @suffix = (); # Array of suffixes according to coders. |
| 278 |
my $execmd = ""; # Execute a command when done. |
| 279 |
my $precmd = ""; # Execute a command before ripping. |
| 280 |
my $multi = 0; # Not yet official. Do not use! |
| 281 |
my $mbname = ""; # Musicbrainz login name. |
| 282 |
my $mbpass = ""; # Musicbrainz password for ISRC submission. |
| 283 |
my $isrc = 0; # Detect ISRC with icedax (1 yes, 0 no). |
| 284 |
my $mailopt = "-t"; # Define options for sendmail |
| 285 |
my $cdtext = 0; # Check for CD text if no DB entry found |
| 286 |
my $coversize = ""; # Change cover size to an XxY format |
| 287 |
my $discno = 0; # Use disc numbering (0 no or number > 0) |
| 288 |
# |
| 289 |
# New options step 1: Add global variables here above or below in case |
| 290 |
# they shouldn't be user configurable. |
| 291 |
# |
| 292 |
# |
| 293 |
# |
| 294 |
# Directory and track template variables: |
| 295 |
# Contains the format the track names will be written as. |
| 296 |
# The '" and "' are important and must surround the template. |
| 297 |
# Example variables to use are: $tracknum, $album, $artist, $genre, |
| 298 |
# $trackname or $year. |
| 299 |
# E.g. following setting of $tracktemplate produces a track name of |
| 300 |
# "07 The Game - Swandive" : |
| 301 |
# $tracktemplate = '"$tracknum $trackname - $artist"'; |
| 302 |
# |
| 303 |
my @dirtemplate = '"$artist - $album"'; |
| 304 |
my $tracktemplate = '"$tracknum $trackname"'; |
| 305 |
my $trackoffset = 0; |
| 306 |
my $addtrackoffset = 0; |
| 307 |
# |
| 308 |
# |
| 309 |
# LCDproc settings: |
| 310 |
# |
| 311 |
my $lcdhost = "localhost"; |
| 312 |
my $lcdport = "13666"; |
| 313 |
my $lcdline1 = " [initializing] "; |
| 314 |
my $lcdline2 = " ripit-lcd-module "; |
| 315 |
my $lcdline3 = " 2005 "; |
| 316 |
my $lcdoline1 = ""; |
| 317 |
my $lcdoline2 = ""; |
| 318 |
my $lcdoline3 = ""; |
| 319 |
my $lcdproc; |
| 320 |
my $lcdtrackno = 0; |
| 321 |
# |
| 322 |
# |
| 323 |
# |
| 324 |
# Normalize settings: |
| 325 |
# |
| 326 |
my $normalize = 0; # normalize CD, needs 'normalize' in $path. |
| 327 |
my $normcmd = "normalize"; # This might differ for other distros. |
| 328 |
my $normopt = "-b"; # Additional options for normalize. |
| 329 |
my $subdir = "Unsorted"; |
| 330 |
# |
| 331 |
# |
| 332 |
######################################################################## |
| 333 |
# |
| 334 |
# System variables, no user configurable variables below. |
| 335 |
# |
| 336 |
use Encode; # Needed for decode_utf8 calls. |
| 337 |
use Encode::Guess; # Needed for guess_encoding. |
| 338 |
use Fcntl; # Needed for sysopen calls. |
| 339 |
use File::Copy; |
| 340 |
use Getopt::Long qw(:config no_ignore_case); |
| 341 |
use IO::Socket; |
| 342 |
use strict; |
| 343 |
use warnings; |
| 344 |
# |
| 345 |
# Initialize paths. |
| 346 |
# |
| 347 |
my $homedir = "$ENV{HOME}"; |
| 348 |
my $workdir = "$ENV{PWD}"; |
| 349 |
my $usename = "$ENV{USER}"; |
| 350 |
# The hostname is not so important and not available on Ubuntu(s) (?). |
| 351 |
my $hostnam = ""; |
| 352 |
if($ENV{HOSTNAME}) { |
| 353 |
$hostnam = "$ENV{HOSTNAME}"; |
| 354 |
} |
| 355 |
elsif($ENV{HOST}) { |
| 356 |
$hostnam = "$ENV{HOST}"; |
| 357 |
} |
| 358 |
my $charset = ""; |
| 359 |
if($ENV{G_FILENAME_ENCODING}) { |
| 360 |
$charset = "$ENV{G_FILENAME_ENCODING}"; |
| 361 |
} |
| 362 |
else { |
| 363 |
$charset = "$ENV{LANG}"; |
| 364 |
} |
| 365 |
if($charset =~ /UTF-8/) { |
| 366 |
$charset = "UTF-8"; |
| 367 |
} |
| 368 |
elsif($charset =~ /ISO-8859-15/) { |
| 369 |
$charset = "ISO-8859-15"; |
| 370 |
} |
| 371 |
else { |
| 372 |
$charset = "ISO-8859-1"; |
| 373 |
} |
| 374 |
#print ($_,$ENV{$_},"\n") foreach (keys %ENV); |
| 375 |
|
| 376 |
# |
| 377 |
# Initialize global variables. |
| 378 |
# |
| 379 |
my $version = "4.0.0_rc_20161009"; |
| 380 |
my $album_utf8 = ""; |
| 381 |
my $artist_utf8 = ""; |
| 382 |
my $distro = ""; # Linux distribution |
| 383 |
my $categ = ""; # CDDB category |
| 384 |
my $cddbid = 0; # Freedb-ID needed in several subroutines |
| 385 |
my $discid = ""; # MB-discID needed in several subroutines |
| 386 |
my $lameflag = 0; # Flag to check if lame is used, some users |
| 387 |
# are not aware that lame is needed for mp3! |
| 388 |
my $oggflag = 0; # Flag to check if oggenc is used. Needed to |
| 389 |
# load modules if coverart for ogg is used. |
| 390 |
my $wvpflag = 0; # Flag to check wavpack version and its |
| 391 |
# coverart support. |
| 392 |
my $trackselection = ""; # Passed from command line |
| 393 |
my @tracksel = (); # Array of all track numbers, including |
| 394 |
# those not explicitly stated. |
| 395 |
my @seltrack = (); # Array of all track numbers, including |
| 396 |
# those not explicitly stated and ghost |
| 397 |
# songs found by ripper needed by encoder. |
| 398 |
my @framelist = (); # Needed in several subroutines |
| 399 |
my @framelist_orig = (); # Needed in several subroutines |
| 400 |
my @secondlist = (); # Needed in several subroutines |
| 401 |
my @tracklist = (); # Needed in several subroutines |
| 402 |
my @tracklist_modif = (); # Needed when re-encoding |
| 403 |
my @tracktags = (); # Needed in several subroutines |
| 404 |
my %cd = (); # HoH of all CD-data. |
| 405 |
my $cddbsubmission = 2; # If zero then data for CDDB submission is |
| 406 |
# incorrect, if 1: submission OK, if 2: CDDB |
| 407 |
# entry not changed (edited) |
| 408 |
my $wpreset = ""; # Preset written into config file. |
| 409 |
my $wcoder = ""; # Use a comma separated string to write the |
| 410 |
# coder-array into the config file. |
| 411 |
my $wthreads = ""; # Use a comma separated string to write the |
| 412 |
# threads-array into the config file. |
| 413 |
my $wsshlist = ""; # As above for the list of remote machines. |
| 414 |
my $sshflag = 0; # Ssh encoding OK if sshflag == 1. |
| 415 |
my %sshlist = (); # Hash of remote machines. |
| 416 |
my $hiddenflag = 0; |
| 417 |
my $logfile = ""; # Used with not *to-use* option --multi. |
| 418 |
my $help = 0; # Print help and exit if 1. |
| 419 |
my $printver = 0; # Print version and exit if 1. |
| 420 |
my @delname = (); # List of track names being processed, i.e. |
| 421 |
# ready for deletion. |
| 422 |
my @skip = (); # List of merged tracks. |
| 423 |
my @globopt = (); # All encoder options sorted according to |
| 424 |
# encoder. |
| 425 |
my @sepdir = (); # Array of sound directories sorted |
| 426 |
# according to encoder. |
| 427 |
my $wavdir = ""; # (Default) directory for sound. |
| 428 |
my $inputdir = ""; # Directory of snd files (wav or flac) |
| 429 |
# for re-encoding process. |
| 430 |
my $limit_flag = 0; # Directory and file length flag. |
| 431 |
my $va_flag = 0; # VA style flag. |
| 432 |
my $va_delim = "/"; # VA style delimiter. |
| 433 |
my @isrcs = (); # ISRC array. |
| 434 |
my @idata = (); # Array for the MB track IDs. |
| 435 |
my @audio = (); # Array of audio / data tracks. |
| 436 |
# |
| 437 |
# New options step 2: Add global variables here in case they shouldn't |
| 438 |
# be user configurable; additional modules can be added right below. |
| 439 |
# |
| 440 |
# |
| 441 |
# Initialize subroutines without (). |
| 442 |
# |
| 443 |
sub ask_subm; |
| 444 |
sub check_bitrate; |
| 445 |
sub check_cddev; |
| 446 |
sub check_chars; |
| 447 |
sub check_vbrmode; |
| 448 |
sub choose_genre; |
| 449 |
sub copy_cover; |
| 450 |
sub del_wav; |
| 451 |
sub disp_info; |
| 452 |
sub extract_comm; |
| 453 |
sub get_cdid; |
| 454 |
sub get_cover; |
| 455 |
sub get_rev; |
| 456 |
sub get_isrcs; |
| 457 |
sub init_mod; |
| 458 |
sub init_var; |
| 459 |
sub lame_preset; |
| 460 |
sub main_sub; |
| 461 |
sub merge_wav; |
| 462 |
sub write_cddb; |
| 463 |
sub write_wavhead; |
| 464 |
# |
| 465 |
# New options step 3: Do not forget to initialize new subroutines. |
| 466 |
# |
| 467 |
# |
| 468 |
# Define the variables which catch the command line input. |
| 469 |
# The p stands for passed (from command line). |
| 470 |
my ( |
| 471 |
$parchive, $pbitrate, $pmaxrate, $PCDDB_HOST, |
| 472 |
$pcddev, $pcdtoc, @pcoder, $pcommentag, |
| 473 |
$pconfig, @pdirtemplate, $ptracktemplate, $peject, |
| 474 |
$pencode, $pfaacopt, $pflacopt, $plameopt, |
| 475 |
$poggencopt, $pgenre, $phalt, $pinfolog, |
| 476 |
$pinteraction, $plcdhost, $plcdport, $plcd, |
| 477 |
$plocal, $ploop, $plowercase, $pmirror, |
| 478 |
$pmailad, $pmulti, $pnice, $pnormalize, |
| 479 |
$pnormopt, $poutputdir, $pparano, $pplaylist, |
| 480 |
$ppreset, $pproto, $pproxy, @pquality, |
| 481 |
$pripopt, $prip, $pripper, $psavenew, |
| 482 |
$psavepara, $pscp, @psshlist, $psubdir, |
| 483 |
$psubmission, $ptransfer, $punderscore, $putftag, |
| 484 |
$pvbrmode, $pverbose, $pwav, $pyear, |
| 485 |
$presume, $pmerge, $pghost, $pprepend, |
| 486 |
$pextend, $pejectopt, $pejectcmd, $pdpermission, |
| 487 |
$pfpermission, $pmd5sum, $pnicerip, @pthreads, |
| 488 |
$pnormcmd, $pmb, $puppercasefirst, $pexecmd, |
| 489 |
$pspan, $poverwrite, $pquitnodb, $pbook, |
| 490 |
$pmusenc, $pmp4alsopt, $pmuseopt, $pinf, |
| 491 |
$pscsi_cddev, $pwavpacopt, $pffmpegopt, $pffmpegsuffix, |
| 492 |
$pprecmd, $pcoverart, $pcoverpath, $pcdcue, |
| 493 |
$pvatag, $pvastring, $pmp3gain, $pvorbgain, |
| 494 |
$pflacgain, $paacgain, $pmpcgain, $pwvgain, |
| 495 |
@pmp3tags, $pcopycover, $ptrackoffset, $pmbname, |
| 496 |
$pmbpass, $pisrc, $pinputdir, $pcdid, |
| 497 |
$pflacdecopt, $paccuracy, $paddtrackoffset, $pverify, |
| 498 |
$poffset, $pmailopt, @pflactags, @poggtags, |
| 499 |
$pcdtext, $pmbrels, $pcoverorg, $pconfdir, |
| 500 |
$pconfname, $pcoversize, $pdiscno, $pcue, |
| 501 |
); |
| 502 |
# |
| 503 |
# New options step 4: For distinction of variables passed on the command |
| 504 |
# line and those from the configuration file, introduce for each new |
| 505 |
# option the variable name prefixed with 'p', 'p' stands for passed. |
| 506 |
# |
| 507 |
# |
| 508 |
######################################################################## |
| 509 |
# |
| 510 |
# Get the parameters from the command line. |
| 511 |
# |
| 512 |
# available: E jJkK |
| 513 |
# already used: aAbBcCdDe fFgGhiI lLmMnNoOpPqQrRsStTuUvVwWxXyYzZ |
| 514 |
# |
| 515 |
GetOptions( |
| 516 |
"accuracy|Q!" => \$paccuracy, |
| 517 |
"archive|a!" => \$parchive, |
| 518 |
"bitrate|b=s" => \$pbitrate, |
| 519 |
"book|A=i" => \$pbook, |
| 520 |
"maxrate|B=i" => \$pmaxrate, |
| 521 |
"chars|W:s" => \$chars, |
| 522 |
"cddbserver|C=s" => \$PCDDB_HOST, |
| 523 |
"cdcue=i" => \$pcdcue, |
| 524 |
"cue=i" => \$pcue, |
| 525 |
"cdid=s" => \$pcdid, |
| 526 |
"cdtext=i" => \$pcdtext, |
| 527 |
"cdtoc=i" => \$pcdtoc, |
| 528 |
"config!" => \$pconfig, |
| 529 |
"confdir=s" => \$pconfdir, |
| 530 |
"confname=s" => \$pconfname, |
| 531 |
"coder|c=s" => \@pcoder, |
| 532 |
"coverart=s" => \$pcoverart, |
| 533 |
"coverorg=i" => \$pcoverorg, |
| 534 |
"coverpath=s" => \$pcoverpath, |
| 535 |
"coversize|F=s" => \$pcoversize, |
| 536 |
"copycover=s" => \$pcopycover, |
| 537 |
"comment=s" => \$pcommentag, |
| 538 |
"device|d=s" => \$pcddev, |
| 539 |
"dirtemplate|D=s" => \@pdirtemplate, |
| 540 |
"discno=i" => \$pdiscno, |
| 541 |
"eject|e!" => \$peject, |
| 542 |
"ejectcmd=s" => \$pejectcmd, |
| 543 |
"ejectopt=s" => \$pejectopt, |
| 544 |
"encode!" => \$pencode, |
| 545 |
"execmd|X=s" => \$pexecmd, |
| 546 |
"extend=f" => \$pextend, |
| 547 |
"faacopt=s" => \$pfaacopt, |
| 548 |
"flacopt=s" => \$pflacopt, |
| 549 |
"flactags=s" => \@pflactags, |
| 550 |
"flacdecopt=s" => \$pflacdecopt, |
| 551 |
"lameopt=s" => \$plameopt, |
| 552 |
"oggencopt=s" => \$poggencopt, |
| 553 |
"oggtags=s" => \@poggtags, |
| 554 |
"mp4alsopt=s" => \$pmp4alsopt, |
| 555 |
"musenc=s" => \$pmusenc, |
| 556 |
"museopt=s" => \$pmuseopt, |
| 557 |
"wavpacopt=s" => \$pwavpacopt, |
| 558 |
"ffmpegopt=s" => \$pffmpegopt, |
| 559 |
"ffmpegsuffix=s" => \$pffmpegsuffix, |
| 560 |
"mp3gain=s" => \$pmp3gain, |
| 561 |
"vorbgain=s" => \$pvorbgain, |
| 562 |
"flacgain=s" => \$pflacgain, |
| 563 |
"aacgain=s" => \$paacgain, |
| 564 |
"mpcgain=s" => \$pmpcgain, |
| 565 |
"wvgain=s" => \$pwvgain, |
| 566 |
"genre|g=s" => \$pgenre, |
| 567 |
"ghost|G!" => \$pghost, |
| 568 |
"halt" => \$phalt, |
| 569 |
"help|h" => \$help, |
| 570 |
"inf=i" => \$pinf, |
| 571 |
"infolog=s" => \$pinfolog, |
| 572 |
"inputdir=s" => \$pinputdir, |
| 573 |
"interaction|i!" => \$pinteraction, |
| 574 |
"isrc=i" => \$pisrc, |
| 575 |
"lcd!" => \$plcd, |
| 576 |
"lcdhost=s" => \$plcdhost, |
| 577 |
"lcdport=s" => \$plcdport, |
| 578 |
"lowercase|l=i" => \$plowercase, |
| 579 |
"uppercasefirst!" => \$puppercasefirst, |
| 580 |
"local!" => \$plocal, |
| 581 |
"loop=i" => \$ploop, |
| 582 |
"mb!" => \$pmb, |
| 583 |
"mbrels=i" => \$pmbrels, |
| 584 |
"md5sum!" => \$pmd5sum, |
| 585 |
"merge=s" => \$pmerge, |
| 586 |
"mirror|m=s" => \$pmirror, |
| 587 |
"mail|M=s" => \$pmailad, |
| 588 |
"mailopt=s" => \$pmailopt, |
| 589 |
"mbname=s" => \$pmbname, |
| 590 |
"mbpass=s" => \$pmbpass, |
| 591 |
"mp3tags=s" => \@pmp3tags, |
| 592 |
"multi" => \$pmulti, |
| 593 |
"nice|n=s" => \$pnice, |
| 594 |
"nicerip=s" => \$pnicerip, |
| 595 |
"normalize|N!" => \$pnormalize, |
| 596 |
"normcmd=s" => \$pnormcmd, |
| 597 |
"normopt|z=s" => \$pnormopt, |
| 598 |
"subdir=s" => \$psubdir, |
| 599 |
"offset=i" => \$poffset, |
| 600 |
"outputdir|o=s" => \$poutputdir, |
| 601 |
"overwrite|O=s" => \$poverwrite, |
| 602 |
"dpermission=s" => \$pdpermission, |
| 603 |
"fpermission=s" => \$pfpermission, |
| 604 |
"playlist|p:s" => \$pplaylist, |
| 605 |
"precmd=s" => \$pprecmd, |
| 606 |
"prepend=f" => \$pprepend, |
| 607 |
"preset|S=s" => \$ppreset, |
| 608 |
"proxy|P=s" => \$pproxy, |
| 609 |
"protocol|L=i" => \$pproto, |
| 610 |
"quality|q=s" => \@pquality, |
| 611 |
"quitnodb=i" => \$pquitnodb, |
| 612 |
"resume|R" => \$presume, |
| 613 |
"rip!" => \$prip, |
| 614 |
"ripper|r=s" => \$pripper, |
| 615 |
"ripopt=s" => \$pripopt, |
| 616 |
"savenew" => \$psavenew, |
| 617 |
"save" => \$psavepara, |
| 618 |
"scp" => \$pscp, |
| 619 |
"scsidevice=s" => \$pscsi_cddev, |
| 620 |
"sshlist=s" => \@psshlist, |
| 621 |
"span|I=s" => \$pspan, |
| 622 |
"submission|s!" => \$psubmission, |
| 623 |
"threads=s" => \@pthreads, |
| 624 |
"tracktemplate|T=s" => \$ptracktemplate, |
| 625 |
"trackoffset=i" => \$ptrackoffset, |
| 626 |
"addtrackoffset!" => \$paddtrackoffset, |
| 627 |
"transfer|t=s" => \$ptransfer, |
| 628 |
"underscore|u!" => \$punderscore, |
| 629 |
"utftag|U!" => \$putftag, |
| 630 |
"vatag=i" => \$pvatag, |
| 631 |
"vastring=s" => \$pvastring, |
| 632 |
"vbrmode|v=s" => \$pvbrmode, |
| 633 |
"verbose|x=i" => \$pverbose, |
| 634 |
"version|V" => \$printver, |
| 635 |
"verify|Y=i" => \$pverify, |
| 636 |
"year|y=i" => \$pyear, |
| 637 |
"wav|w!" => \$pwav, |
| 638 |
"disable-paranoia|Z:i" => \$pparano, |
| 639 |
) |
| 640 |
or exit print_usage(); |
| 641 |
# |
| 642 |
# New options step 5: Add the command line option here (above). |
| 643 |
# |
| 644 |
# |
| 645 |
######################################################################## |
| 646 |
# |
| 647 |
# Evaluate the command line parameters if passed. We need to do it this |
| 648 |
# way, because passed options have to be saved (in case user wants to |
| 649 |
# save them in the config file) before config file is read to prevent |
| 650 |
# overriding passed options with options from config file. The passed |
| 651 |
# options shall be stronger than the config file options! |
| 652 |
# Problems arise with options that can be zero. Because a usual if-test |
| 653 |
# can not distinguish between zero or undef, use the defined-test! |
| 654 |
# |
| 655 |
# New options step 6: force use of command line options if passed. |
| 656 |
# |
| 657 |
# |
| 658 |
# First for the normal options, e. g. options which are never zero. |
| 659 |
# |
| 660 |
# The check of array @coder will be done in the subroutine! |
| 661 |
$faacopt = $pfaacopt if($pfaacopt); |
| 662 |
$flacopt = $pflacopt if($pflacopt); |
| 663 |
$flacdecopt = $pflacdecopt if($pflacdecopt); |
| 664 |
$lameopt = $plameopt if($plameopt); |
| 665 |
$mailopt = $pmailopt if($pmailopt); |
| 666 |
$oggencopt = $poggencopt if($poggencopt); |
| 667 |
$mp4alsopt = $pmp4alsopt if($pmp4alsopt); |
| 668 |
$musenc = $pmusenc if($pmusenc); |
| 669 |
$museopt = $pmuseopt if($pmuseopt); |
| 670 |
$wavpacopt = $pwavpacopt if($pwavpacopt); |
| 671 |
$ffmpegopt = $pffmpegopt if($pffmpegopt); |
| 672 |
$ffmpegsuffix = $pffmpegsuffix if($pffmpegsuffix); |
| 673 |
$oggencopt = " " unless($oggencopt); # Oops, only to prevent warnings... |
| 674 |
$mp3gain = $pmp3gain if($pmp3gain); |
| 675 |
$vorbgain = $pvorbgain if($pvorbgain); |
| 676 |
$flacgain = $pflacgain if($pflacgain); |
| 677 |
$aacgain = $paacgain if($paacgain); |
| 678 |
$mpcgain = $pmpcgain if($pmpcgain); |
| 679 |
$wvgain = $pwvgain if($pwvgain); |
| 680 |
$CDDB_HOST = $PCDDB_HOST if($PCDDB_HOST); |
| 681 |
$cddev = $pcddev if($pcddev); |
| 682 |
$overwrite = $poverwrite if($poverwrite); |
| 683 |
$verify = $pverify if($pverify); |
| 684 |
# |
| 685 |
# Get the default "no-argument" values. |
| 686 |
# Note, that subroutine clean_all already purges ;><" and \015. |
| 687 |
$chars = "NTFS" if($chars eq ""); |
| 688 |
$chars = "" if($chars eq "off"); |
| 689 |
$commentag = $pcommentag if($pcommentag); |
| 690 |
$confname = $pconfname if($pconfname); |
| 691 |
$confdir = $pconfdir if($pconfdir); |
| 692 |
$copycover = $pcopycover if($pcopycover); |
| 693 |
$coverpath = $pcoverpath if($pcoverpath); |
| 694 |
$coversize = $pcoversize if($pcoversize); |
| 695 |
@dirtemplate = @pdirtemplate if($pdirtemplate[0]); |
| 696 |
$tracktemplate = $ptracktemplate if($ptracktemplate); |
| 697 |
$execmd = $pexecmd if($pexecmd); |
| 698 |
$precmd = $pprecmd if($pprecmd); |
| 699 |
@flactags = @pflactags if($pflactags[0]); |
| 700 |
$halt = $phalt if($phalt); |
| 701 |
$inputdir = $pinputdir if($pinputdir); |
| 702 |
$infolog = $pinfolog if($pinfolog); |
| 703 |
$lcdhost = $plcdhost if($plcdhost); |
| 704 |
$lcdport = $plcdport if($plcdport); |
| 705 |
$mailad = $pmailad if($pmailad); |
| 706 |
$mbname = $pmbname if($pmbname); |
| 707 |
$mbpass = $pmbpass if($pmbpass); |
| 708 |
@mp3tags = @pmp3tags if($pmp3tags[0]); |
| 709 |
$mirror = $pmirror if($pmirror); |
| 710 |
$normcmd = $pnormcmd if($pnormcmd); |
| 711 |
$normopt = $pnormopt if($pnormopt); |
| 712 |
@oggtags = @poggtags if($poggtags[0]); |
| 713 |
$outputdir = $poutputdir if($poutputdir); |
| 714 |
my $preset = $ppreset if($ppreset); |
| 715 |
$ripopt = $pripopt if($pripopt); |
| 716 |
$dpermission = $pdpermission if($pdpermission); |
| 717 |
$fpermission = $pfpermission if($pfpermission); |
| 718 |
$proto = $pproto if($pproto); |
| 719 |
$proxy = $pproxy if($pproxy); |
| 720 |
# Check for variable $psshlist will be done in the subroutine! |
| 721 |
# Check for variable $pthreads will be done in the subroutine! |
| 722 |
$transfer = $ptransfer if($ptransfer); |
| 723 |
$vbrmode = $pvbrmode if($pvbrmode); |
| 724 |
$year = $pyear if($pyear); |
| 725 |
# |
| 726 |
# Options which might be zero. |
| 727 |
$bitrate = $pbitrate if($pbitrate); |
| 728 |
$book = $pbook if($pbook); |
| 729 |
$cdcue = $pcdcue if defined $pcdcue; |
| 730 |
$cue = $pcue if defined $pcue; |
| 731 |
$cdid = $pcdid if defined $pcdid; |
| 732 |
$cdtext = $pcdtext if defined $pcdtext; |
| 733 |
$cdtoc = $pcdtoc if defined $pcdtoc; |
| 734 |
$coverart = $pcoverart if defined $pcoverart; |
| 735 |
$coverorg = $pcoverorg if defined $pcoverorg; |
| 736 |
$extend = $pextend if defined $pextend; |
| 737 |
$genre = $pgenre if defined $pgenre; |
| 738 |
$inf = $pinf if defined $pinf; |
| 739 |
$isrc = $pisrc if defined $pisrc; |
| 740 |
$loop = $ploop if defined $ploop; |
| 741 |
$lowercase = $plowercase if defined $plowercase; |
| 742 |
$md5sum = $pmd5sum if defined $pmd5sum; |
| 743 |
$maxrate = $pmaxrate if defined $pmaxrate; |
| 744 |
$nice = $pnice if defined $pnice; |
| 745 |
$nicerip = $pnicerip if defined $pnicerip; |
| 746 |
$offset = $poffset if defined $poffset; |
| 747 |
$parano = $pparano if defined $pparano; |
| 748 |
$playlist = $pplaylist if defined $pplaylist; |
| 749 |
$playlist = 1 if($playlist eq ""); |
| 750 |
$prepend = $pprepend if defined $pprepend; |
| 751 |
$quitnodb = $pquitnodb if defined $pquitnodb; |
| 752 |
$resume = $presume if defined $presume; |
| 753 |
$ripper = $pripper if defined $pripper; |
| 754 |
$savepara = $psavepara if defined $psavepara; |
| 755 |
$savenew = $psavenew if defined $psavenew; |
| 756 |
$scp = $pscp if defined $pscp; |
| 757 |
$discno = $pdiscno if defined $pdiscno; |
| 758 |
if(defined $pscsi_cddev) { |
| 759 |
$scsi_cddev = $pscsi_cddev; |
| 760 |
} |
| 761 |
else { |
| 762 |
$scsi_cddev = $pcddev if($pcddev); |
| 763 |
} |
| 764 |
$span = $pspan if defined $pspan; |
| 765 |
$trackoffset = $ptrackoffset if defined $ptrackoffset; |
| 766 |
$verbose = $pverbose if defined $pverbose; |
| 767 |
$vatag = $pvatag if defined $pvatag; |
| 768 |
# |
| 769 |
# And for the negatable options. |
| 770 |
$addtrackoffset = $paddtrackoffset if defined $paddtrackoffset; |
| 771 |
$accuracy = $paccuracy if defined $paccuracy; |
| 772 |
$archive = $parchive if defined $parchive; |
| 773 |
$config = $pconfig if defined $pconfig; |
| 774 |
$encode = $pencode if defined $pencode; |
| 775 |
$eject = $peject if defined $peject; |
| 776 |
$ejectcmd = $pejectcmd if defined $pejectcmd; |
| 777 |
$ejectopt = $pejectopt if defined $pejectopt; |
| 778 |
$ghost = $pghost if defined $pghost; |
| 779 |
$interaction = $pinteraction if defined $pinteraction; |
| 780 |
$lcd = $plcd if defined $plcd; |
| 781 |
$local = $plocal if defined $plocal; |
| 782 |
$mb = $pmb if defined $pmb; |
| 783 |
$uppercasefirst = $puppercasefirst if defined $puppercasefirst; |
| 784 |
$multi = $pmulti if defined $pmulti; |
| 785 |
$normalize = $pnormalize if defined $pnormalize; |
| 786 |
$rip = $prip if defined $prip; |
| 787 |
$submission = $psubmission if defined $psubmission; |
| 788 |
$underscore = $punderscore if defined $punderscore; |
| 789 |
$utftag = $putftag if defined $putftag; |
| 790 |
$wav = $pwav if defined $pwav; |
| 791 |
# |
| 792 |
######################################################################## |
| 793 |
# |
| 794 |
# Preliminary start: print version, read (and write) config file. |
| 795 |
# |
| 796 |
# To have the version printed first of all other (warning-) messages, |
| 797 |
# find out if verbosity is set off or not, either by command line or |
| 798 |
# by config file. |
| 799 |
# |
| 800 |
my $ripdir = ""; |
| 801 |
if($confdir ne "") { |
| 802 |
$ripdir = $confdir . "/" . $confname; |
| 803 |
} |
| 804 |
elsif($confname ne "config") { |
| 805 |
$ripdir = $homedir . "/.ripit/" . $confname; |
| 806 |
} |
| 807 |
else { |
| 808 |
$ripdir = $homedir . "/.ripit/config" |
| 809 |
} |
| 810 |
# Fallback: |
| 811 |
$ripdir = $homedir . "/.ripit/config" unless(-r "$ripdir"); |
| 812 |
$ripdir = "/etc/ripit/config" unless(-r "$ripdir"); |
| 813 |
if(-r "$ripdir" && $config == 1) { |
| 814 |
open(CONF, "$ripdir") || print "Can not read config file!\n"; |
| 815 |
my @conflines = <CONF>; |
| 816 |
close(CONF); |
| 817 |
chomp($verbose = join('', grep(s/^verbose=//, @conflines))) |
| 818 |
unless(defined $pverbose); |
| 819 |
if(defined $pinfolog && $pinfolog ne "") { |
| 820 |
# Do nothing, use argument passed. |
| 821 |
} |
| 822 |
else { |
| 823 |
chomp($infolog = join('', grep(s/^infolog=//, @conflines))); |
| 824 |
} |
| 825 |
} |
| 826 |
# |
| 827 |
print "\n\n\nRipIT version $version.\n" if($verbose >= 1); |
| 828 |
# Preliminary creation of the infolog path. |
| 829 |
# No log_system call here because this would try to write to the infolog |
| 830 |
# file not yet created. |
| 831 |
if($infolog) { |
| 832 |
my($log_path, $filename) = $infolog =~ m/(.*\/)(.*)$/; |
| 833 |
system("mkdir -m 0755 -p \"$log_path\"") and |
| 834 |
print "Can not create directory \"$log_path\": $!\n"; |
| 835 |
} |
| 836 |
log_info("RipIT version $version infolog-file.\n"); |
| 837 |
if($loop == 0) { |
| 838 |
my $ripstart = sprintf "%02d:%02d:%02d", |
| 839 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 840 |
my $date = sprintf("%04d-%02d-%02d", |
| 841 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 842 |
chomp($date); |
| 843 |
log_info("$date $ripstart\n"); |
| 844 |
} |
| 845 |
# |
| 846 |
# |
| 847 |
# Do some checks before writing a new config file (if wanted): |
| 848 |
# |
| 849 |
# First check if arguments of option merge are OK. |
| 850 |
my @dummy = skip_tracks(1) if($pmerge); |
| 851 |
# |
| 852 |
# Then the options that will be written to the config file. |
| 853 |
if($help ne 1 && $printver ne 1) { |
| 854 |
check_coder(); # Check encoder array. |
| 855 |
check_quality(); # Check if quality is valid. |
| 856 |
check_proto(); # Check if protocol level is valid. |
| 857 |
check_sshlist(); # Check list of remote machines. |
| 858 |
check_preset() if($preset); # Check preset settings. |
| 859 |
# |
| 860 |
# To be able to save a new config file we have to write it before |
| 861 |
# reading the parameters not yet passed from the config file. |
| 862 |
# |
| 863 |
$chars = "" if($chars eq "XX" && ($savenew == 1 || $savepara == 1)); |
| 864 |
# |
| 865 |
if($savenew == 1) { |
| 866 |
$verbose = 3; # Set back to default value. |
| 867 |
$infolog = ""; # Set back to default value. |
| 868 |
save_config(); |
| 869 |
print "Saved a new config file!\n\n" if($verbose >= 3); |
| 870 |
} |
| 871 |
# |
| 872 |
# Read the config file. |
| 873 |
# |
| 874 |
read_config() if($config == 1); |
| 875 |
check_enc("lame", "mp3"); |
| 876 |
# check_enc("faac", "m4a"); |
| 877 |
# |
| 878 |
# Check if the necessary modules are installed properly. |
| 879 |
# |
| 880 |
init_mod; |
| 881 |
# |
| 882 |
# |
| 883 |
# Security check for new options: give them default value if empty. |
| 884 |
# This can happen, if the config file is not yet up-to date. |
| 885 |
# This will go away again in version 4.1.0. This is also done to prevent |
| 886 |
# warnings. |
| 887 |
# |
| 888 |
# New options step 7: not mandatory, might be useful. |
| 889 |
# |
| 890 |
$discno = 0 unless($discno); |
| 891 |
$accuracy = 0 unless($accuracy); |
| 892 |
$cue = 0 unless($cue); |
| 893 |
$cdtext = 0 unless($cdtext); |
| 894 |
$copycover = "" unless($copycover); |
| 895 |
$coverorg = 0 unless($coverorg); |
| 896 |
$coversize = "" unless($coversize); |
| 897 |
$mbrels = 0 unless($mbrels); |
| 898 |
$dpermission = "0755" unless($dpermission); |
| 899 |
$uppercasefirst = 0 unless($uppercasefirst); |
| 900 |
$isrc = 0 unless($isrc); |
| 901 |
$resume = 0 unless($resume); |
| 902 |
$musenc = "mpcenc" unless($musenc); |
| 903 |
$quamp4als = 0 unless($quamp4als); |
| 904 |
$quamuse = 5 unless($quamuse); |
| 905 |
$trackoffset = 0 unless($trackoffset); |
| 906 |
$addtrackoffset = 0 unless($addtrackoffset); |
| 907 |
$vatag = 0 unless($vatag); |
| 908 |
$pcdid = 0 unless($pcdid); |
| 909 |
$verify = 1 unless($verify); |
| 910 |
$mailopt = "-t" unless($mailopt); |
| 911 |
# |
| 912 |
# |
| 913 |
# Save the config file. |
| 914 |
# |
| 915 |
save_config() if($savepara == 1); |
| 916 |
print "Updated the config file!\n\n" |
| 917 |
if($verbose >= 3 && $savepara == 1); |
| 918 |
# |
| 919 |
# It might be a good to x-check settings from config file because they |
| 920 |
# can be edited manually. |
| 921 |
# |
| 922 |
check_coder(); # Check it again for lame cbr vs vbr. |
| 923 |
check_quality(); # Check it again if quality is valid. |
| 924 |
check_sshlist(); # Check it again to create the hash. |
| 925 |
check_options(); # Sort the options according to the encoder. |
| 926 |
check_distro(); # Check for the distribution used. |
| 927 |
|
| 928 |
} |
| 929 |
# |
| 930 |
######################################################################## |
| 931 |
# |
| 932 |
# MAIN ROUTINE |
| 933 |
# |
| 934 |
######################################################################## |
| 935 |
# |
| 936 |
if($printver) { |
| 937 |
print "\n"; |
| 938 |
exit 2; |
| 939 |
} |
| 940 |
|
| 941 |
if($verbose >= 2) { |
| 942 |
print "Process summary:\n", "-" x 16, "\n" unless($help == 1); |
| 943 |
} |
| 944 |
|
| 945 |
if($help == 1) { |
| 946 |
print "\nThis is a shorten man page. Refer to the full manpage ", |
| 947 |
"for more details.\n"; |
| 948 |
print_help(); |
| 949 |
exit 3; |
| 950 |
} |
| 951 |
|
| 952 |
if(!$pcddev && $cddev eq "") { |
| 953 |
# Condition change in 4.0: Why is $cddev from config not considered? |
| 954 |
check_cddev; |
| 955 |
} |
| 956 |
else { |
| 957 |
my $closeopt = $cddev if($ejectopt eq '{cddev}'); |
| 958 |
$closeopt = "-t " . $closeopt if($ejectcmd =~ /^eject$/); |
| 959 |
$closeopt = $closeopt . " close" if($ejectcmd =~ /cdcontrol/); |
| 960 |
log_system("$ejectcmd $closeopt > /dev/null 2>&1"); |
| 961 |
} |
| 962 |
|
| 963 |
if($scsi_cddev eq "") { |
| 964 |
$scsi_cddev = $cddev; |
| 965 |
} |
| 966 |
|
| 967 |
if($chars) { |
| 968 |
check_chars; |
| 969 |
} |
| 970 |
|
| 971 |
if($lcd == 1) { |
| 972 |
init_lcd(); |
| 973 |
} |
| 974 |
|
| 975 |
if($outputdir eq "") { |
| 976 |
$outputdir = $homedir; |
| 977 |
chomp $outputdir; |
| 978 |
} |
| 979 |
|
| 980 |
if($outputdir =~ /^\.\//) { |
| 981 |
$outputdir =~ s/^\./$workdir/; |
| 982 |
} |
| 983 |
elsif($outputdir =~ /^\.\s*$/) { |
| 984 |
$outputdir =~ s/^\./$workdir/; |
| 985 |
} |
| 986 |
|
| 987 |
if($outputdir =~ /^~\//) { |
| 988 |
$outputdir =~ s/^~/$homedir/; |
| 989 |
} |
| 990 |
|
| 991 |
if($outputdir =~ /^\$HOME/) { |
| 992 |
$outputdir =~ s/^\$HOME/$homedir/; |
| 993 |
} |
| 994 |
|
| 995 |
if($copycover =~ /^~\//) { |
| 996 |
$copycover =~ s/^~/$homedir/; |
| 997 |
} |
| 998 |
|
| 999 |
if($copycover =~ /^\$HOME/) { |
| 1000 |
$copycover =~ s/^\$HOME/$homedir/; |
| 1001 |
} |
| 1002 |
|
| 1003 |
if($coverpath =~ /^~\//) { |
| 1004 |
$coverpath =~ s/^~/$homedir/; |
| 1005 |
} |
| 1006 |
|
| 1007 |
if($coverpath =~ /^\$HOME/) { |
| 1008 |
$coverpath =~ s/^\$HOME/$homedir/; |
| 1009 |
} |
| 1010 |
|
| 1011 |
# New options step 8: Add a message about selected options if needed. |
| 1012 |
|
| 1013 |
if(length($year) > 0 && length($year) != 4 ) { |
| 1014 |
print STDERR "Warning: year should be in 4 digits - $year.\n" |
| 1015 |
if($verbose >= 1); |
| 1016 |
} |
| 1017 |
|
| 1018 |
if($pdpermission && $verbose >= 2) { |
| 1019 |
# Print this message only, if a dpermission has been passed on CL. |
| 1020 |
$dpermission = sprintf("%04d", $dpermission); |
| 1021 |
print "Directory permission will be set to $dpermission.\n"; |
| 1022 |
} |
| 1023 |
|
| 1024 |
if($fpermission && $verbose >= 2) { |
| 1025 |
$fpermission = sprintf("%04d", $fpermission); |
| 1026 |
print "File permission will be set to $fpermission.\n"; |
| 1027 |
} |
| 1028 |
|
| 1029 |
if($resume == 1 && $verbose >= 2) { |
| 1030 |
print "Resuming previous session.\n"; |
| 1031 |
} |
| 1032 |
|
| 1033 |
if($span && $verbose >= 2) { |
| 1034 |
print "Partial wav files will be ripped.\n" unless($span =~ /\d-$/); |
| 1035 |
print "Accuracy check not possible with option span, switched off.\n" |
| 1036 |
if($accuracy == 1 && $span !~ /\d-$/); |
| 1037 |
$accuracy = 0; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if($pmerge && $verbose >= 2) { |
| 1041 |
print "Some tracks will be merged according $pmerge.\n"; |
| 1042 |
print "Accuracy check not possible with option merge, switched off.\n" |
| 1043 |
if($accuracy == 1); |
| 1044 |
$accuracy = 0; |
| 1045 |
} |
| 1046 |
|
| 1047 |
if($wav == 1 && $verbose >= 2) { |
| 1048 |
print "Wav files will not be deleted.\n"; |
| 1049 |
} |
| 1050 |
|
| 1051 |
if($rip == 0) { |
| 1052 |
if($inputdir ne "") { |
| 1053 |
if(! -d "$inputdir") { |
| 1054 |
die "\nQuitting, inputdir \"$inputdir\" can not be found.\n\n"; |
| 1055 |
} |
| 1056 |
print "Re-encoding of existing files.\n"; |
| 1057 |
if($cdid ne "") { |
| 1058 |
print "Track tags will be updated if possible using the ", |
| 1059 |
"given ID $cdid.\n" if($verbose > 1); |
| 1060 |
unless($pcdid =~ /[0-9a-f]/ && length($pcdid) == 8) { |
| 1061 |
print "\nWarning: the cdid given seems not to be a valid ", |
| 1062 |
"discid which has to be 28 chars long and ends with ", |
| 1063 |
"a hyphen.\n" unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 1064 |
} |
| 1065 |
# Don't touch existing playlist files. No, update playlist |
| 1066 |
# because tags might be updated. |
| 1067 |
# $playlist = -1; |
| 1068 |
$normalize = 0; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
else { |
| 1072 |
print "\nOption --norip needs an --inputdir to read from.\n"; |
| 1073 |
exit print_usage(); |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
if($verify > 1 && $verbose >= 2) { |
| 1078 |
print "Checking each ripped file until 2 consecutive rips give the same md5sum.\n"; |
| 1079 |
} |
| 1080 |
|
| 1081 |
if($mb == 1 && $verbose >= 2) { |
| 1082 |
print "Checking MusicBrainz instead of freedb.org.\n"; |
| 1083 |
} |
| 1084 |
|
| 1085 |
if($cdtext == 1 && $verbose >= 2) { |
| 1086 |
print "Checking for CD text if no DB entry found.\n"; |
| 1087 |
} |
| 1088 |
|
| 1089 |
if($normalize == 1 && $verbose >= 2) { |
| 1090 |
print "Normalizeing the CD-tracks.\n"; |
| 1091 |
} |
| 1092 |
|
| 1093 |
if($addtrackoffset == 1 && $mb == 1 && $verbose >= 2) { |
| 1094 |
print "Checking for multi disc release and addition of offset in ", |
| 1095 |
"track numbers if detected.\n"; |
| 1096 |
} |
| 1097 |
|
| 1098 |
if($discno > 0 && $verbose >= 2) { |
| 1099 |
if($mb == 1) { |
| 1100 |
print "Checking for multi disc release and adding a disc number ", |
| 1101 |
"to the tags if detected.\n"; |
| 1102 |
} |
| 1103 |
else { |
| 1104 |
print "Adding disc number $discno to the tags.\n"; |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
if($book >= 1 && $verbose >= 2) { |
| 1109 |
print "All tracks will be merged into one file and a chapter file ", |
| 1110 |
"written.\n"; |
| 1111 |
$pmerge = "1-"; |
| 1112 |
$ghost = 0; |
| 1113 |
print "Accuracy check not possible with option merge, accuracy", |
| 1114 |
" will be switched off.\n" if($accuracy == 1); |
| 1115 |
$accuracy = 0; |
| 1116 |
} |
| 1117 |
|
| 1118 |
if($cdcue > 0 && $verbose >= 2) { |
| 1119 |
print "All tracks will be merged into one file and a cue-file ", |
| 1120 |
"written.\n"; |
| 1121 |
$pmerge = "1-" if($cdcue == 2); |
| 1122 |
$ghost = 0; |
| 1123 |
$ghost = 1 if($cdcue == 1); |
| 1124 |
print "Accuracy check not possible with option cdcue == 2, accuracy", |
| 1125 |
" will be switched off.\n" if($accuracy == 1 and $cdcue > 1); |
| 1126 |
$accuracy = 0 if($accuracy == 1 and $cdcue > 1); |
| 1127 |
} |
| 1128 |
|
| 1129 |
if($cue > 0 && $verbose >= 2) { |
| 1130 |
print "A cue-file will be written for all tracks.\n"; |
| 1131 |
} |
| 1132 |
|
| 1133 |
if($accuracy > 0 && $verbose >= 2) { |
| 1134 |
if($ripper == 1 || $ripper == 4) { |
| 1135 |
print "Accuracy check will be done after ripping.\n"; |
| 1136 |
} |
| 1137 |
else { |
| 1138 |
print "Accuracy check not possible with other ripper than ", |
| 1139 |
"cdparanoia, accuracy will be switched off.\n"; |
| 1140 |
$accuracy = 0 if($accuracy == 1); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
|
| 1144 |
if($cdtoc > 0 && $verbose >= 2) { |
| 1145 |
print "A toc file will be written.\n"; |
| 1146 |
} |
| 1147 |
|
| 1148 |
if($inf > 0 && $verbose >= 2) { |
| 1149 |
print "Inf files will be written for each track.\n"; |
| 1150 |
} |
| 1151 |
|
| 1152 |
if($ghost == 1) { |
| 1153 |
print "Tracks will be analyzed for ghost songs. " if($verbose >= 2); |
| 1154 |
print "Forced by option --cdcue." if($cdcue == 1 && $verbose >= 2); |
| 1155 |
print "\n" if($verbose >= 2); |
| 1156 |
} |
| 1157 |
|
| 1158 |
if($utftag == 0 && $verbose >= 2 && "@coder" =~ /0/) { |
| 1159 |
print "Lame-tags will be encoded to ISO8859-1.\n"; |
| 1160 |
} |
| 1161 |
|
| 1162 |
if($flactags[0] && $verbose >= 2 ) { |
| 1163 |
print "Additional track tags will be added to flac files.\n"; |
| 1164 |
} |
| 1165 |
|
| 1166 |
if($mp3tags[0] && $verbose >= 2 ) { |
| 1167 |
print "Special track tags will be added to mp3 files.\n"; |
| 1168 |
} |
| 1169 |
|
| 1170 |
if($oggtags[0] && $verbose >= 2 ) { |
| 1171 |
print "Additional track tags will be added to mp3 files.\n"; |
| 1172 |
} |
| 1173 |
|
| 1174 |
if($vatag > 0 && $verbose >= 2 ) { |
| 1175 |
print "Track tags will be analyzed for VA style.\n"; |
| 1176 |
} |
| 1177 |
|
| 1178 |
if($playlist >= 1 && $verbose >= 2) { |
| 1179 |
print "Playlist (m3u) file will be written.\n"; |
| 1180 |
} |
| 1181 |
|
| 1182 |
if($md5sum == 1 && $verbose >= 2) { |
| 1183 |
print "MD5SUMs of sound files will be calculated.\n"; |
| 1184 |
} |
| 1185 |
|
| 1186 |
if($copycover && $verbose >= 2) { |
| 1187 |
print "Copying a cover picture to encoder directories.\n"; |
| 1188 |
} |
| 1189 |
|
| 1190 |
if($coverorg =~ /1/ && $verbose >= 2) { |
| 1191 |
print "Retrieving coverart from coverartarchive.org.\n"; |
| 1192 |
} |
| 1193 |
|
| 1194 |
if($coversize =~ /^\d+$/ && $verbose >= 2) { |
| 1195 |
print "Resizing coverart to $coversize.\n"; |
| 1196 |
} |
| 1197 |
|
| 1198 |
if($coverart =~ /1/ && $verbose >= 2) { |
| 1199 |
print "Adding coverart to sound files (if provided).\n"; |
| 1200 |
} |
| 1201 |
|
| 1202 |
if(($mp3gain || $vorbgain || $flacgain || $aacgain || $mpcgain || $wvgain) |
| 1203 |
&& $encode == 1 && $verbose >= 2) { |
| 1204 |
print "Adding album gain tags to sound files.\n"; |
| 1205 |
} |
| 1206 |
|
| 1207 |
if($parano >= 3 && $verbose >= 2 ) { |
| 1208 |
print "Warning: paranoia argument unknown, will use paranoia.\n"; |
| 1209 |
$parano = 1; |
| 1210 |
} |
| 1211 |
|
| 1212 |
if($halt == 1 && $verbose >= 2) { |
| 1213 |
print "Halting machine when finished.\n"; |
| 1214 |
} |
| 1215 |
|
| 1216 |
if($eject == 1 || $loop >= 1) { |
| 1217 |
print "CD will be ejected when finished.\n" if($verbose >= 2); |
| 1218 |
$ejectcmd = "eject -v" if($ejectcmd =~ /eject/ && $verbose >= 4); |
| 1219 |
} |
| 1220 |
|
| 1221 |
if($loop >= 1) { |
| 1222 |
print "Restarting and ejection of each CD.\n" if($verbose >= 2); |
| 1223 |
print "\n" if($verbose >= 2); |
| 1224 |
while($loop >= 1) { |
| 1225 |
main_sub; |
| 1226 |
last if($loop == 0); |
| 1227 |
init_var; |
| 1228 |
# This is the light version without eating the disc. |
| 1229 |
print "Please insert a new CD!\n" if($verbose >= 1); |
| 1230 |
while( not cd_present() ) { |
| 1231 |
sleep(6); |
| 1232 |
} |
| 1233 |
# Do it again in case operator changed something in between. |
| 1234 |
if($config == 1) { |
| 1235 |
read_config(); |
| 1236 |
print "Rereading config file.\n" if($verbose > 3); |
| 1237 |
} |
| 1238 |
} |
| 1239 |
} |
| 1240 |
else { |
| 1241 |
print "\n" if($verbose >= 2); |
| 1242 |
main_sub; |
| 1243 |
} |
| 1244 |
exit; |
| 1245 |
# |
| 1246 |
######################################################################## |
| 1247 |
# |
| 1248 |
# Main subroutine. |
| 1249 |
# |
| 1250 |
######################################################################## |
| 1251 |
# |
| 1252 |
sub main_sub { |
| 1253 |
if($loop > 0) { |
| 1254 |
my $ripstart = sprintf "%02d:%02d:%02d", |
| 1255 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 1256 |
my $date = sprintf("%04d-%02d-%02d", |
| 1257 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 1258 |
chomp $date; |
| 1259 |
log_info("$date $ripstart\n"); |
| 1260 |
} |
| 1261 |
|
| 1262 |
if(@ARGV) { |
| 1263 |
$trackselection = $ARGV[0]; |
| 1264 |
} |
| 1265 |
|
| 1266 |
if($bitrate ne "off" && $lameflag == 1) { |
| 1267 |
check_bitrate; |
| 1268 |
} |
| 1269 |
|
| 1270 |
if($vbrmode ne "" && $lameflag == 1) { |
| 1271 |
check_vbrmode; |
| 1272 |
} |
| 1273 |
|
| 1274 |
if($preset) { |
| 1275 |
lame_preset; |
| 1276 |
} |
| 1277 |
|
| 1278 |
if($rip == 1 && $loop == 0) { # Condition added in 4.0 |
| 1279 |
unless( cd_present() ) { |
| 1280 |
print "\nPlease insert an audio CD!\n" if($verbose > 0); |
| 1281 |
while( not cd_present() ) { |
| 1282 |
check_cddev; |
| 1283 |
sleep(12); |
| 1284 |
} |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
if($rip == 0) { ### and $cdid eq "") { |
| 1289 |
# Main idea of re-encoding: |
| 1290 |
# Re-encoding means needing for tags, only possibly here within |
| 1291 |
# flac files, no way to extract track names from wav file names. |
| 1292 |
# In this way let's suppose the meta data look-up makes sense. And |
| 1293 |
# in case of flac it makes sense to check Musicbrainz, updating |
| 1294 |
# tags with freedb would not really improve the quality. |
| 1295 |
# So this means less of work: for a freedb look-up without disc in |
| 1296 |
# the drive we would not only need the discid, but the complete |
| 1297 |
# framelist (toc) for all tracks. This means, a freedb look-up |
| 1298 |
# without disc is only possible after reading a local copy in the |
| 1299 |
# archive: operator gives discid --> archive --> selection of |
| 1300 |
# disc --> readout of toc and save it in an array --> |
| 1301 |
# return to freedb look-up --> choose again release with probably |
| 1302 |
# no significant quality improvement. Or the toc is assembled from |
| 1303 |
# MB data to ensure genre retrieval. This could make sense if we |
| 1304 |
# have only wav and an discid from a log file. |
| 1305 |
# |
| 1306 |
# The idea of passing a discid is only meant as a workaround in |
| 1307 |
# case operator has no other meta data with this info. |
| 1308 |
# Giving a MB-discid will lead to an online look-up, an discid will |
| 1309 |
# enable a local archive look-up. |
| 1310 |
# The detection of an existing id won't be done in this case. |
| 1311 |
# |
| 1312 |
# So start here if no id is passed and an id should be detected. |
| 1313 |
# Come here only if operator did not pass any CD-ID. |
| 1314 |
# First: try to find a cue, m3u or toc file, finally analyze |
| 1315 |
# existing flac or wav files. |
| 1316 |
# Hm, should we let operator decide if tags shall be checked? |
| 1317 |
# |
| 1318 |
# What if operator has flac with tags? Then |
| 1319 |
# look-up will possibly update tags -- how does ripit show a |
| 1320 |
# diff? |
| 1321 |
get_cdid; |
| 1322 |
# If no CDID passed or detected and only wav or flac without |
| 1323 |
# tags are present, then after sub disp_info operator may enter |
| 1324 |
# tags. |
| 1325 |
# What should happen, if flacs with tags are present but no |
| 1326 |
# discid. Nothing, reuse the tags. |
| 1327 |
# If a discid is found (or exists), then update tags this way: |
| 1328 |
# If mbreid is given/found and option --mb is on: make a look-up. |
| 1329 |
# If cdid is given/found and option -a is on: check archive. |
| 1330 |
} |
| 1331 |
|
| 1332 |
if($rip == 1 || ($rip == 0 && $cdid ne "")) { |
| 1333 |
# Sorry, replication of code snippet from sub get_cdid. |
| 1334 |
# Final clean-up of IDs. |
| 1335 |
if($rip == 0) { |
| 1336 |
print "Cleaning cddbid and discid found locally.\n" if($verbose > 4); |
| 1337 |
if($cdid =~ /[0-9a-f]/ && length($cdid) == 8) { |
| 1338 |
$cddbid = $cdid; |
| 1339 |
$cd{id} = $cddbid; |
| 1340 |
} |
| 1341 |
else{ |
| 1342 |
$discid = $cdid; |
| 1343 |
$discid = "" unless($discid =~ /\-$/ && length($discid) == 28); |
| 1344 |
$cdid = ""; |
| 1345 |
$cd{discid} = $discid if($discid ne ""); |
| 1346 |
} |
| 1347 |
} |
| 1348 |
if($archive == 1 && $multi == 0) { |
| 1349 |
print "Checking local archive.\n" if($verbose > 4); |
| 1350 |
get_arch(); |
| 1351 |
} |
| 1352 |
else { |
| 1353 |
# Place interaction here if DB update should happen or not? |
| 1354 |
# TODO |
| 1355 |
print "Checking external DBs...\n" if($verbose > 4); |
| 1356 |
# Don't go in when re-encoding. |
| 1357 |
get_cdinfo() if($mb == 0 && $rip == 1); |
| 1358 |
get_mb() if($mb == 1); |
| 1359 |
} |
| 1360 |
} |
| 1361 |
disp_info; |
| 1362 |
create_seltrack($trackselection); |
| 1363 |
ask_subm(); |
| 1364 |
my $answer = create_dirs(); |
| 1365 |
@framelist_orig = @framelist if($rip == 0); |
| 1366 |
|
| 1367 |
if($answer eq "go") { |
| 1368 |
if($precmd) { |
| 1369 |
$precmd =~ s/\$/\\\$/g; |
| 1370 |
log_system("$precmd"); |
| 1371 |
} |
| 1372 |
get_cover if($coverorg > 0 and $mb == 1); |
| 1373 |
# This is where we would expect the resize_cover call, but if no |
| 1374 |
# coverart is found, we want the command to take effect even if |
| 1375 |
# operator adds a cover manually. |
| 1376 |
if($loop > 0 && $interaction == 1) { |
| 1377 |
my $startover = -1; |
| 1378 |
while($startover < 0 || $startover > 1) { |
| 1379 |
print "\nRestart to choose another DB source? [y/n] (n) "; |
| 1380 |
$startover = <STDIN>; |
| 1381 |
chomp $startover; |
| 1382 |
$startover = 0 if($startover eq ""); |
| 1383 |
$startover = 1 if($startover eq "y"); |
| 1384 |
$startover = -1 unless($startover =~ /^0|1$/); |
| 1385 |
print "\n"; |
| 1386 |
} |
| 1387 |
return if($startover == 1); |
| 1388 |
} |
| 1389 |
|
| 1390 |
if(-f "$copycover" && -s "$copycover") { |
| 1391 |
# First check existence of base file: |
| 1392 |
my $msg = "\nChecking for files to be copied from copycover " . |
| 1393 |
"path $copycover."; |
| 1394 |
check_copy("$copycover") if($interaction == 1); |
| 1395 |
resize_cover("$copycover") |
| 1396 |
if(defined $coversize && $coversize =~ /^\d+$/); |
| 1397 |
copy_cover; |
| 1398 |
# Once album art is copied, make sure that it is available |
| 1399 |
# under the given $coverpath: |
| 1400 |
# But this does not really make sense if several destination |
| 1401 |
# directories exist. Test at least one to make sure copy_cover |
| 1402 |
# did the job. |
| 1403 |
$msg = "\nCheck for album cover with path coverpath " . |
| 1404 |
"$coverpath."; |
| 1405 |
check_cover("$coverpath", $msg) if($interaction == 1); |
| 1406 |
} |
| 1407 |
elsif($copycover ne "") { |
| 1408 |
print "\nChecking for album cover to be copied from ", |
| 1409 |
"copycover $copycover." if($verbose > 2); |
| 1410 |
if($interaction == 1) { |
| 1411 |
my $msg = "\nChecking for files to be copied from " . |
| 1412 |
"copycover path $copycover."; |
| 1413 |
check_copy("$copycover", $msg); |
| 1414 |
resize_cover("$copycover") |
| 1415 |
if(defined $coversize && $coversize =~ /^\d+$/); |
| 1416 |
copy_cover if(-f "$copycover" && -s "$copycover"); |
| 1417 |
$msg = "\nChecking again for album cover with path " . |
| 1418 |
"coverpath $coverpath."; |
| 1419 |
check_copy("$coverpath", $msg); |
| 1420 |
} |
| 1421 |
} |
| 1422 |
elsif(!-f "$coverpath" && $coverpath ne "") { |
| 1423 |
my $msg = "\nChecking for album cover with path coverpath " . |
| 1424 |
"$coverpath."; |
| 1425 |
check_cover($coverpath, $msg) if($interaction == 1); |
| 1426 |
resize_cover("$copycover") |
| 1427 |
if(defined $coversize && $coversize =~ /^\d+$/); |
| 1428 |
} |
| 1429 |
if($normalize == 1 or $cdcue > 0) { |
| 1430 |
rip_cd(); |
| 1431 |
norm_cd(); |
| 1432 |
enc_cd(); |
| 1433 |
} |
| 1434 |
else { |
| 1435 |
if($rip == 1) { |
| 1436 |
rip_cd(); |
| 1437 |
} |
| 1438 |
else { |
| 1439 |
decode_tracks(); |
| 1440 |
enc_cd(); |
| 1441 |
} |
| 1442 |
} |
| 1443 |
# In case non public option multi is used make sure covers are |
| 1444 |
# copied if not present at process beginning. |
| 1445 |
if($multi == 1 && -f "$copycover" && -s "$copycover") { |
| 1446 |
copy_cover; |
| 1447 |
} |
| 1448 |
} |
| 1449 |
elsif($answer eq "next") { |
| 1450 |
print "\nFound tracks of release $cd{artist} - $cd{title} ", |
| 1451 |
"already done, giving up.\n" if($verbose > 0); |
| 1452 |
log_info("Directory already present, giving up."); |
| 1453 |
log_info("*" x 72, "\n"); |
| 1454 |
} |
| 1455 |
elsif($answer eq "unknown") { |
| 1456 |
print "\nRelease unknown, giving up.\n" if($verbose > 0); |
| 1457 |
log_info("Release unknown, giving up."); |
| 1458 |
log_info("*" x 72, "\n"); |
| 1459 |
} |
| 1460 |
|
| 1461 |
if($eject == 1 or $loop >= 1 |
| 1462 |
or $overwrite eq "e" and $answer eq "next") { |
| 1463 |
my $ejectopt = $cddev if($ejectopt eq '{cddev}'); |
| 1464 |
$ejectopt = $ejectopt . " eject" if($ejectcmd =~ /cdcontrol/); |
| 1465 |
log_system("$ejectcmd $ejectopt"); |
| 1466 |
} |
| 1467 |
|
| 1468 |
return if($answer eq "next" or $answer eq "unknown"); |
| 1469 |
|
| 1470 |
if($loop == 2) { |
| 1471 |
my $pid = fork(); |
| 1472 |
if(not defined $pid) { |
| 1473 |
print "\nResources not available, will quit.\n"; |
| 1474 |
} |
| 1475 |
elsif($pid != 0) { |
| 1476 |
finish_process($pid); |
| 1477 |
} |
| 1478 |
else { |
| 1479 |
# Child: restart process. |
| 1480 |
return; |
| 1481 |
# Problem: being recursive, we won't come back! Hello zombie. |
| 1482 |
exit(0); |
| 1483 |
} |
| 1484 |
} |
| 1485 |
else { |
| 1486 |
finish_process(); |
| 1487 |
} |
| 1488 |
$loop = 0 if($loop == 2); |
| 1489 |
return; |
| 1490 |
} |
| 1491 |
# |
| 1492 |
######################################################################## |
| 1493 |
# |
| 1494 |
# SUBROUTINES |
| 1495 |
# |
| 1496 |
######################################################################## |
| 1497 |
# |
| 1498 |
# New options step 9: Add new code as a subroutine somewhere below, |
| 1499 |
# the very end might be appropriate. |
| 1500 |
# |
| 1501 |
######################################################################## |
| 1502 |
# |
| 1503 |
# Check local .cddb directory for cddb files with album, artist, discID |
| 1504 |
# and track titles. |
| 1505 |
# |
| 1506 |
sub get_arch { |
| 1507 |
|
| 1508 |
# Get cddbid and number of tracks of CD. |
| 1509 |
my $trackno; |
| 1510 |
if($rip == 0) { |
| 1511 |
$trackno = substr($cddbid, 6); |
| 1512 |
$trackno = hex($trackno); |
| 1513 |
} |
| 1514 |
else { |
| 1515 |
($cddbid, $trackno) = get_cddbid(); |
| 1516 |
} |
| 1517 |
|
| 1518 |
my ($artist, $album); |
| 1519 |
my @comment = (); |
| 1520 |
|
| 1521 |
if($pgenre) { |
| 1522 |
$genre = $pgenre; |
| 1523 |
} |
| 1524 |
else { |
| 1525 |
$genre = ""; |
| 1526 |
} |
| 1527 |
if($pyear) { |
| 1528 |
$year = $pyear; |
| 1529 |
} |
| 1530 |
else { |
| 1531 |
$year = ""; |
| 1532 |
} |
| 1533 |
|
| 1534 |
my $usearch = "x"; |
| 1535 |
my @categs = (); |
| 1536 |
|
| 1537 |
print "\nChecking for a local DB entry, please wait...\n\n" |
| 1538 |
if($verbose > 1); |
| 1539 |
log_system("mkdir -m 0755 -p $homedir/.cddb") |
| 1540 |
or print "Can not create directory $homedir/.cddb: $!\n"; |
| 1541 |
opendir(CDDB, "$homedir/.cddb/") |
| 1542 |
or print "Can not read in $homedir/.cddb: $!\n"; |
| 1543 |
@categs = grep(/\w/i, readdir(CDDB)); |
| 1544 |
close(CDDB); |
| 1545 |
my @cddbid = (); |
| 1546 |
foreach (@categs) { |
| 1547 |
if(-d "$homedir/.cddb/$_") { |
| 1548 |
opendir(CATEG, "$homedir/.cddb/$_") |
| 1549 |
or print "Can not read in $homedir/.cddb: $!\n"; |
| 1550 |
my @entries = grep(/$cddbid$/, readdir(CATEG)); |
| 1551 |
close(CATEG); |
| 1552 |
push @cddbid, $_ if($entries[0]); |
| 1553 |
} |
| 1554 |
elsif(-f "$homedir/.cddb/$_" && -s "$homedir/.cddb/$_") { |
| 1555 |
push @cddbid, $_ if($_ =~ /$cddbid/); |
| 1556 |
} |
| 1557 |
} |
| 1558 |
my $count = 1; |
| 1559 |
my @dirflag = (); |
| 1560 |
my $openflag = "no"; |
| 1561 |
if($cddbid[0] and $cddbid =~ /[0-9a-f]/ and length($cddbid) == 8) { |
| 1562 |
print "Found local entry $cddbid in $homedir/.cddb !\n" |
| 1563 |
if($interaction == 1); |
| 1564 |
print "This CD could be:\n\n" if($interaction == 1); |
| 1565 |
foreach (@cddbid) { |
| 1566 |
if(-s "$homedir/.cddb/$_/$cddbid") { |
| 1567 |
open(LOG, "$homedir/.cddb/$_/$cddbid"); |
| 1568 |
$openflag = "ok"; |
| 1569 |
$dirflag[$count-1] = 1; |
| 1570 |
} |
| 1571 |
elsif(-s "$homedir/.cddb/$cddbid") { |
| 1572 |
open(LOG, "$homedir/.cddb/$cddbid"); |
| 1573 |
$_ = "no category found!"; |
| 1574 |
$openflag = "ok"; |
| 1575 |
$dirflag[$count-1] = 0; |
| 1576 |
} |
| 1577 |
if($openflag eq "ok") { |
| 1578 |
my @loglines = <LOG>; |
| 1579 |
close(LOG); |
| 1580 |
# Here we should test if @loglines is a good entry! |
| 1581 |
# If there are empty files, we get warnings! |
| 1582 |
chomp(my $artist = join(' ', grep(s/^DTITLE=//, @loglines))); |
| 1583 |
$artist = clean_all($artist); |
| 1584 |
chomp(my $agenre = join(' ', grep(s/^DGENRE=//, @loglines))); |
| 1585 |
$agenre =~ s/[\015]//g; |
| 1586 |
$agenre = "none" unless($agenre); |
| 1587 |
print "$count: $artist (genre: $agenre, category: $_)\n" |
| 1588 |
if($interaction == 1); |
| 1589 |
$count++; |
| 1590 |
$agenre = ""; |
| 1591 |
$openflag = "ko"; |
| 1592 |
} |
| 1593 |
} |
| 1594 |
if($openflag eq "no") { |
| 1595 |
$usearch = 0; |
| 1596 |
print "No valid entries found for CDDBID $cddbid.\n" |
| 1597 |
if(defined $cddbid && $verbose >= 3); |
| 1598 |
} |
| 1599 |
print "\n0: Search online DB instead.\n" |
| 1600 |
if($interaction == 1); |
| 1601 |
if($interaction == 0) { |
| 1602 |
$usearch = 1; |
| 1603 |
$usearch = 0 if($openflag eq "no"); |
| 1604 |
} |
| 1605 |
else { |
| 1606 |
while($usearch !~ /\d/ || $usearch >= $count) { |
| 1607 |
print "\nChoose: (1) "; |
| 1608 |
$usearch = <STDIN>; |
| 1609 |
chomp $usearch; |
| 1610 |
$usearch = 1 if($usearch eq ""); |
| 1611 |
print "\n"; |
| 1612 |
} |
| 1613 |
} |
| 1614 |
} |
| 1615 |
else { |
| 1616 |
print "No local entry with ID <$cddbid> found.\n"; |
| 1617 |
get_cdinfo() if($mb == 0 && $rip == 1); |
| 1618 |
get_mb() if($mb == 1 && $rip == 1); |
| 1619 |
log_info("No local entry with ID <$cddbid> found."); |
| 1620 |
return; |
| 1621 |
} |
| 1622 |
|
| 1623 |
if($usearch != 0) { |
| 1624 |
# We use "musicbrainz" as key when reading entry if coming from |
| 1625 |
# MB section (below). So if we have a ~/.cddb/musicbrainz |
| 1626 |
# directory this will give problems, use word "archive" for the |
| 1627 |
# category name instead. |
| 1628 |
my $ctg = $cddbid[$usearch-1]; |
| 1629 |
log_info("Local entry found in $ctg/$cddbid."); |
| 1630 |
$ctg = "archive" if($ctg =~ /musicbrainz/); |
| 1631 |
if($dirflag[$usearch-1] == 1) { |
| 1632 |
read_entry("$homedir/.cddb/$cddbid[$usearch-1]/$cddbid", |
| 1633 |
$ctg, $trackno); |
| 1634 |
} |
| 1635 |
elsif($dirflag[$usearch-1] == 0) { |
| 1636 |
read_entry("$homedir/.cddb/$cddbid", $ctg, $trackno); |
| 1637 |
} |
| 1638 |
$categ = $cd{cat} = $cddbid[$usearch-1]; |
| 1639 |
} |
| 1640 |
else { |
| 1641 |
get_cdinfo() if($mb == 0); |
| 1642 |
get_mb() if($mb == 1); |
| 1643 |
return; |
| 1644 |
} |
| 1645 |
|
| 1646 |
# Actually this is useless if MB failed and local archive is |
| 1647 |
# fallback... shouldn't go here in in this case as we will fail |
| 1648 |
# again. |
| 1649 |
# So retrieve the discid if not yet done, although we should have it |
| 1650 |
# in case $mb == 1... |
| 1651 |
if($mb == 1 && $rip == 1 && $discid eq "") { |
| 1652 |
open(DISCID, "discid $scsi_cddev|"); |
| 1653 |
my @response = <DISCID>; |
| 1654 |
close(DISCID); |
| 1655 |
chomp($cd{discid} = join("", grep(s/^DiscID\s*:\s//, @response))); |
| 1656 |
$discid = $cd{discid}; |
| 1657 |
# Fill up the track->id array @idata in case we want to submit |
| 1658 |
# ISRCs after sub disc_info, but only if ripit found one single |
| 1659 |
# match. |
| 1660 |
if($isrc == 1) { |
| 1661 |
eval { |
| 1662 |
my $ws = WebService::MusicBrainz::Release->new(); |
| 1663 |
my $result = $ws->search({ DISCID => $cd{discid} }); |
| 1664 |
my @releases = @{$result->release_list->releases}; |
| 1665 |
if(scalar(@releases) == 1) { |
| 1666 |
my $release = $releases[0]; |
| 1667 |
my @tracks = @{$release->track_list->tracks}; |
| 1668 |
for(my $i = 0; $i < scalar(@tracks); $i++) { |
| 1669 |
my $track = $tracks[$i]; |
| 1670 |
push(@idata, $track->id); |
| 1671 |
} |
| 1672 |
} |
| 1673 |
} |
| 1674 |
} |
| 1675 |
} |
| 1676 |
} |
| 1677 |
######################################################################## |
| 1678 |
# |
| 1679 |
# Read the album, artist, discID and track titles via the get_CDDB() |
| 1680 |
# module. |
| 1681 |
# |
| 1682 |
sub get_cdinfo { |
| 1683 |
my $writecddb = shift; # Passed when calling this sub from get_mb. |
| 1684 |
$writecddb = 0 unless($writecddb); |
| 1685 |
my %config = (); |
| 1686 |
|
| 1687 |
# Items to import into callers namespace by default. |
| 1688 |
CDDB_get->import( qw( get_cddb get_discids ) ); |
| 1689 |
|
| 1690 |
# Get cddbid and number of tracks of CD. |
| 1691 |
my $trackno; |
| 1692 |
if($rip == 0) { |
| 1693 |
$trackno = substr($cddbid, 6); |
| 1694 |
$trackno = hex($trackno); |
| 1695 |
} |
| 1696 |
else { |
| 1697 |
($cddbid, $trackno) = get_cddbid(); |
| 1698 |
} |
| 1699 |
my $diskid = hex($cddbid); |
| 1700 |
|
| 1701 |
my ($artist, $album, $revision); |
| 1702 |
my ($CDDB_INPUT, $CDDB_MODE, $CDDB_PORT); |
| 1703 |
my @comment = (); |
| 1704 |
|
| 1705 |
if($pgenre) { |
| 1706 |
$genre = $pgenre; |
| 1707 |
} |
| 1708 |
else { |
| 1709 |
$genre = ""; |
| 1710 |
} |
| 1711 |
if($pyear) { |
| 1712 |
$year = $pyear; |
| 1713 |
} |
| 1714 |
else { |
| 1715 |
$year = "" unless($writecddb == 0); |
| 1716 |
} |
| 1717 |
|
| 1718 |
#Configure CDDB_get parameters |
| 1719 |
if($CDDB_HOST eq "freedb2.org") { |
| 1720 |
$config{CDDB_HOST} = $CDDB_HOST; |
| 1721 |
} |
| 1722 |
elsif($CDDB_HOST eq "musicbrainz.org") { |
| 1723 |
$config{CDDB_HOST} = "freedb." . $CDDB_HOST; |
| 1724 |
} |
| 1725 |
else { |
| 1726 |
$config{CDDB_HOST} = $mirror . "." . $CDDB_HOST; |
| 1727 |
} |
| 1728 |
while($transfer !~ /^cddb$|^http$/) { |
| 1729 |
print "Transfer mode not valid!\n"; |
| 1730 |
print "Enter cddb or http : "; |
| 1731 |
$transfer = <STDIN>; |
| 1732 |
chomp $transfer; |
| 1733 |
} |
| 1734 |
if($transfer eq "cddb") { |
| 1735 |
$CDDB_PORT = 8880; |
| 1736 |
$CDDB_MODE = "cddb"; |
| 1737 |
} |
| 1738 |
elsif($transfer eq "http") { |
| 1739 |
$CDDB_PORT = 80; |
| 1740 |
$CDDB_MODE = "http"; |
| 1741 |
} |
| 1742 |
$config{CDDB_MODE} = $CDDB_MODE; |
| 1743 |
$config{CDDB_PORT} = $CDDB_PORT; |
| 1744 |
$config{CD_DEVICE} = $scsi_cddev; |
| 1745 |
$config{HTTP_PROXY}= $proxy if($proxy); |
| 1746 |
if($interaction == 0) { |
| 1747 |
$CDDB_INPUT = 0; |
| 1748 |
} |
| 1749 |
else { |
| 1750 |
$CDDB_INPUT = 1; |
| 1751 |
} |
| 1752 |
$config{input} = $CDDB_INPUT; |
| 1753 |
$config{PROTO_VERSION} = $proto; |
| 1754 |
|
| 1755 |
# Change to whatever, but be aware to enter exactly 4 words! |
| 1756 |
# E.g. username hostname clientname version |
| 1757 |
my $hid = "RipIT www.suwald.com/ripit/ripit.html RipIT $version"; |
| 1758 |
my @hid = split(/ /, $hid); |
| 1759 |
if($hid[4]) { |
| 1760 |
print "There are more than 4 words in the \"HELLO_ID\".\n", |
| 1761 |
"The handshake with the freeDB-server will fail!\n\n"; |
| 1762 |
} |
| 1763 |
$config{HELLO_ID} = $hid; |
| 1764 |
|
| 1765 |
# Add the framelist to the calling sequence in case of re-encoding |
| 1766 |
# with no disc to be read out. Remember, the framelist has been |
| 1767 |
# assembled in the get_MB subroutine. |
| 1768 |
my @toc; |
| 1769 |
if($rip == 0) { |
| 1770 |
my $totaltime = substr($cddbid, 2, 4); |
| 1771 |
$totaltime = hex($totaltime); |
| 1772 |
push(@framelist, $totaltime * 75); |
| 1773 |
@toc = create_toc(@framelist); |
| 1774 |
} |
| 1775 |
print "\nChecking for a DB entry \@ $config{CDDB_HOST}...\n" |
| 1776 |
if($verbose >= 1 && $writecddb != 0); |
| 1777 |
if($rip == 0) { |
| 1778 |
eval {%cd = get_cddb(\%config, [$diskid, $trackno, \@toc]);}; |
| 1779 |
} |
| 1780 |
else { |
| 1781 |
# use Data::Dumper; |
| 1782 |
# print Dumper(%config); |
| 1783 |
eval {%cd = get_cddb(\%config);}; |
| 1784 |
} |
| 1785 |
if($@) { |
| 1786 |
$@ =~ s/db:\s/db:\n/; |
| 1787 |
$@ =~ s/at\s\//at\n\//; |
| 1788 |
print "No connection to internet? The error message is:\n", |
| 1789 |
"$@\n" if($verbose >= 1); |
| 1790 |
$submission = 0; |
| 1791 |
} |
| 1792 |
# |
| 1793 |
# Thanks to Frank Sundermeyer |
| 1794 |
# If wanting to write the CDDB data (archive=1) but having set |
| 1795 |
# interaction=0, the CDDB data will not get modified, so it |
| 1796 |
# is safe to write it now. |
| 1797 |
# But this routine is also called from get_mb (for getting a genre) |
| 1798 |
# with $interaction temporarily set to 0. We call it with a parameter |
| 1799 |
# set to zero (0) when calling it from get_mb. This parameter is |
| 1800 |
# saved to $writecddb. Therefore do not write the entry if |
| 1801 |
# $writecddb == 0, i.e. if we came from MB part. |
| 1802 |
# |
| 1803 |
if($interaction == 0 && $archive == 1 && defined $cd{title}) { |
| 1804 |
write_cddb() unless($writecddb == 0); |
| 1805 |
} |
| 1806 |
|
| 1807 |
if($multi == 1) { |
| 1808 |
my $cddevno = $cddev; |
| 1809 |
$cddevno =~ s/\/dev\///; |
| 1810 |
$cddevno =~ s/(\d)/0$1/ unless($cddevno =~ /\d\d/); |
| 1811 |
$logfile = $outputdir . "/" . $cddevno; |
| 1812 |
read_entry($logfile, "multi"); |
| 1813 |
} |
| 1814 |
} |
| 1815 |
######################################################################## |
| 1816 |
# |
| 1817 |
# Read the album, artist, discID and track titles from MusicBrainz. |
| 1818 |
# |
| 1819 |
sub get_mb { |
| 1820 |
print "Querying MusicBrainz DB.\n" if($verbose >= 3); |
| 1821 |
my ($mbreid, $trackno, $totaltime); |
| 1822 |
|
| 1823 |
# Get cddbid and number of tracks of CD; note: $cddbid is global and |
| 1824 |
# might exist in case of re-encoding. |
| 1825 |
if($rip == 0) { |
| 1826 |
$trackno = substr($cddbid, 6); |
| 1827 |
$trackno = hex($trackno); |
| 1828 |
$totaltime = substr($cddbid, 2, 4); |
| 1829 |
$totaltime = hex($totaltime); |
| 1830 |
} |
| 1831 |
else { |
| 1832 |
($cddbid, $trackno, $totaltime) = get_cddbid(); |
| 1833 |
} |
| 1834 |
# Using the perl module to retrieve the MB discid. |
| 1835 |
my $submit_url = 0; |
| 1836 |
my $disc; |
| 1837 |
if($rip == 0) { |
| 1838 |
# TODO: |
| 1839 |
# Manually compose the MB submission url in case operator needs |
| 1840 |
# to submit missing data. |
| 1841 |
$submit_url = "" |
| 1842 |
} |
| 1843 |
else { |
| 1844 |
eval {$disc = new MusicBrainz::DiscID($scsi_cddev);}; |
| 1845 |
if($@) { |
| 1846 |
# Use the libdiscid command discid to retrieve the MB discid. |
| 1847 |
print "Discid detection with the libdiscid command.\n" |
| 1848 |
if($verbose > 5); |
| 1849 |
open(DISCID, "discid $scsi_cddev|"); |
| 1850 |
my @response = <DISCID>; |
| 1851 |
close(DISCID); |
| 1852 |
chomp($discid = join("", grep(s/^DiscID\s*:\s//, @response))); |
| 1853 |
chomp($submit_url = join("", grep(s/^Submit\svia\s*:\s//, @response))); |
| 1854 |
} |
| 1855 |
else { |
| 1856 |
print "Discid detection with module MusicBrainz::DiscID ", |
| 1857 |
"successful.\n" if($verbose > 5); |
| 1858 |
if($disc->read() == 0) { |
| 1859 |
print "Error: %s\n", $disc->error_msg(); |
| 1860 |
get_cdinfo(); |
| 1861 |
return; |
| 1862 |
} |
| 1863 |
$discid = $disc->id(); |
| 1864 |
$submit_url = $disc->submission_url(); |
| 1865 |
} |
| 1866 |
} |
| 1867 |
print "\nChecking for a DB entry \@ MusicBrainz.org...\n" |
| 1868 |
if($verbose >= 1); |
| 1869 |
my $service; |
| 1870 |
eval {$service = WebService::MusicBrainz::Release->new();}; |
| 1871 |
my $discid_response; |
| 1872 |
eval { |
| 1873 |
$discid_response = $service->search({ DISCID => $discid }); |
| 1874 |
}; |
| 1875 |
if($@){ |
| 1876 |
print "\nMusicBrainz look-up failed... 2nd try in 3s.", |
| 1877 |
"\nError message is: $@.\n" if($verbose > 3); |
| 1878 |
sleep 3; |
| 1879 |
eval {$discid_response = $service->search({ DISCID => $discid });}; |
| 1880 |
if($@){ |
| 1881 |
print "\nMusicBrainz look-up failed.\n" if($verbose > 3); |
| 1882 |
print "Using freedb instead.", |
| 1883 |
"\nError message is: $@.\n" if($verbose > 3 && $rip > 0); |
| 1884 |
# Do not try freedb in case $rip == 0 as we do not have the toc. |
| 1885 |
get_cdinfo() unless($rip == 0); |
| 1886 |
return; |
| 1887 |
} |
| 1888 |
} |
| 1889 |
else { |
| 1890 |
print "DiscID retrieved.\n" if($verbose > 4); |
| 1891 |
print "Discid is: $discid\n" if($verbose > 3); |
| 1892 |
} |
| 1893 |
|
| 1894 |
my $AoH; |
| 1895 |
eval { |
| 1896 |
my $relH = $discid_response->release_list(); |
| 1897 |
foreach my $medium (@{$relH->releases()}) { |
| 1898 |
my $a = $medium->artist->name(); |
| 1899 |
my $i = $medium->id(); |
| 1900 |
my $t = $medium->title(); |
| 1901 |
push(@{$AoH}, {'artist' => $a, 'id' => $i, 'title' => $t}); |
| 1902 |
# MBREID needed for following conditions. Use the first one |
| 1903 |
# presented, this is the one that will be used if only one |
| 1904 |
# release is found. |
| 1905 |
$mbreid = $i unless(defined $mbreid && $mbreid ne ""); |
| 1906 |
} |
| 1907 |
}; |
| 1908 |
if($@){ |
| 1909 |
print "\nMusicBrainz does not know this discid. Use\n", |
| 1910 |
"$submit_url for submission!\n" if($verbose > 1); |
| 1911 |
# Do not try freedb in case $rip == 0 as we do not have the toc. |
| 1912 |
get_cdinfo() unless($rip == 0); |
| 1913 |
return; |
| 1914 |
} |
| 1915 |
# This should not happen. |
| 1916 |
elsif(!defined $mbreid or $mbreid eq "") { |
| 1917 |
print "\nNo discid $discid found at MusicBrainz. Use\n", |
| 1918 |
"$submit_url for submission!\n" if($verbose > 1); |
| 1919 |
} |
| 1920 |
elsif($#{$AoH} > 0 && $interaction == 1) { |
| 1921 |
print "\nMore than one release found:\n"; |
| 1922 |
my $i = 0; |
| 1923 |
while($i > $#{$AoH}+1 || $i <= 0) { |
| 1924 |
$i = 0; |
| 1925 |
foreach (@{$AoH}) { |
| 1926 |
$i++; |
| 1927 |
printf(" %2d", $i); |
| 1928 |
print ": ", $_->{artist}, ": ", $_->{title}, " (MBREID: ", $_->{id}, ")\n"; |
| 1929 |
} |
| 1930 |
print "\nChoose [1-$i]: "; |
| 1931 |
$i = <STDIN>; |
| 1932 |
chomp $i; |
| 1933 |
} |
| 1934 |
$mbreid = ${$AoH}[$i-1]->{id}; |
| 1935 |
print "MBREID is: $mbreid.\n" if($verbose > 3); |
| 1936 |
$cd{mbreid} = $mbreid; |
| 1937 |
} |
| 1938 |
else { |
| 1939 |
print "MBREID is: $mbreid.\n" if($verbose > 3); |
| 1940 |
$cd{mbreid} = $mbreid; |
| 1941 |
} |
| 1942 |
if(defined $mbreid and $mbreid ne "" and $verbose > 4) { |
| 1943 |
print "\nUse\n", |
| 1944 |
"$submit_url for submission!\n"; |
| 1945 |
} |
| 1946 |
# Intermezzo (could be done further below). |
| 1947 |
# Figure out number of disks and possible track offset. |
| 1948 |
# Code based on Don Armstrongs submission. |
| 1949 |
my $prev_discno = $discno; |
| 1950 |
my $xml; |
| 1951 |
my $ua = LWP::UserAgent->new(); |
| 1952 |
if(defined $mbreid && $mbreid ne "") { |
| 1953 |
print "\nChecking for a multi disc release \@ MusicBrainz.org...\n" |
| 1954 |
if($verbose >= 1 && $addtrackoffset == 1); |
| 1955 |
eval { |
| 1956 |
$ua->env_proxy(); |
| 1957 |
$ua->agent("ripit/$version"); |
| 1958 |
my $response = $ua->get("http://musicbrainz.org/ws/2/release/$mbreid?inc=media+discids+release-group-rels"); |
| 1959 |
use XML::Simple qw(:strict); |
| 1960 |
$xml = XMLin($response->content(), ForceArray => 0, KeyAttr => []); |
| 1961 |
if(defined $xml->{release}{'medium-list'}{count} && $xml->{release}{'medium-list'}{count} > 1) { |
| 1962 |
foreach my $medium (@{$xml->{release}{'medium-list'}{medium}}) { |
| 1963 |
# The discS in the disc-list can be an array. This needs |
| 1964 |
# to be checked first. |
| 1965 |
my $lastflag = 0; |
| 1966 |
if(exists $medium->{'disc-list'}{count} and |
| 1967 |
$medium->{'disc-list'}{count} > 1) { |
| 1968 |
foreach my $discarray (@{$medium->{'disc-list'}{disc}}) { |
| 1969 |
if(exists $discarray->{$discid} or |
| 1970 |
exists $discarray->{id} and |
| 1971 |
$discarray->{id} eq $discid) { |
| 1972 |
$lastflag = 1; |
| 1973 |
} |
| 1974 |
} |
| 1975 |
} |
| 1976 |
# Else the regular case with only one disc, probably |
| 1977 |
# not needed anymore. |
| 1978 |
else{ |
| 1979 |
if(exists $medium->{'disc-list'}{disc}{$discid} or |
| 1980 |
exists $medium->{'disc-list'}{disc}{id} and |
| 1981 |
$medium->{'disc-list'}{disc}{id} eq $discid) { |
| 1982 |
$lastflag = 1; |
| 1983 |
} |
| 1984 |
} |
| 1985 |
$discno += $medium->{'disc-list'}{count} |
| 1986 |
if($discno == 1 && $medium->{'disc-list'}{count} > 0); |
| 1987 |
last if($lastflag > 0); |
| 1988 |
$trackoffset += $medium->{'track-list'}{count} |
| 1989 |
if($addtrackoffset == 1); |
| 1990 |
} |
| 1991 |
} |
| 1992 |
}; |
| 1993 |
print "Adding trackoffset $trackoffset to track numbers.\n" |
| 1994 |
if($trackoffset > 0 && $verbose > 2); |
| 1995 |
print "Setting discno to $discno.\n" |
| 1996 |
if($discno > 1 && $prev_discno != $discno && $verbose > 2); |
| 1997 |
} |
| 1998 |
# Instead of pulling out the data from the release_list response |
| 1999 |
# above, get a new response according to the MBREID choosen, sorry |
| 2000 |
# for the additional traffic. |
| 2001 |
eval { |
| 2002 |
$discid_response = $service->search( |
| 2003 |
{ MBID => $mbreid, |
| 2004 |
INC => 'artist+release-events+tracks+url-rels' }); |
| 2005 |
}; |
| 2006 |
if($@){ |
| 2007 |
print "\nMusicBrainz look-up failed... 2nd try in 3s.", |
| 2008 |
"\nError message is: $@.\n" if($verbose > 3); |
| 2009 |
sleep 3; |
| 2010 |
eval {$discid_response = $service->search( |
| 2011 |
{ MBID => $mbreid, |
| 2012 |
INC => 'artist+release-events+tracks+url-rels' }); |
| 2013 |
;}; |
| 2014 |
if($@){ |
| 2015 |
print "\nMusicBrainz look-up failed.\n" if($verbose > 3); |
| 2016 |
print "Using freedb instead.", |
| 2017 |
"\nError message is: $@.\n" if($verbose > 3 && $rip > 0); |
| 2018 |
# Do not try freedb in case $rip == 0 as we do not have the toc. |
| 2019 |
get_cdinfo() unless($rip == 0); |
| 2020 |
return; |
| 2021 |
} |
| 2022 |
} |
| 2023 |
else { |
| 2024 |
print "DiscID retrieved.\n" if($verbose > 4); |
| 2025 |
print "Discid is: $discid\n" if($verbose > 3); |
| 2026 |
} |
| 2027 |
|
| 2028 |
my $release = $discid_response->release(); |
| 2029 |
my $artist = $release->artist()->name(); |
| 2030 |
my $album = $release->title(); |
| 2031 |
my $asin = $release->asin(); |
| 2032 |
my $language = $release->text_rep_language(); |
| 2033 |
$artist =~ s/^The\s+// unless($artist =~ /^The\sThe/); |
| 2034 |
$language = "English" unless($language); |
| 2035 |
$language = "English" if($language eq "ENG"); |
| 2036 |
$language = "French" if($language eq "FRA"); |
| 2037 |
$language = "German" if($language eq "DEU"); |
| 2038 |
|
| 2039 |
my $content = $release->release_event_list(); |
| 2040 |
my $reldate = ""; |
| 2041 |
my $barcode = ""; |
| 2042 |
my $catalog = ""; |
| 2043 |
if($content) { |
| 2044 |
eval {$reldate = ${$content->events()}[0]->date();}; |
| 2045 |
eval {$barcode = ${$content->events()}[0]->barcode();}; |
| 2046 |
eval {$catalog = ${$content->events()}[0]->catalog_number();}; |
| 2047 |
} |
| 2048 |
my @urls; |
| 2049 |
my $dgid = ""; |
| 2050 |
my $asinurl = ""; |
| 2051 |
eval { |
| 2052 |
$content = $release->relation_list->relations(); |
| 2053 |
if($content) { |
| 2054 |
for my $url (@{$content}) { |
| 2055 |
if(exists $url->{'target'}) { |
| 2056 |
push(@urls, $url->{'target'}); |
| 2057 |
} |
| 2058 |
} |
| 2059 |
} |
| 2060 |
foreach(@urls) { |
| 2061 |
s:^.*discogs.com/release/::; |
| 2062 |
$dgid = $_ if(/^\d+$/); |
| 2063 |
$asinurl = $_ if(/www\.amazon\./); |
| 2064 |
} |
| 2065 |
}; |
| 2066 |
my $mb_year = $reldate; |
| 2067 |
$mb_year =~ s/-.*$// if($mb_year); |
| 2068 |
# Do not overwrite a year passed on CL. |
| 2069 |
$year = $mb_year unless($year =~ /\d{4}/ ); |
| 2070 |
|
| 2071 |
# Why this? Actually, I don't know. Thought that in the 21st |
| 2072 |
# century there should be no UTF-8 problem anymore... But getting |
| 2073 |
# e.g. track names with pure ascii in one track, latin chars in an |
| 2074 |
# other track and even true wide chars in a third one will totally |
| 2075 |
# mess up encoder tags and even the file names used by the ripper. |
| 2076 |
my $temp_file = "/tmp/ripit-MB-$$\.txt"; |
| 2077 |
open(TMP, '>:utf8', "$temp_file") or print "$temp_file $!"; |
| 2078 |
print TMP "artist: $artist\n"; |
| 2079 |
print TMP "album: $album\n"; |
| 2080 |
print TMP "category: musicbrainz\n"; |
| 2081 |
print TMP "cddbid: $cddbid\n"; |
| 2082 |
print TMP "discid: $discid\n"; |
| 2083 |
print TMP "MBREID: $mbreid\n"; |
| 2084 |
print TMP "asin: $asin\n" if($asin); |
| 2085 |
print TMP "asinurl: $asinurl\n" if($asinurl); |
| 2086 |
print TMP "discogs: $dgid\n" if($dgid); |
| 2087 |
print TMP "year: $year\n" if($year); |
| 2088 |
print TMP "language: $language\n"; |
| 2089 |
print TMP "reldate: $reldate\n" if($reldate); |
| 2090 |
print TMP "barcode: $barcode\n" if($barcode); |
| 2091 |
print TMP "catalog: $catalog\n" if($catalog); |
| 2092 |
print TMP "totaltime: $totaltime\n" if($totaltime); |
| 2093 |
print TMP "disc-number: $discno\n" if($discno > 0); |
| 2094 |
print TMP "trackoff: $trackoffset\n" if($trackoffset > 0); |
| 2095 |
|
| 2096 |
my $track_list = $release->track_list(); |
| 2097 |
my $mb_trackno = $#{$track_list->tracks()} + 1; |
| 2098 |
|
| 2099 |
my $i=0; |
| 2100 |
my $j=0; |
| 2101 |
@framelist = 150; |
| 2102 |
my $frame = 150; |
| 2103 |
print "Retrieving track relationships for each track, this might ", |
| 2104 |
"take a while...\n" if($verbose > 2 && $mbrels > 0); |
| 2105 |
foreach my $track (@{$track_list->tracks()}) { |
| 2106 |
$i++; |
| 2107 |
next if($i <= $trackoffset && $addtrackoffset == 1); |
| 2108 |
$_ = $track->title(); |
| 2109 |
my $track_id = $track->id(); |
| 2110 |
|
| 2111 |
if($mbrels > 0) { |
| 2112 |
my $rela_artist = ""; |
| 2113 |
my $rela_work = ""; |
| 2114 |
|
| 2115 |
eval { |
| 2116 |
$ua->env_proxy(); |
| 2117 |
$ua->agent("ripit/$version"); |
| 2118 |
my $response = $ua->get("http://musicbrainz.org/ws/2/recording/" . $track->id() . "?inc=recording-rels+artist-rels+work-rels"); |
| 2119 |
$xml = XMLin($response->content(), ForceArray => ['relation-list'], KeyAttr => []); |
| 2120 |
for my $rel (@{$xml->{recording}{'relation-list'}}) { |
| 2121 |
if(exists $rel->{'relation'}{'artist'}{'name'}) { |
| 2122 |
$rela_artist = $rel->{'relation'}{'artist'}{'name'}; |
| 2123 |
} |
| 2124 |
if(exists $rel->{'relation'}{'artist'}{'work'}) { |
| 2125 |
$rela_work = $rel->{'relation'}{'artist'}{'name'}; |
| 2126 |
} |
| 2127 |
} |
| 2128 |
}; |
| 2129 |
|
| 2130 |
if($rela_artist ne "") { |
| 2131 |
$_ .= " (featuring $rela_artist)"; |
| 2132 |
} |
| 2133 |
if($rela_work ne "") { |
| 2134 |
$_ .= " [covering $rela_work]"; |
| 2135 |
} |
| 2136 |
} |
| 2137 |
# Various artist style |
| 2138 |
$j++; |
| 2139 |
if($track->artist) { |
| 2140 |
# TODO: Fill array track artist here. |
| 2141 |
# What happens if no track artist is found? Album artist as |
| 2142 |
# filler. |
| 2143 |
print TMP "track $i: ", $track->artist->name(), " / $_\n"; |
| 2144 |
print "\nVarious artist style detected:\n" if($verbose > 4); |
| 2145 |
print "track $i: ", $track->artist->name(), " / $_\n" |
| 2146 |
if($verbose > 4); |
| 2147 |
$va_flag = 2; |
| 2148 |
$va_delim = "/"; |
| 2149 |
} |
| 2150 |
# Normal tracklist style. |
| 2151 |
else { |
| 2152 |
my $j = $i; |
| 2153 |
$j += $trackoffset if($trackoffset > 0 and $addtrackoffset == 0); |
| 2154 |
print TMP "track $j: $_\n"; |
| 2155 |
} |
| 2156 |
# For ISRC detection/submission use the track IDs. |
| 2157 |
push(@idata, $track->id); |
| 2158 |
push(@framelist, int($track->duration / 1000 * 75 + $frame + 0.5)); |
| 2159 |
$frame += $track->duration / 1000 * 75 + 0.5; |
| 2160 |
} |
| 2161 |
$trackno = $j if($rip == 0); |
| 2162 |
$i++; |
| 2163 |
# MusicBrainz does not state data tracks. Let's continue to fill up |
| 2164 |
# the tracklist in the %cd-hash. |
| 2165 |
while($i <= $trackno) { |
| 2166 |
print TMP "track $i: data\n"; |
| 2167 |
$i++; |
| 2168 |
$j++; |
| 2169 |
# Oops, we're lost in case we want to fill the framelist... |
| 2170 |
} |
| 2171 |
print TMP "trackno: $trackno\n"; |
| 2172 |
|
| 2173 |
# Some people insist in getting a genre, but MB does not supply one. |
| 2174 |
# Don't go in here when re-encoding, no way to make a freedb look-up. |
| 2175 |
# OK, it is possible, in case we have the cdid from freedb which |
| 2176 |
# gives us total playing time. Now having all durations from MB |
| 2177 |
# (except lead-out) we can calculate lead-out and therefor provide |
| 2178 |
# the full toc, i.e. array [$diskid, $trackno, $toc] in the |
| 2179 |
# sub get_cdinfo above. Of course we do not know the pre-gap too, so |
| 2180 |
# just use the most common one (150s). |
| 2181 |
if($rip == 1 and $genre eq "" and $framelist[0] =~ /\d+/) { |
| 2182 |
my $save_inter = $interaction; |
| 2183 |
$interaction = 0; |
| 2184 |
print "Retrieving a genre from freedb.org.\n" if($verbose > 2); |
| 2185 |
get_cdinfo(0); |
| 2186 |
$interaction = $save_inter; |
| 2187 |
$genre = $cd{genre}; |
| 2188 |
$year = $cd{year} unless($year =~ /\d{4}/); |
| 2189 |
} |
| 2190 |
# Actually, do not override existing genre as we have to refer to |
| 2191 |
# freedb and from there one might get back crap. If a genre exists |
| 2192 |
# from existing tags, keep it as it might be fulfill operators |
| 2193 |
# wishes. |
| 2194 |
elsif($rip == 0 && $genre eq "" && $cddbid ne "") { |
| 2195 |
my $save_inter = $interaction; |
| 2196 |
$interaction = 0; |
| 2197 |
print "Retrieving a genre from freedb.org.\n" if($verbose > 2); |
| 2198 |
get_cdinfo(0); |
| 2199 |
$interaction = $save_inter; |
| 2200 |
$genre = $cd{genre}; |
| 2201 |
$year = $cd{year} unless($year =~ /\d{4}/ ); |
| 2202 |
} |
| 2203 |
print TMP "genre: $genre\n" if($genre); |
| 2204 |
|
| 2205 |
close(TMP); |
| 2206 |
read_entry("$temp_file", "musicbrainz", $trackno); |
| 2207 |
unlink("$temp_file"); |
| 2208 |
} |
| 2209 |
######################################################################## |
| 2210 |
# |
| 2211 |
# Read CD-text with code submitted by S. Oosthoek |
| 2212 |
# |
| 2213 |
sub get_cdtext { |
| 2214 |
%cd = (); |
| 2215 |
print "\nChecking for CD-text...\n" if($verbose > 1); |
| 2216 |
my $cdinfoexe = `which cd-info`; |
| 2217 |
chomp $cdinfoexe; |
| 2218 |
if(-x $cdinfoexe) { |
| 2219 |
open(CDTXT, "cd-info --no-cddb |"); |
| 2220 |
my $cdtextfound = 0; |
| 2221 |
my $currentinfo = ""; |
| 2222 |
my $diff_cn = 0; |
| 2223 |
my $prev_perf = ""; |
| 2224 |
my $tracknr = 1; |
| 2225 |
my $prev_trnr = 0; |
| 2226 |
while(<CDTXT>) { |
| 2227 |
chomp; |
| 2228 |
print "\n$_\n" if($verbose > 5); |
| 2229 |
$cdtextfound = ($_ =~ /CD-TEXT/ || $cdtextfound) ? 1 : 0; |
| 2230 |
if($cdtextfound) { |
| 2231 |
if(/Disc/) { |
| 2232 |
$currentinfo = "disk"; |
| 2233 |
} |
| 2234 |
elsif(/Track\s+(?<tracknum>\d+):/) { |
| 2235 |
$currentinfo = "track"; |
| 2236 |
$tracknr = $+{tracknum}; |
| 2237 |
} |
| 2238 |
elsif(/^\s+(?<tag>\w+):\s+(?<content>.*)/) { |
| 2239 |
my $tag = $+{tag}; |
| 2240 |
my $content = $+{content}; |
| 2241 |
if($currentinfo =~ /disk/) { |
| 2242 |
$cd{artist} = $content if($tag =~ /PERFORMER/); |
| 2243 |
$cd{title} = $content if($tag =~ /TITLE/); |
| 2244 |
} |
| 2245 |
elsif($currentinfo =~ /track/) { |
| 2246 |
# In case CD-text could not be read out completely |
| 2247 |
# add dummy entries for complete arrays. |
| 2248 |
while($prev_trnr < $tracknr) { |
| 2249 |
if($#{$cd{track}} > - 1 and $#{$cd{track}} < ($prev_trnr - 1)) { |
| 2250 |
push(@{$cd{track}}, "unknown track"); |
| 2251 |
} |
| 2252 |
if($#{$cd{track_artist}} > - 1 and $#{$cd{track_artist}} < ($prev_trnr - 1)) { |
| 2253 |
# TODO: should the album artist be used (if defined) instead of placeholders? |
| 2254 |
push(@{$cd{track_artist}}, "unknown performer"); |
| 2255 |
} |
| 2256 |
$prev_trnr++; |
| 2257 |
last if($prev_trnr > 100); |
| 2258 |
} |
| 2259 |
# Regular array filling. |
| 2260 |
push(@{$cd{track}}, "$content") if($tag =~ /TITLE/); |
| 2261 |
push(@{$cd{track_artist}}, $content) if($tag =~ /PERFORMER/); |
| 2262 |
$diff_cn++ if($prev_perf ne $content and $tag =~ /PERFORMER/); |
| 2263 |
$prev_perf = $content if($tag =~ /PERFORMER/); |
| 2264 |
$prev_trnr = $tracknr; |
| 2265 |
} |
| 2266 |
else { |
| 2267 |
print "No track info found on CD.\n" if($verbose > 5); |
| 2268 |
} |
| 2269 |
} |
| 2270 |
else { |
| 2271 |
print "No CDTEXT found.\n" if($verbose > 5); |
| 2272 |
} |
| 2273 |
} |
| 2274 |
} |
| 2275 |
if($cdtextfound == 0 or !defined $cd{artist} or !defined $cd{title}) { |
| 2276 |
print "\nNo CDTEXT found.\n" if($verbose > 3); |
| 2277 |
} |
| 2278 |
elsif($cd{artist} eq "" && $cd{title} ne "" && $cd{track}[0] ne "" && $diff_cn > 1) { |
| 2279 |
$cd{artist} = "Various Artists"; |
| 2280 |
} |
| 2281 |
elsif($cd{artist} eq "" && $cd{title} eq "" && $cd{track}[0] ne "") { |
| 2282 |
$cd{artist} = "Unknown Artist"; |
| 2283 |
$cd{title} = "Unknown Album"; |
| 2284 |
} |
| 2285 |
elsif($cd{artist} eq "" && $cd{title} ne "" && $cd{track}[0] ne "") { |
| 2286 |
$cd{artist} = "Unknown Artist"; |
| 2287 |
} |
| 2288 |
elsif($cd{artist} ne "" && $cd{title} eq "" && $cd{track}[0] ne "") { |
| 2289 |
$cd{title} = "Unknown Album"; |
| 2290 |
} |
| 2291 |
# Check for VA style |
| 2292 |
if($diff_cn > 1) { |
| 2293 |
my @tra_art = @{$cd{track_artist}}; |
| 2294 |
print "Compilation detected from CD-text.\n" if($verbose > 2); |
| 2295 |
foreach my $track (@{$cd{track}}) { |
| 2296 |
$track = shift(@tra_art) . " / " . $track; |
| 2297 |
} |
| 2298 |
} |
| 2299 |
$cd{cat} = "CDTEXT"; |
| 2300 |
} |
| 2301 |
else { |
| 2302 |
print "cd-info (from cdda2wav or cdio-utils package) not ", |
| 2303 |
"installed!\n" if($verbose > 0); |
| 2304 |
} |
| 2305 |
} |
| 2306 |
######################################################################## |
| 2307 |
# |
| 2308 |
# Display CDDB info. |
| 2309 |
# |
| 2310 |
# |
| 2311 |
sub disp_info { |
| 2312 |
my $enc_name; |
| 2313 |
my ($artist, $album, %config, $revision); |
| 2314 |
my ($id, $trackno, $toc, $totaltime); |
| 2315 |
my @comment = (); |
| 2316 |
|
| 2317 |
if($rip == 1) { |
| 2318 |
CDDB_get->import( qw( get_cddb get_discids ) ); |
| 2319 |
my $cd = get_discids($scsi_cddev); |
| 2320 |
($id, $trackno, $toc) = ($cd->[0], $cd->[1], $cd->[2]); |
| 2321 |
$cddbid = sprintf("%08x", $id); |
| 2322 |
$totaltime = sprintf("%02d:%02d",$toc->[$trackno]->{min},$toc->[$trackno]->{sec}); |
| 2323 |
} |
| 2324 |
else { |
| 2325 |
if($cddbid) { |
| 2326 |
$trackno = $cddbid; |
| 2327 |
$trackno =~ s/.*(..)$/$1/; |
| 2328 |
$totaltime = substr($cddbid, 2, 4); |
| 2329 |
$totaltime = hex($totaltime); |
| 2330 |
} |
| 2331 |
} |
| 2332 |
|
| 2333 |
if(!defined $cd{title} && $cdtext == 1 && $rip == 1) { |
| 2334 |
get_cdtext; |
| 2335 |
} |
| 2336 |
|
| 2337 |
if(defined $cd{title}) { |
| 2338 |
$album = clean_all($cd{title}); |
| 2339 |
$artist = clean_all($cd{artist}); |
| 2340 |
# Remember: use of lowercase was supposed for file/dir names only, |
| 2341 |
# tags should not be lowercase (what for?). But option |
| 2342 |
# ucfirst is useful if DB entry is in uppercase only, and tags |
| 2343 |
# in uppercase are rather ugly. |
| 2344 |
$album = change_case($cd{title}, "t") if($uppercasefirst == 1); |
| 2345 |
$artist = change_case($cd{artist}, "t") if($uppercasefirst == 1); |
| 2346 |
$categ = $cd{cat}; |
| 2347 |
|
| 2348 |
# Set the year if it wasn't passed on command line. |
| 2349 |
unless($year) { |
| 2350 |
$year = $cd{year} if($cd{year}); |
| 2351 |
$year =~ s/[\015]//g if($year); |
| 2352 |
} |
| 2353 |
|
| 2354 |
# Set the genre if it wasn't passed on command line. |
| 2355 |
if(!defined $pgenre && defined $cd{genre}) { |
| 2356 |
$genre = $cd{genre}; |
| 2357 |
$genre =~ s/[\015]//g if($genre); |
| 2358 |
} |
| 2359 |
elsif(defined $pgenre && !defined $cd{genre}) { # New in 4.0 |
| 2360 |
$cd{genre} = $pgenre if($pgenre ne ""); |
| 2361 |
} |
| 2362 |
|
| 2363 |
@comment = extract_comm; |
| 2364 |
$revision = get_rev() unless($cd{discid}); |
| 2365 |
# In case of corrupted (local) DB files. |
| 2366 |
$revision = "unknown" unless($revision); |
| 2367 |
} |
| 2368 |
else { |
| 2369 |
if($submission == 0) { |
| 2370 |
print "\nNo CDDB info chosen or found for this CD\n" |
| 2371 |
if($verbose > 0); |
| 2372 |
} |
| 2373 |
# Set submission OK, will be set to 0 if default names are used. |
| 2374 |
$cddbsubmission = 1; |
| 2375 |
# Don't ask for default settings, use them ... |
| 2376 |
if($interaction == 0) { |
| 2377 |
create_deftrack(1); |
| 2378 |
} |
| 2379 |
# ... or ask whether 1) default or 2) manual entries shall be used |
| 2380 |
# or entered. |
| 2381 |
else { |
| 2382 |
create_deftrack(2); |
| 2383 |
} |
| 2384 |
$album = $cd{title}; |
| 2385 |
$artist = $cd{artist}; |
| 2386 |
$revision = $cd{revision}; |
| 2387 |
} |
| 2388 |
|
| 2389 |
if($cd{discid}) { |
| 2390 |
# We do nothing anymore because we read the data from a file. |
| 2391 |
} |
| 2392 |
else { |
| 2393 |
# The strings from archive files should be OK, because the files |
| 2394 |
# should be written in the corresponding encoding. Only strings |
| 2395 |
# from CDDB_get must be treated. |
| 2396 |
# But still, this gives the error: |
| 2397 |
# Cannot decode string with wide characters at |
| 2398 |
# /usr/lib/perl5/5.8.8/i586-linux-threads-multi/Encode.pm line 186. |
| 2399 |
# So do it here to be sure to analyze manually entered data! |
| 2400 |
# |
| 2401 |
# Create a string with the DB data to be analyzed for true UTF-8 |
| 2402 |
# (wide) characters. |
| 2403 |
my $char_string = $cd{title} . $cd{artist}; |
| 2404 |
$char_string .= $_ foreach (@{$cd{track}}); |
| 2405 |
$enc_name = check_encoding($char_string); |
| 2406 |
print "\n Encoding looks like $enc_name\n" if($verbose > 6); |
| 2407 |
Encode::from_to($artist, $enc_name, 'UTF-8') if($enc_name); |
| 2408 |
Encode::from_to($album, $enc_name, 'UTF-8') if($enc_name); |
| 2409 |
} |
| 2410 |
|
| 2411 |
|
| 2412 |
# Resetting the album and artist in the %cd-hash will screw up all the |
| 2413 |
# track titles (e.g. Bang Bang). Can you believe it? Change album and |
| 2414 |
# artist and track names will blow up. That's life, that's Perl. |
| 2415 |
# Again: we need a save copy of the string as it is now! What is wrong |
| 2416 |
# changing an entry of a hash? Why are all other entries of that |
| 2417 |
# hash screwed up? |
| 2418 |
|
| 2419 |
$album_utf8 = $album; |
| 2420 |
$artist_utf8 = $artist; |
| 2421 |
|
| 2422 |
my $genreno = ""; |
| 2423 |
unless($artist =~ /unknown.artist/i && $album =~ /unknown.album/i && $quitnodb == 1) { |
| 2424 |
if($genre eq "" && $interaction == 1 && $lameflag >= 0) { |
| 2425 |
print "\nPlease enter a valid ID3v2 genre (or none): "; |
| 2426 |
$genre = <STDIN>; |
| 2427 |
chomp $genre; |
| 2428 |
$cd{genre} = $genre; |
| 2429 |
} |
| 2430 |
if($genre) { |
| 2431 |
$genre =~ s/[\015]//g; |
| 2432 |
($genre,$genreno) = check_genre($genre); |
| 2433 |
} |
| 2434 |
} |
| 2435 |
if($verbose >= 1) { |
| 2436 |
print "\n", "-" x 17, "\nCDDB and tag Info", "\n", "-" x 17, "\n"; |
| 2437 |
print "Artist: $artist_utf8\n"; |
| 2438 |
print "Album: $album_utf8\n"; |
| 2439 |
print "Category: $categ\n" if($verbose >= 2); |
| 2440 |
if($genre && $genre ne "") { |
| 2441 |
print "ID3-Genre: $genre ($genreno)\n" if($lameflag >= 0); |
| 2442 |
print "Genre-tag: $genre\n" if($lameflag == -1); |
| 2443 |
if(lc($genre) ne lc($cd{genre})) { |
| 2444 |
print "CDDB-Genre: $cd{genre}\n"; |
| 2445 |
} |
| 2446 |
} |
| 2447 |
else{ |
| 2448 |
print "ID3-Genre: none\n"; |
| 2449 |
} |
| 2450 |
print "ASIN: $cd{asin}\n" if($cd{asin}); |
| 2451 |
print "ASIN-url: $cd{asinurl}\n" if($cd{asinurl}); |
| 2452 |
print "discogs: $cd{dgid}\n" if($cd{dgid}); |
| 2453 |
print "Barcode: $cd{barcode}\n" if($cd{barcode}); |
| 2454 |
print "Catalog: $cd{catalog}\n" if($cd{catalog}); |
| 2455 |
print "Language: $cd{language}\n" if($cd{language}); |
| 2456 |
print "Release date: $cd{reldate}\n" if($cd{reldate}); |
| 2457 |
print "Year: $year\n" if($year); |
| 2458 |
print "Revision: $revision\n" if($verbose >= 2); |
| 2459 |
# It happens, that the ID from CDDB is NOT identical to the ID |
| 2460 |
# calculated from the frames of the inserted CD... |
| 2461 |
if($rip == 1) { |
| 2462 |
if(defined $cd{id} && $cddbid ne $cd{id}) { |
| 2463 |
print "CDDB id: $cd{id}\n"; |
| 2464 |
} |
| 2465 |
} |
| 2466 |
print "CD ID: $cddbid\n"; |
| 2467 |
print "DiscID: $discid\n" if($discid); |
| 2468 |
print "MB ID: ", $cd{mbreid}, "\n" if($cd{mbreid}); |
| 2469 |
if(@comment && $verbose >= 2) { |
| 2470 |
foreach (@comment) { |
| 2471 |
print "Comment: $_\n" if($_); |
| 2472 |
} |
| 2473 |
} |
| 2474 |
print "CD length: $totaltime\n"; |
| 2475 |
print "CD number: $discno\n" if($discno > 0); |
| 2476 |
print "\n"; |
| 2477 |
} |
| 2478 |
log_info("\nArtist: $artist"); |
| 2479 |
log_info("Album: $album"); |
| 2480 |
log_info("ID3-Genre: $genre ($genreno)") if($genre); |
| 2481 |
log_info("ID3-Genre: none") unless($genre); |
| 2482 |
log_info("Category: $categ"); |
| 2483 |
log_info("ASIN: $cd{asin}") if($cd{asin}); |
| 2484 |
log_info("CD id: $cddbid"); |
| 2485 |
log_info("Disc id: $cd{discid}") |
| 2486 |
if($cd{discid} && $cd{discid} ne $cddbid); |
| 2487 |
log_info("MB rel id: $cd{mbreid}") if($cd{mbreid}); |
| 2488 |
log_info("CD length: $totaltime\n"); |
| 2489 |
log_info("CD number: $discno\n") if($discno > 0); |
| 2490 |
|
| 2491 |
# Read out pre-gap before calculating track lengths. |
| 2492 |
# Prevent double filled framelist arrays when sub read_entry |
| 2493 |
# already filled @framelist. |
| 2494 |
my $frameflag = 0; |
| 2495 |
$frameflag = 1 if($framelist[0]); |
| 2496 |
my $frames = 150; # The hard way if $rip == 0 (no disc to be read). |
| 2497 |
if($rip == 1) { |
| 2498 |
$frames = $toc->[0]->{'frames'}; |
| 2499 |
check_audio(); |
| 2500 |
} |
| 2501 |
push @framelist, "$frames" if($frameflag == 0); |
| 2502 |
if($frames > 400) { |
| 2503 |
my $second = int($frames/75); |
| 2504 |
my $frame = $frames - $second * 75; |
| 2505 |
my $minute = int($second/60); |
| 2506 |
$second -= $minute * 60; |
| 2507 |
printf("%s %02d:%02d %s %d %s\n", |
| 2508 |
"There might be a hidden track", $minute, $second, |
| 2509 |
"long,\nbecause offset of track 01 has", $frames, |
| 2510 |
"frames\nintstead of typically 150 (equals 2 seconds).\n") |
| 2511 |
if($verbose >= 1); |
| 2512 |
my $riptrackname = "Hidden Track"; |
| 2513 |
$riptrackname = change_case($riptrackname, "t"); |
| 2514 |
$riptrackname =~ s/ /_/g if($underscore == 1); |
| 2515 |
if("@audio" =~ /\*/ && $rip == 1) { |
| 2516 |
printf(" %s %02d: [%02d:%02d.%02d] %s\n", " ", |
| 2517 |
"00", $minute, $second, $frame, $riptrackname) |
| 2518 |
if($verbose > 1); |
| 2519 |
} |
| 2520 |
else { |
| 2521 |
printf("%s: [%02d:%02d.%02d] %s\n", |
| 2522 |
"00", $minute, $second, $frame, $riptrackname) |
| 2523 |
if($verbose >= 1); |
| 2524 |
} |
| 2525 |
$second = int($frames/75); |
| 2526 |
$hiddenflag = 1 if($trackselection eq "" |
| 2527 |
|| $trackselection =~ /^0/ |
| 2528 |
|| $trackselection =~ /\D0/ |
| 2529 |
|| $trackselection =~ /1-a/); |
| 2530 |
# We can't add this track to seltrack and framelist, because this |
| 2531 |
# would break (re-) submission of CDDB. |
| 2532 |
# Note: seltrack is not yet defined... But we start to fill the |
| 2533 |
# @secondlist array (yet empty) with track lengths in seconds. |
| 2534 |
# TODO: push the pre-gap seconds to the list in any case, then we |
| 2535 |
# don't need to differentiate between the case hiddenflag == 1 or |
| 2536 |
# hiddenflag == 0 while choosing track names. |
| 2537 |
push(@secondlist, "$second") if($hiddenflag == 1); |
| 2538 |
# No need to: unshift(@audio, ' '); |
| 2539 |
# here, printout has already been done for the hidden track... |
| 2540 |
} |
| 2541 |
# In case of $rip == 0 and archive entry found: |
| 2542 |
|
| 2543 |
# Print track information. |
| 2544 |
my $n = 1; |
| 2545 |
$n = 0 if($rip == 0 and $hiddenflag == 1); |
| 2546 |
foreach (@{$cd{track}}) { |
| 2547 |
$_ = clean_all($_); |
| 2548 |
$_ = change_case($_, "t") if($uppercasefirst == 1); |
| 2549 |
|
| 2550 |
# Print track in case of re-encoding only if track is present. |
| 2551 |
# If no flac present, @tracksel is not yet filled and we would |
| 2552 |
# miss all track names, track tags etc. |
| 2553 |
# TODO: should array @tracksel be filled in the sub get_cdid also |
| 2554 |
# if no flac are present? |
| 2555 |
my $nextflag = 0; |
| 2556 |
if($rip == 0 && defined $tracksel[0]) { |
| 2557 |
foreach my $num (@tracksel) { |
| 2558 |
$nextflag = 1 if($num == $n && $nextflag == 0); |
| 2559 |
$nextflag = 1 if($num == $n+1 && $nextflag == 0 && $hiddenflag == 1); |
| 2560 |
} |
| 2561 |
$n++ if($nextflag == 0); # Needed in case only a track 1 and e.g. a track 8 are present |
| 2562 |
next if($nextflag == 0); |
| 2563 |
} |
| 2564 |
|
| 2565 |
Encode::from_to($_, $enc_name, 'UTF-8') if($enc_name); |
| 2566 |
push(@tracktags, $_); |
| 2567 |
|
| 2568 |
# Get frames and total time. |
| 2569 |
my $frames = 0; |
| 2570 |
if($rip == 1) { |
| 2571 |
$frames = $toc->[$n]->{'frames'}; |
| 2572 |
} |
| 2573 |
else { |
| 2574 |
$frames = $secondlist[$n - 1] * 75 if($secondlist[$n - 1]); |
| 2575 |
$frames = $framelist[$n] unless($frames); |
| 2576 |
# In case $rip == 0 and no tag-update shall happen, array |
| 2577 |
# framelist only consists of the initialized value and |
| 2578 |
# consecutive tracks will have length -2 s... rather make them |
| 2579 |
# zero length. |
| 2580 |
$frames = 150 unless($frames); |
| 2581 |
} |
| 2582 |
push(@framelist, "$frames") if($frameflag == 0); |
| 2583 |
$frames = $frames - $framelist[$n - 1]; |
| 2584 |
my $second = int($frames / 75); |
| 2585 |
push(@secondlist, "$second") if($rip == 1); |
| 2586 |
my $frame = $frames - $second * 75; |
| 2587 |
$frame = 0 if($frame < 0); |
| 2588 |
my $minute = int($second / 60); |
| 2589 |
$second -= $minute * 60; |
| 2590 |
$_ = clean_chars($_) if($chars); |
| 2591 |
if("@audio" =~ /\*/ && $rip == 1) { |
| 2592 |
printf(" %s %02d: [%02d:%02d.%02d] %s\n", $audio[$n], |
| 2593 |
$n + $trackoffset, $minute, $second, $frame, $_) |
| 2594 |
if($verbose > 1); |
| 2595 |
} |
| 2596 |
else { |
| 2597 |
printf("%02d: [%02d:%02d.%02d] %s\n", |
| 2598 |
$n + $trackoffset, $minute, $second, $frame, $_) |
| 2599 |
if($verbose > 1); |
| 2600 |
} |
| 2601 |
$_ = clean_name($_); |
| 2602 |
$_ = change_case($_, "t"); |
| 2603 |
$_ =~ s/ /_/g if($underscore == 1); |
| 2604 |
# Why do we do this? We need an array @tracklist in case operator |
| 2605 |
# wants to alter the track-tags (and this implies the track-names |
| 2606 |
# in the encoder process) in sub create_deftrack. |
| 2607 |
# So, do this as before not only if $rip == 1. |
| 2608 |
push(@tracklist, $_); |
| 2609 |
$n++; |
| 2610 |
} |
| 2611 |
if("@audio" =~ /\*\s+\*/ && $rip == 1) { |
| 2612 |
print "\n * Detected data tracks (will be omitted in case ", |
| 2613 |
"trackselection is 1-a)." if($verbose > 1); |
| 2614 |
} |
| 2615 |
elsif("@audio" =~ /\*/ && $rip == 1) { |
| 2616 |
print "\n * Detected data track (will be omitted in case ", |
| 2617 |
"trackselection is 1-a)." if($verbose > 1); |
| 2618 |
} |
| 2619 |
print "\n\n" if($verbose >= 1); |
| 2620 |
|
| 2621 |
# Some more error checking. |
| 2622 |
if($artist eq "") { |
| 2623 |
die "Error: No artist found!\n"; |
| 2624 |
} |
| 2625 |
if(!defined $tracklist[0]) { |
| 2626 |
die "Error: No tracks found!\n" if($rip == 1); # New in 4.0 |
| 2627 |
} |
| 2628 |
|
| 2629 |
get_isrcs if($isrc == 1 && $mb == 1 && $rip == 1); |
| 2630 |
|
| 2631 |
# LCDproc |
| 2632 |
if($lcd == 1) { |
| 2633 |
$lcdline1 = $artist . "-" . $album; |
| 2634 |
$lcdline2 = "R00|00.0%|----------"; |
| 2635 |
$lcdline3 = "E00|00.0%|----------"; |
| 2636 |
ulcd(); |
| 2637 |
} |
| 2638 |
} |
| 2639 |
######################################################################## |
| 2640 |
# |
| 2641 |
# Create the track selection from the parameters passed on the command- |
| 2642 |
# line, i. e. create an array with all track numbers including those not |
| 2643 |
# explicitly stated at the command line. |
| 2644 |
# |
| 2645 |
sub create_seltrack { |
| 2646 |
if($rip == 0) { |
| 2647 |
# Check what is present, nothing more needs to be done, but |
| 2648 |
# sub check_va would respond even if all values tested are zero. |
| 2649 |
return; |
| 2650 |
} |
| 2651 |
else { |
| 2652 |
print "\nGot @_ as ARG.\n" if($verbose > 5 and "@_" ne ""); |
| 2653 |
} |
| 2654 |
my($tempstr, $intrack); |
| 2655 |
($tempstr) = @_; |
| 2656 |
if($_[0] eq "-") { |
| 2657 |
die "Invalid track selection \"-\"!\n\n"; |
| 2658 |
} |
| 2659 |
elsif($tempstr =~ /\d+-a/) { |
| 2660 |
my $first_tn = $tempstr; |
| 2661 |
$first_tn =~ s/\D*//g; |
| 2662 |
$tempstr = ""; |
| 2663 |
my $tcn = 0; |
| 2664 |
foreach (@audio) { |
| 2665 |
$tempstr .= "$tcn," if($_ ne "*" and $tcn >= $first_tn); |
| 2666 |
$tcn++; |
| 2667 |
} |
| 2668 |
$tempstr =~ s/,$//; |
| 2669 |
$tempstr =~ s/^0,//; |
| 2670 |
} |
| 2671 |
|
| 2672 |
if(($tempstr =~ /,/) || ($tempstr =~ /\-/)) { |
| 2673 |
my @intrack = split(/,/ , $tempstr); |
| 2674 |
# If last character is a , add an other item with a - |
| 2675 |
if($tempstr =~ /,$/) { |
| 2676 |
push @intrack, ($intrack[$#intrack]+1) . "-"; |
| 2677 |
} |
| 2678 |
foreach $intrack (@intrack) { |
| 2679 |
if($intrack =~ /\-/) { |
| 2680 |
my @outrack = split(/-/ , $intrack); |
| 2681 |
# If last character is a -, add last track to $outrack |
| 2682 |
if($#outrack == 0) { |
| 2683 |
$outrack[1] = $#tracklist + 1; |
| 2684 |
if($outrack[0] > ($#tracklist + 1)) { |
| 2685 |
die "Track selection higher than number of tracks ", |
| 2686 |
"on CD.\n\n"; |
| 2687 |
} |
| 2688 |
} |
| 2689 |
for(my $i = $outrack[0]; $i <= $outrack[1]; $i++) { |
| 2690 |
push(@seltrack, $i); |
| 2691 |
} |
| 2692 |
} |
| 2693 |
else { |
| 2694 |
push(@seltrack, $intrack); |
| 2695 |
} |
| 2696 |
} |
| 2697 |
} |
| 2698 |
elsif($tempstr eq '') { |
| 2699 |
for(my $i = 1; $i <= ($#tracklist + 1); $i++) { |
| 2700 |
$seltrack[$i - 1] = $i; |
| 2701 |
} |
| 2702 |
} |
| 2703 |
elsif($tempstr =~ /^[0-9]*[0-9]$/) { |
| 2704 |
$seltrack[0] = $tempstr; |
| 2705 |
} |
| 2706 |
else { |
| 2707 |
die "Track selection invalid!\n"; |
| 2708 |
} |
| 2709 |
|
| 2710 |
@seltrack = sort {$a <=> $b} @seltrack; |
| 2711 |
|
| 2712 |
# Check the validity of the track selection. |
| 2713 |
foreach (@seltrack) { |
| 2714 |
if($_ > ($#tracklist + 1)) { |
| 2715 |
die "Track selection higher than number of tracks on CD.\n\n"; |
| 2716 |
} |
| 2717 |
elsif($_ == 0) { |
| 2718 |
shift @seltrack; |
| 2719 |
} |
| 2720 |
} |
| 2721 |
return; |
| 2722 |
} |
| 2723 |
######################################################################## |
| 2724 |
# |
| 2725 |
# Ask if CDDB submission shall be done. Either because one might change |
| 2726 |
# some settings a last time before writing to directories and files (if |
| 2727 |
# there was no DB entry and operator entered all by hand) or because |
| 2728 |
# DB entry had some typos! Also x-check for VA-style and let operator |
| 2729 |
# change settings according to meta data retrieved (in case interaction |
| 2730 |
# is on) and finally submit ISRCs to MusicBrainz if login info available |
| 2731 |
# and the ISRCs are OK. |
| 2732 |
# |
| 2733 |
sub ask_subm { |
| 2734 |
my $index = 2; |
| 2735 |
my $save_archive = $archive; |
| 2736 |
unless($cddbsubmission == 0 || $interaction == 0) { |
| 2737 |
while($index !~ /^[0-1]$/) { |
| 2738 |
print "\nDo you want to edit or submit the CDDB entry?"; |
| 2739 |
print "\nTo confirm each question type Enter.\n\n"; |
| 2740 |
print "1: Yes, and I know about the naming-rules of "; |
| 2741 |
print "freedb.org!\n\n"; |
| 2742 |
print "0: No\n\nChoose [0-1]: (0) "; |
| 2743 |
$index = <STDIN>; |
| 2744 |
chomp $index; |
| 2745 |
if($index eq "") { |
| 2746 |
$index = 0; |
| 2747 |
} |
| 2748 |
print "\n"; |
| 2749 |
} |
| 2750 |
if($index == 1) { |
| 2751 |
my $revision = get_rev() unless($cd{discid}); |
| 2752 |
if($revision) { |
| 2753 |
print "\nPlease change some settings."; |
| 2754 |
print "\nYou may confirm CDDB settings with \"enter\".\n"; |
| 2755 |
create_deftrack(0); |
| 2756 |
} |
| 2757 |
else { |
| 2758 |
print "\nPlease change some settings."; |
| 2759 |
print "\nYou may confirm given settings with \"enter\".\n"; |
| 2760 |
create_deftrack(0); |
| 2761 |
} |
| 2762 |
} |
| 2763 |
elsif($index == 0) { |
| 2764 |
# |
| 2765 |
# CDDB data does not get modified, write the existing data to |
| 2766 |
# the local CDDB if wanted. |
| 2767 |
if($archive == 1 && defined $cd{title}) { |
| 2768 |
write_cddb(); |
| 2769 |
} |
| 2770 |
} |
| 2771 |
else { |
| 2772 |
print "Choose 0 or 1!\n"; |
| 2773 |
} |
| 2774 |
} |
| 2775 |
if($index == 1) { |
| 2776 |
pre_subm(); |
| 2777 |
} |
| 2778 |
elsif($archive == 1 && defined $cd{title} && $mb == 1 && $index == 2) { |
| 2779 |
write_cddb(); |
| 2780 |
} |
| 2781 |
$archive = $save_archive; |
| 2782 |
# Once the meta data has been altered (optionally), check for |
| 2783 |
# VA style. |
| 2784 |
# Delimiters to be checked for various artists style. |
| 2785 |
my $delim_colon = 0; |
| 2786 |
my $delim_hyphen = 0; |
| 2787 |
my $delim_slash = 0; |
| 2788 |
my $delim_parenthesis = 0; |
| 2789 |
my $n = 0; |
| 2790 |
if($vatag > 0) { |
| 2791 |
# We call check_va only to print detected results if verbosity is |
| 2792 |
# switched on. |
| 2793 |
my $trackno = $#tracklist + 1; |
| 2794 |
my ($delim, $delim_cn) = check_va(1); |
| 2795 |
$delim_cn = 0 unless(defined $delim_cn); |
| 2796 |
unless($artist_utf8 =~ /unknown.artist/i && $album_utf8 =~ /unknown.album/i && $quitnodb == 1) { |
| 2797 |
if($interaction == 1) { |
| 2798 |
$index = 9; |
| 2799 |
while($index !~ /^[0-8]$/) { |
| 2800 |
print "\nDelimiter $delim found on $delim_cn of ", |
| 2801 |
"$trackno tracks." if(defined $delim and $delim_cn > 0); |
| 2802 |
print "\nAll tracks have a delimiter: suggestion: use 1 ", |
| 2803 |
"(2) or 5 (6)." if(defined $delim && defined $delim_cn && $delim_cn > 0 && $delim_cn >= $trackno); |
| 2804 |
print "\nOnly some tracks have a delimiter: suggestion: ", |
| 2805 |
"use 3 (4) or 7 (8)." if($delim_cn > 0 && $delim_cn < $trackno); |
| 2806 |
print "\nDo you want to change option --vatag to alter ", |
| 2807 |
"detection of compilation style?", |
| 2808 |
"\n\nChoose [0-8]: ($vatag) "; |
| 2809 |
$index = <STDIN>; |
| 2810 |
chomp $index; |
| 2811 |
if($index eq "") { |
| 2812 |
$index = $vatag; |
| 2813 |
} |
| 2814 |
print "\n"; |
| 2815 |
$vatag = $index if($index =~ /[0-8]/); |
| 2816 |
} |
| 2817 |
} |
| 2818 |
} |
| 2819 |
} |
| 2820 |
return; |
| 2821 |
} |
| 2822 |
######################################################################## |
| 2823 |
# |
| 2824 |
# Create the directory where the sound files shall go. |
| 2825 |
# Directory created will be: /outputdir/$dirtemplate[$c] . |
| 2826 |
# We first check the wavdir and set the counter $c for the encoder |
| 2827 |
# depending arrays @sepdir, @suffix, @globopt to -1. In this way, |
| 2828 |
# directory names will not be suffixed with a counter if they shall be |
| 2829 |
# the same for wavs and encoded files (condition $soundir ne $wavdir and |
| 2830 |
# the exception handling below). |
| 2831 |
# |
| 2832 |
sub create_dirs { |
| 2833 |
my $c = -1; |
| 2834 |
my $save_overwrite = $overwrite; |
| 2835 |
|
| 2836 |
# Get cddbid and number of tracks of CD, needed e.g. with option |
| 2837 |
# --precmd. |
| 2838 |
my $trackno; |
| 2839 |
if($rip == 1) { |
| 2840 |
($cddbid, $trackno) = get_cddbid(); |
| 2841 |
} |
| 2842 |
else { |
| 2843 |
if($cddbid ne "") { |
| 2844 |
$trackno = substr($cddbid, 6); |
| 2845 |
$trackno = hex($trackno); |
| 2846 |
} |
| 2847 |
else { |
| 2848 |
$trackno = $tracklist[$#tracklist]; |
| 2849 |
} |
| 2850 |
} |
| 2851 |
|
| 2852 |
foreach("wav", @coder) { |
| 2853 |
my $suffix = $suffix[$c] if(defined $suffix[$c]); |
| 2854 |
$suffix = "wav" if($_ eq "wav"); |
| 2855 |
my $quality = $globopt[$c] if(defined $globopt[$c]); |
| 2856 |
$quality = "" if($_ eq "wav"); |
| 2857 |
|
| 2858 |
# Why this? Remember, we have worked a lot with encoding of artist |
| 2859 |
# and album names! |
| 2860 |
my $album = clean_all($album_utf8); |
| 2861 |
my $artist = clean_all($artist_utf8); |
| 2862 |
$album = clean_name($album); |
| 2863 |
$artist = clean_name($artist); |
| 2864 |
$album = clean_chars($album) if($chars); |
| 2865 |
$artist = clean_chars($artist) if($chars); |
| 2866 |
$artist = change_case($artist, "d"); |
| 2867 |
$album = change_case($album, "d"); |
| 2868 |
$album =~ s/ /_/g if($underscore == 1); |
| 2869 |
$artist =~ s/ /_/g if($underscore == 1); |
| 2870 |
|
| 2871 |
# Define variable for initial letter of artist. |
| 2872 |
my $iletter = $artist; |
| 2873 |
$iletter =~ s/\s*(.).*/$1/; |
| 2874 |
if($iletter =~ /\d/) { |
| 2875 |
my @words = split(/ /, $artist); |
| 2876 |
shift(@words); |
| 2877 |
foreach (@words) { |
| 2878 |
$iletter = $_; |
| 2879 |
$iletter =~ s/\s*(.).*/$1/; |
| 2880 |
last if($iletter =~ /\w{1}/); |
| 2881 |
} |
| 2882 |
} |
| 2883 |
$iletter = "A" unless($iletter); |
| 2884 |
$iletter = "\u$iletter" unless($lowercase == 1 or $lowercase == 3); |
| 2885 |
|
| 2886 |
# Take the last dirtemplate for missing ones and for wav. |
| 2887 |
my $dirindex = $c; |
| 2888 |
if($suffix eq "wav") { |
| 2889 |
$dirindex = $#dirtemplate; |
| 2890 |
} |
| 2891 |
elsif($c > $#dirtemplate) { |
| 2892 |
$dirindex = $#dirtemplate; |
| 2893 |
} |
| 2894 |
|
| 2895 |
# Check and create the full path where the files will go. |
| 2896 |
# Check the dirtemplate and use the actual year as default if |
| 2897 |
# $year is in the template and none is given! |
| 2898 |
if(($dirtemplate[$dirindex] =~ /\$year/ or |
| 2899 |
$tracktemplate =~ /\$year/) && !$year) { |
| 2900 |
$year = sprintf("%04d", sub {$_[5]+1900}->(localtime)); |
| 2901 |
} |
| 2902 |
# Do the same for the genre. |
| 2903 |
if(($dirtemplate[$dirindex] =~ /\$genre/ or |
| 2904 |
$tracktemplate =~ /\$genre/)) { |
| 2905 |
$genre = "Other" if($genre eq ""); |
| 2906 |
chomp $genre; |
| 2907 |
} |
| 2908 |
|
| 2909 |
my $dir; |
| 2910 |
if(!eval("\$dir = $dirtemplate[$dirindex]")) { |
| 2911 |
die "Directory template incorrect, caused eval to fail: $!\n"; |
| 2912 |
} |
| 2913 |
$dir =~ s,\s-\s/,/,g; # Do this in any case, even if all chars are |
| 2914 |
$dir =~ s,\s-\s$,,g; # allowed. |
| 2915 |
$dir =~ s,\s+/,/,g; # Do this in any case, even if all chars are |
| 2916 |
$dir =~ s,\s+, ,g; # allowed. |
| 2917 |
$dir =~ s,\s-\s-\s*, ,g; |
| 2918 |
# Change case again only if lowercase wanted! Else we will get |
| 2919 |
# lower case of special dirtemplates like: $iletter/$artist: here |
| 2920 |
# artist would be converted to lowercase, since we check for words! |
| 2921 |
$dir = change_case($dir, "t") if($lowercase == 1 or $lowercase == 3); |
| 2922 |
$dir = clean_chars($dir) if($chars); |
| 2923 |
$dir =~ s/ /_/g if($underscore == 1); |
| 2924 |
|
| 2925 |
$dir =~ s/\.+$// if($chars =~ /NTFS/); |
| 2926 |
$dir =~ s/^\///; |
| 2927 |
my $soundir = $outputdir . "/" . $dir if($outputdir !~ /\/$/); |
| 2928 |
$soundir = $outputdir . $dir if($outputdir =~ /\/$/); |
| 2929 |
# Check if the soundir already exists, if it does, try "soundir i" |
| 2930 |
# with i an integer until it works, unless option resume is given. |
| 2931 |
# |
| 2932 |
# TODO: What if two identical named discs shall be done, but with |
| 2933 |
# different number of tracks (different track names will be too |
| 2934 |
# difficult to distinguish!)? Maybe we should test here the number |
| 2935 |
# of tracks in an existing directory with same name... |
| 2936 |
# E.g. Nouvelle Vague: Bande à part, EU version, US version, |
| 2937 |
# LTD. Ed, initial release version... all have the same name but |
| 2938 |
# different track names/numbers. |
| 2939 |
# |
| 2940 |
my $cdexistflag = 0; |
| 2941 |
my $i = 1; |
| 2942 |
my $nsoundir = $soundir; |
| 2943 |
my $sfx = ""; |
| 2944 |
while(defined(opendir(TESTDIR, $nsoundir)) && |
| 2945 |
# $rip == 1 && # No overwriteing while re-encoding. |
| 2946 |
$resume == 0 && $soundir ne $wavdir) { |
| 2947 |
$sfx = " " . $i if($underscore == 0); |
| 2948 |
$sfx = "_" . $i if($underscore == 1); |
| 2949 |
$sfx = clean_chars($sfx) if($chars); |
| 2950 |
$nsoundir = $soundir . $sfx; |
| 2951 |
$i++; |
| 2952 |
$cdexistflag = 1; |
| 2953 |
} |
| 2954 |
# In case a multi-disc release is ripped using trackoffset it |
| 2955 |
# would be nice to rip to the existing directories, but how to |
| 2956 |
# detect if those tracks have already been ripped? |
| 2957 |
# Note that operator could have first ripped the n-th disc and |
| 2958 |
# the first disc is the last one to be added to the directory, so |
| 2959 |
# it would not be a good idea to say that the n-th track number |
| 2960 |
# should not exist. |
| 2961 |
if($addtrackoffset == 1 && $overwrite ne "y" ) { |
| 2962 |
my $riptracktag = $tracktags[0]; |
| 2963 |
$riptracktag = $tracktags[1] if($hiddenflag == 1); |
| 2964 |
my $artistag; |
| 2965 |
my ($delimiter, $dummy) = check_va(0) if($vatag > 0); |
| 2966 |
my $delim = quotemeta($delimiter) if(defined $delimiter); |
| 2967 |
$vatag = 0 if(!defined $delim or $delim eq ""); |
| 2968 |
|
| 2969 |
# Split the tracktag into its artist part and track part if |
| 2970 |
# VA style is used. |
| 2971 |
if(defined $delim && $va_flag > 0 && $riptracktag =~ /$delim/) { |
| 2972 |
($artistag, $riptracktag) = split_tags($riptracktag, $delim); |
| 2973 |
} |
| 2974 |
$artistag = clean_all($artist_utf8) unless(defined $artistag); |
| 2975 |
my $trackartist = clean_all($artistag); |
| 2976 |
$trackartist = clean_name($trackartist); |
| 2977 |
$trackartist = clean_chars($trackartist); |
| 2978 |
my $tracktitle = clean_all($riptracktag); |
| 2979 |
$tracktitle = clean_name($tracktitle); |
| 2980 |
$tracktitle = clean_chars($tracktitle); |
| 2981 |
$trackartist =~ s/ /_/g if($underscore == 1); |
| 2982 |
$tracktitle =~ s/ /_/g if($underscore == 1); |
| 2983 |
my $riptrackname = get_trackname(1, $tracklist[0], 0, $trackartist, $tracktitle); |
| 2984 |
$riptrackname = get_trackname(0, $tracklist[1], 0, $trackartist, $tracktitle) |
| 2985 |
if($hiddenflag == 1); |
| 2986 |
$riptrackname = $album if($book == 1 or $cdcue == 2); |
| 2987 |
$cdexistflag = 0; |
| 2988 |
# Note that the "original" $soundir (existing) is tested here |
| 2989 |
# and not the new $nsoundir with suffix (not yet existing). |
| 2990 |
$cdexistflag = 1 if(-f "$soundir/$riptrackname.$suffix"); |
| 2991 |
$overwrite = "y" if($cdexistflag == 0); |
| 2992 |
} |
| 2993 |
return "next" if($cdexistflag == 1 && $overwrite =~ /^e|q$/); |
| 2994 |
return "unknown" if($artist =~ /unknown.artist/i && $album =~ /unknown.album/i && $quitnodb == 1); |
| 2995 |
|
| 2996 |
$nsoundir = $soundir if($overwrite eq "y"); |
| 2997 |
# Exception handling: if the $wavdir is identical to the |
| 2998 |
# $nsoundir apart from a suffixed counter, use the $wavdir as |
| 2999 |
# $soundir instead of the incremented $nsoundir! |
| 3000 |
esc_char($soundir, 0); |
| 3001 |
my $qwavdir = $wavdir; |
| 3002 |
my $qsoundir = $soundir; |
| 3003 |
$qwavdir =~ s/\|/\\|/g; |
| 3004 |
$qsoundir =~ s/\|/\\|/g; |
| 3005 |
$nsoundir = $wavdir if($qwavdir =~ /$qsoundir.\d+/); |
| 3006 |
|
| 3007 |
if($multi == 1 && $_ eq "wav") { |
| 3008 |
if($overwrite =~ /^y$/) { |
| 3009 |
$cdexistflag = 0; |
| 3010 |
$sfx = ""; |
| 3011 |
# Delete existing error.log file to prevent ripping of |
| 3012 |
# more than one slot at once. |
| 3013 |
if(-f "$wavdir/error.log") { |
| 3014 |
unlink("$wavdir/error.log"); |
| 3015 |
} |
| 3016 |
} |
| 3017 |
my $aadir = $dir . $sfx; |
| 3018 |
if($cdexistflag == 1) { |
| 3019 |
$i--; |
| 3020 |
open(SRXY,"$logfile") or |
| 3021 |
print "Can not open \"$logfile\"!\n"; |
| 3022 |
my @srxylines = <SRXY>; |
| 3023 |
close(SRXY); |
| 3024 |
chomp(my $orig_album = join(' ', grep(/^album:\s/, @srxylines))); |
| 3025 |
grep(s/^album:\s(.*)$/album: $1 $i/, @srxylines) |
| 3026 |
if($underscore == 0); |
| 3027 |
grep(s/^album:\s(.*)$/album: $1_$i/, @srxylines) |
| 3028 |
if($underscore == 1); |
| 3029 |
open(SRXY,">$logfile") |
| 3030 |
or print "Can not write to file \"$logfile\"!\n"; |
| 3031 |
print SRXY @srxylines; |
| 3032 |
print SRXY "Original-$orig_album\n"; |
| 3033 |
close(SRXY); |
| 3034 |
} |
| 3035 |
log_system("cp \"$logfile\" \"$soundir/$dir.db\""); |
| 3036 |
open(SRXY,">>$logfile") |
| 3037 |
or print "Can not append to file \"$logfile\"!\n"; |
| 3038 |
print SRXY "\n\nArtist - Album:$aadir"; |
| 3039 |
close(SRXY); |
| 3040 |
} |
| 3041 |
$soundir = $nsoundir; |
| 3042 |
$soundir =~ s;/$;;g; |
| 3043 |
$overwrite = $save_overwrite; |
| 3044 |
|
| 3045 |
# Problem: multi level directory creation should set permission to |
| 3046 |
# each directory level. I thought the easiest way would be to |
| 3047 |
# alter permissions using umask and then set it back. I did not |
| 3048 |
# succeed. |
| 3049 |
# |
| 3050 |
# Save machines umask for reset. |
| 3051 |
my $umask = umask(); |
| 3052 |
|
| 3053 |
# Get the default permission mode. |
| 3054 |
my $dperm = sprintf("%04o", 0777 & ~umask()); |
| 3055 |
|
| 3056 |
# Do not create the wav directory in case rip (Morituri) is used, |
| 3057 |
# else Morituri will give up on existing directories. |
| 3058 |
if($suffix eq "wav" && $ripper == 3) { |
| 3059 |
print "\nNo wav directory created when using Morituri, the ", |
| 3060 |
"ripper will take care of it.\n" if($verbose > 3); |
| 3061 |
} |
| 3062 |
elsif(!opendir(TESTDIR, $soundir)) { |
| 3063 |
# Explicitly log soundir creation. |
| 3064 |
log_info("new-mediadir: $soundir"); |
| 3065 |
|
| 3066 |
# The so called Holzhacker-Method: create dir level by level. |
| 3067 |
# TODO: Let me know the good way to do it, thanks. |
| 3068 |
my $growing_dir = ""; |
| 3069 |
foreach (split(/\//, $soundir)) { |
| 3070 |
next if($_ eq " "); |
| 3071 |
# Should we allow relative paths? |
| 3072 |
if($_ =~ /^\.{1,2}$/ && $growing_dir eq "") { |
| 3073 |
$growing_dir .= "$_"; |
| 3074 |
} |
| 3075 |
else { |
| 3076 |
$growing_dir .= "/$_"; |
| 3077 |
} |
| 3078 |
$growing_dir =~ s;//;/;g; |
| 3079 |
if(!opendir(TESTDIR, $growing_dir)) { |
| 3080 |
log_system("mkdir -m $dpermission -p \"$growing_dir\""); |
| 3081 |
if(! -d "$growing_dir") { |
| 3082 |
print "\nWill try to trim length of directory.\n" |
| 3083 |
if($verbose > 4); |
| 3084 |
while(length($_) > 250) { |
| 3085 |
chop; |
| 3086 |
chop($growing_dir); |
| 3087 |
} |
| 3088 |
log_system("mkdir -m $dpermission -p \"$growing_dir\"") |
| 3089 |
or die "Can not create directory $growing_dir: $!\n"; |
| 3090 |
$limit_flag = 255; |
| 3091 |
} |
| 3092 |
} |
| 3093 |
} |
| 3094 |
# In case $growing_dir needed to be shorten. |
| 3095 |
$soundir = $growing_dir; |
| 3096 |
# Do it again for security reasons. |
| 3097 |
log_system("mkdir -m $dpermission -p \"$soundir\"") |
| 3098 |
or die "Can not create directory $soundir: $!\n"; |
| 3099 |
# What if strange chars appear like backslash? |
| 3100 |
# Can the created dir be accessed with $sounddir? |
| 3101 |
if(!defined(opendir(SND, "$soundir"))) { |
| 3102 |
print "Can not read in $soundir: $!\n"; |
| 3103 |
exit; |
| 3104 |
} |
| 3105 |
close(SND); |
| 3106 |
} |
| 3107 |
else { |
| 3108 |
closedir(TESTDIR); |
| 3109 |
} |
| 3110 |
# Reset umask |
| 3111 |
#umask($umask) if defined $umask; |
| 3112 |
$sepdir[$c] = $soundir unless($_ eq "wav"); |
| 3113 |
$wavdir = $soundir if($_ eq "wav"); |
| 3114 |
$c++; |
| 3115 |
|
| 3116 |
# New in 4.0 |
| 3117 |
del_wav if($overwrite =~ /^y$/ && $suffix eq "wav" && $rip == 1); |
| 3118 |
# This might not be the best place to set up the pre- and exe- |
| 3119 |
# command and the coverpath but this is where most variables are |
| 3120 |
# available. The same goes for the copycover variable. |
| 3121 |
if($execmd && $suffix eq "wav") { |
| 3122 |
my $exec; |
| 3123 |
if(!eval("\$exec = $execmd")) { |
| 3124 |
print "execmd incorrect, caused eval to fail: $!\n"; |
| 3125 |
} |
| 3126 |
$execmd = esc_char($exec, 1); |
| 3127 |
} |
| 3128 |
if($precmd && $suffix eq "wav") { |
| 3129 |
my $prec; |
| 3130 |
print "\nEvaluating $precmd.\n" if($verbose > 4); |
| 3131 |
if(!eval("\$prec = $precmd")) { |
| 3132 |
print "precmd <$prec> incorrect, caused eval to fail: $!\n"; |
| 3133 |
} |
| 3134 |
$precmd = esc_char($prec, 1); |
| 3135 |
} |
| 3136 |
# Test the coverart only once, use suffix wav to prevent repeated |
| 3137 |
# checks. This will be omitted in case rip (Morituri) is used. |
| 3138 |
if($coverpath && $suffix eq "wav") { |
| 3139 |
if($coverpath =~ /\$/) { |
| 3140 |
my $covp; |
| 3141 |
if(!eval("\$covp = $coverpath")) { |
| 3142 |
print "coverpath incorrect, caused eval to fail: $!\n"; |
| 3143 |
} |
| 3144 |
$coverpath = $covp; |
| 3145 |
} |
| 3146 |
else { |
| 3147 |
print "No further checks to be done on coverpath $coverpath.\n" |
| 3148 |
if($verbose > 4); |
| 3149 |
} |
| 3150 |
} |
| 3151 |
if($copycover && $suffix eq "wav") { |
| 3152 |
if($copycover =~ /\$/) { |
| 3153 |
my $copy; |
| 3154 |
if(!eval("\$copy = $copycover")) { |
| 3155 |
print "copycover path incorrect, caused eval to fail: $!\n"; |
| 3156 |
} |
| 3157 |
$copycover = $copy; |
| 3158 |
} |
| 3159 |
else { |
| 3160 |
print "No further checks to be done on copycover $copycover.\n" |
| 3161 |
if($verbose > 4); |
| 3162 |
} |
| 3163 |
} |
| 3164 |
# Reset suffix: |
| 3165 |
$suffix = ""; |
| 3166 |
} |
| 3167 |
return("go"); |
| 3168 |
} |
| 3169 |
######################################################################## |
| 3170 |
# |
| 3171 |
# Create the full-path track file name from the tracktemplate variable. |
| 3172 |
# |
| 3173 |
sub get_trackname { |
| 3174 |
my($trnum, $trname, $riptrname, $shortflag, $trackartist, $tracktitle); |
| 3175 |
|
| 3176 |
($trnum, $trname, $shortflag, $trackartist, $tracktitle) = @_; |
| 3177 |
$shortflag = 0 unless($shortflag); |
| 3178 |
|
| 3179 |
my $album = clean_all($album_utf8); |
| 3180 |
my $artist = clean_all($artist_utf8); |
| 3181 |
$album = clean_name($album); |
| 3182 |
$artist = clean_name($artist); |
| 3183 |
$album = clean_chars($album) if($chars); |
| 3184 |
$artist = clean_chars($artist) if($chars); |
| 3185 |
$album =~ s/ /_/g if($underscore == 1); |
| 3186 |
$artist =~ s/ /_/g if($underscore == 1); |
| 3187 |
|
| 3188 |
# Fill VA parameters in case they're empty, does not hurt if not |
| 3189 |
# needed at all. Switched condition in 4.0. |
| 3190 |
$trackartist = $artist unless(defined $trackartist && $trackartist ne ""); |
| 3191 |
$tracktitle = $trname unless(defined $tracktitle && $tracktitle ne ""); |
| 3192 |
|
| 3193 |
# Create the full file name from the track template, unless |
| 3194 |
# the disk is unknown. |
| 3195 |
if($trname =~ /short/ && $shortflag =~ /short/) { |
| 3196 |
$riptrname = $trname; |
| 3197 |
} |
| 3198 |
elsif(defined $cd{title}) { |
| 3199 |
# We do not need to lowercase the track template because all |
| 3200 |
# variables are already lowercase! |
| 3201 |
$tracktemplate =~ s/ /\\_/g if($underscore == 1); |
| 3202 |
# We have to update tracknum and track name because they're |
| 3203 |
# evaluated by the track template! |
| 3204 |
my $tracknum = sprintf("%02d", $trnum + $trackoffset); |
| 3205 |
my $trackname = $trname; |
| 3206 |
if(!eval("\$riptrname = $tracktemplate")) { |
| 3207 |
die "\nTrack Template incorrect, caused eval to fail: $!.\n"; |
| 3208 |
} |
| 3209 |
} |
| 3210 |
else { |
| 3211 |
$trname = change_case($trname, "t"); |
| 3212 |
$trname =~ s/ /_/g if($underscore == 1); |
| 3213 |
$riptrname = $trname; |
| 3214 |
} |
| 3215 |
|
| 3216 |
if($limit_flag == 255) { |
| 3217 |
$riptrname = substr($riptrname, 0, 250); |
| 3218 |
} |
| 3219 |
|
| 3220 |
# No counters if option book or cdcue is used: |
| 3221 |
if($book == 1 or $cdcue > 0) { |
| 3222 |
$riptrname =~ s/^\d+[\s|_]// if($tracktemplate =~ /^\$tracknum/); |
| 3223 |
} |
| 3224 |
return $riptrname; |
| 3225 |
} |
| 3226 |
######################################################################## |
| 3227 |
# |
| 3228 |
# Rip the CD. |
| 3229 |
# |
| 3230 |
sub rip_cd { |
| 3231 |
my($ripcom, $riptrackname, $riptracktag); |
| 3232 |
my $startenc = 0; |
| 3233 |
my $failflag = 0; |
| 3234 |
my $resumerip = $resume; |
| 3235 |
my $trackstart = 0; |
| 3236 |
my $cue_point = 0; |
| 3237 |
# Cleaning. |
| 3238 |
my $albumtag = clean_all($album_utf8); |
| 3239 |
my $artistag = clean_all($artist_utf8); |
| 3240 |
my $album = $albumtag; |
| 3241 |
$album = clean_name($album); |
| 3242 |
my $artist = $artistag; |
| 3243 |
$artist = clean_name($artist); |
| 3244 |
$album = clean_chars($album) if($chars); |
| 3245 |
$artist = clean_chars($artist) if($chars); |
| 3246 |
$album =~ s/ /_/g if($underscore == 1); |
| 3247 |
$artist =~ s/ /_/g if($underscore == 1); |
| 3248 |
# New parameters for tracktemplate used for file names only, i.e. |
| 3249 |
# less verbose than the corresponding tags $artistag and tracktag. |
| 3250 |
my $trackartist; |
| 3251 |
my $tracktitle; |
| 3252 |
|
| 3253 |
# Delete existing md5 files in case of resuming. |
| 3254 |
if($md5sum == 1 && $resume == 1) { |
| 3255 |
if($wav == 1) { |
| 3256 |
my @paths = split(/\//, $wavdir); |
| 3257 |
my $md5file = $paths[$#paths] . " - wav" . ".md5"; |
| 3258 |
$md5file =~ s/ /_/g if($underscore == 1); |
| 3259 |
unlink("$wavdir/$md5file"); |
| 3260 |
} |
| 3261 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 3262 |
my @paths = split(/\//, $sepdir[$c]); |
| 3263 |
my $md5file = $paths[$#paths] . " - " . $suffix[$c] . ".md5"; |
| 3264 |
$md5file =~ s/ /_/g if($underscore == 1); |
| 3265 |
unlink("$sepdir[$c]/$md5file"); |
| 3266 |
} |
| 3267 |
} |
| 3268 |
|
| 3269 |
# Delete machine.lock files. |
| 3270 |
if($resume == 1) { |
| 3271 |
opendir (DIR, "$wavdir") or print "Can't open $wavdir $!\n"; |
| 3272 |
my @lockfiles = grep(/\.lock_\d+$/, readdir(DIR)); |
| 3273 |
@lockfiles = grep(/\.lock$/, readdir(DIR)) unless($lockfiles[0]); |
| 3274 |
closedir(DIR); |
| 3275 |
unlink("$wavdir/$_") foreach(@lockfiles); |
| 3276 |
} |
| 3277 |
|
| 3278 |
# Delete existing ghost.log file unless we're resuming. Nevertheless |
| 3279 |
# this might lead to corrupted content if $resume == 1. |
| 3280 |
if(-r "$wavdir/ghost.log" && $resume == 0) { |
| 3281 |
unlink("$wavdir/ghost.log"); |
| 3282 |
} |
| 3283 |
|
| 3284 |
# Get delimiter for VA style. |
| 3285 |
# We need it here only in case merge is used. |
| 3286 |
# No messages to be printed. |
| 3287 |
my ($delimiter, $dummy) = check_va(0) if($vatag > 0); |
| 3288 |
my $delim = quotemeta($delimiter) if(defined $delimiter); |
| 3289 |
$vatag = 0 if(!defined $delim or $delim eq ""); |
| 3290 |
# Define an array with intervals and the tracks to be skipped. |
| 3291 |
# First clean-up array @framelist, may contain strange characters |
| 3292 |
# appearing when printed values get screwed up. |
| 3293 |
if($book == 1 || $cdcue == 2) { |
| 3294 |
# The array of tracks to skipped needs to be filled somewhere, but |
| 3295 |
# not too early (failure if no track numbers exist) and not too |
| 3296 |
# late too. So somewhere in between. |
| 3297 |
my @dummy = skip_tracks(1) if($pmerge); |
| 3298 |
} |
| 3299 |
s/\D//g foreach(@framelist); |
| 3300 |
my @merge = (); |
| 3301 |
my @skip = (); |
| 3302 |
# If merge is used, we need to calculate the true track length for |
| 3303 |
# the chaptermark and playlist file. An copy of the original values |
| 3304 |
# is needed. |
| 3305 |
@framelist_orig = @framelist; |
| 3306 |
if($pmerge) { |
| 3307 |
# If hidden track supposed, try to merge it too in case operator |
| 3308 |
# wants a book or a cdcue. |
| 3309 |
$pmerge = "0-" if($hiddenflag == 1 && ($book == 1 || $cdcue == 2)); |
| 3310 |
@skip = skip_tracks(0); |
| 3311 |
@merge = split(/,/, $pmerge); |
| 3312 |
# Define a string to concatenate the track names. |
| 3313 |
my $concat = " + "; |
| 3314 |
$concat =~ s/ /_/g if($underscore == 1); |
| 3315 |
$concat = clean_chars($concat) if($chars); |
| 3316 |
foreach(@merge) { |
| 3317 |
my @bea = split(/-|\+/, $_); |
| 3318 |
my $beg = $bea[0] - 1; |
| 3319 |
$beg = 0 if($beg < 0); # If nerds want to merge hidden tracks. |
| 3320 |
while($bea[0] < $bea[1]) { |
| 3321 |
$secondlist[$beg] += $secondlist[$bea[0]]; |
| 3322 |
# Framelist is already a summed list and we do not want to |
| 3323 |
# spoil indices of tracks kept, alter subsequent tracks |
| 3324 |
# merged. |
| 3325 |
$framelist[$beg+1] = $framelist[$bea[1]]; |
| 3326 |
# Don't merge all track names if option book or cdcue is |
| 3327 |
# used. |
| 3328 |
if($vatag == 0) { |
| 3329 |
$tracklist[$beg] = $tracklist[$beg] . $concat . |
| 3330 |
$tracklist[$bea[0]] unless($book == 1 or $cdcue == 2); |
| 3331 |
$tracktags[$beg] = $tracktags[$beg] . " + " . |
| 3332 |
$tracktags[$bea[0]] unless($book == 1 or $cdcue == 2); |
| 3333 |
} |
| 3334 |
else { |
| 3335 |
$tracklist[$beg] = $tracklist[$beg] . $concat . |
| 3336 |
$tracklist[$bea[0]] unless($book == 1 or $cdcue == 2); |
| 3337 |
my $delim_l_close = $delim; |
| 3338 |
my $delim_t_close = $delim; |
| 3339 |
if($delim =~ /[([{]/) { |
| 3340 |
$delim_l_close =~ tr/\({\[/)}]/; |
| 3341 |
$delim_t_close =~ tr/\({\[/)}]/; |
| 3342 |
# $delim_l_close = chop($tracklist[$beg]) if($tracktags[$beg] =~ /[)}\]]$/); |
| 3343 |
# $delim_t_close = chop($tracktags[$beg]) if($tracktags[$beg] =~ /[)}\]]$/); |
| 3344 |
} |
| 3345 |
# Syntax: Left/Right_List/Tag_Prev/New |
| 3346 |
my ($l_t_p,$r_t_p) = split(/$delim/, $tracktags[$beg]); |
| 3347 |
my ($l_t_n,$r_t_n) = split(/$delim/, $tracktags[$bea[0]]); |
| 3348 |
$tracktags[$beg] = $l_t_p . $concat . $l_t_n . $delimiter . $r_t_p . $concat . $r_t_n . $delim_t_close unless($book == 1 or $cdcue == 2); |
| 3349 |
$tracktags[$beg] =~ s/\s+/ /g; |
| 3350 |
} |
| 3351 |
$bea[0]++; |
| 3352 |
} |
| 3353 |
} |
| 3354 |
} |
| 3355 |
# Display info which tracks are going to be ripped. Because of option |
| 3356 |
# merge we have to work hard to make it look nice: |
| 3357 |
@tracksel = @seltrack; # Use a copy of @seltrack to work with. |
| 3358 |
my @printracks; # A new array in nice print format. |
| 3359 |
my $trackcn; |
| 3360 |
my $prevtcn = -1; |
| 3361 |
# Add the hidden track to @tracksel if a nerd wants it to merge, i.e. |
| 3362 |
# operator entered it in the merge argument. |
| 3363 |
unshift(@tracksel, 0) if($pmerge && $pmerge =~ /^0/ && $hiddenflag == 1); |
| 3364 |
foreach $trackcn (@tracksel) { |
| 3365 |
next if($trackcn <= $prevtcn); |
| 3366 |
my $trackno; |
| 3367 |
# Check if next track number is in the skip array of tracks being |
| 3368 |
# merged. If so, add a hyphen. |
| 3369 |
my $increment = 1; |
| 3370 |
if($skip[0] && ($trackcn + $increment) =~ /^$skip[0]$/) { |
| 3371 |
$trackno = $trackcn . "-"; |
| 3372 |
shift(@skip); |
| 3373 |
$trackcn++; |
| 3374 |
# Is the next track number the last of the interval of merged |
| 3375 |
# tracks? If not, continue to increase the track number. |
| 3376 |
while($skip[0] && ($trackcn + $increment) =~ /^$skip[0]$/) { |
| 3377 |
$trackcn++; |
| 3378 |
shift(@skip); |
| 3379 |
} |
| 3380 |
$trackno = $trackno . $trackcn; |
| 3381 |
$prevtcn = $trackcn; |
| 3382 |
} |
| 3383 |
else { |
| 3384 |
$trackno = $trackcn; |
| 3385 |
} |
| 3386 |
push(@printracks, $trackno); |
| 3387 |
} |
| 3388 |
|
| 3389 |
print "\n" if($verbose > 0); |
| 3390 |
if($#seltrack == 0 && $hiddenflag == 0) { |
| 3391 |
print "Track @printracks will be ripped.\n\n" if($verbose > 0); |
| 3392 |
} |
| 3393 |
elsif(!@seltrack && $hiddenflag == 1) { |
| 3394 |
print "Track 0 will be ripped.\n\n" if($verbose > 0); |
| 3395 |
} |
| 3396 |
elsif($pmerge && $pmerge =~ /^0/ && $hiddenflag == 1) { |
| 3397 |
print "Tracks @printracks will be ripped.\n\n" if($verbose > 0); |
| 3398 |
} |
| 3399 |
elsif($hiddenflag == 1) { |
| 3400 |
print "Tracks 0 @printracks will be ripped.\n\n" if($verbose > 0); |
| 3401 |
} |
| 3402 |
else { |
| 3403 |
print "Tracks @printracks will be ripped.\n\n" if($verbose > 0); |
| 3404 |
} |
| 3405 |
|
| 3406 |
# Prevent failure if hald occupies drive. |
| 3407 |
sleep 6 if($loop == 2); |
| 3408 |
# Get the time when ripping started, and save it in the error.log. |
| 3409 |
my $ripstart = sprintf("%02d:%02d", sub {$_[2], $_[1]}->(localtime)); |
| 3410 |
my $date = sprintf("%04d-%02d-%02d", |
| 3411 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 3412 |
|
| 3413 |
# If accurate rip is wanted, no way to parallelize the process, but |
| 3414 |
# checks on each track still must be done afterwards. |
| 3415 |
# It could be done though, just alter the main part in the loop |
| 3416 |
# to look for wav files done and somehow block / mv them to a secure |
| 3417 |
# place in case Morituri wants to delete them because of failed |
| 3418 |
# checksums... but then: what should the clean-up rule be? |
| 3419 |
# As of version 0.2.2 rip will cancel process in case wav directory |
| 3420 |
# is present. So creation of wav directory must be prevented and done |
| 3421 |
# by rip (Morituri) i.e. rip needs to be started before writing |
| 3422 |
# headers of any descripitve files. In earlier versions of ripit |
| 3423 |
# this snippet was positioned right before the foreach(@tracksel) |
| 3424 |
# loop. |
| 3425 |
my $mori_dirs = ""; |
| 3426 |
if($ripper == 3 && $rip == 1) { |
| 3427 |
print "\nRipping to \"$wavdir\" using rip:\n" if($verbose > 3); |
| 3428 |
$ripcom = "rip cd -d $cddev rip --profile=wav -U \\ |
| 3429 |
--track-template=\"%t\_Morituri-Rip\" \\ |
| 3430 |
--disc-template=\"\" --offset=$offset \\ |
| 3431 |
-O \"$wavdir\""; |
| 3432 |
$ripcom .= " $ripopt" if($ripopt ne ""); |
| 3433 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 3434 |
unless(log_system("$ripcom")) { |
| 3435 |
die "Morituri (rip) failed."; |
| 3436 |
} |
| 3437 |
print "Ripping complete.\n" if($verbose > 3); |
| 3438 |
# Is this a rip (Morituri) bug? All meta files have no name and |
| 3439 |
# become hidden. Probably due to the empty disc template. |
| 3440 |
foreach ("cue", "log", "m3u") { |
| 3441 |
if(-f "$wavdir/.$_") { |
| 3442 |
log_system("mv \"/$wavdir/.$_\" \\ |
| 3443 |
\"$wavdir/Morituri.$_\""); |
| 3444 |
} |
| 3445 |
else { |
| 3446 |
# If we did not die above, Morituri might have placed files |
| 3447 |
# somewhere else... |
| 3448 |
opendir(RIP, "$wavdir") or |
| 3449 |
print "Can not read in $wavdir: $!\n"; |
| 3450 |
my @mori_dirs = grep {/^\s*\(/i} readdir(RIP); |
| 3451 |
$mori_dirs = $mori_dirs[0]; |
| 3452 |
close(RIP); |
| 3453 |
if(-f "$wavdir/$mori_dirs/.$_") { |
| 3454 |
log_system("mv \"/$wavdir/$mori_dirs/.$_\" \\ |
| 3455 |
\"$wavdir/Morituri.$_\""); |
| 3456 |
} |
| 3457 |
else { |
| 3458 |
print "Did not detect file: $wavdir/$mori_dirs/.$_\n" |
| 3459 |
if($verbose > 3); |
| 3460 |
} |
| 3461 |
} |
| 3462 |
} |
| 3463 |
} |
| 3464 |
|
| 3465 |
# Write the start time to error.log only when all directories exist. |
| 3466 |
open(ERO, ">$wavdir/error.log") |
| 3467 |
or print "Can not write to file \"$wavdir/error.log\"!\n"; |
| 3468 |
print ERO "Ripping started: $ripstart\n"; |
| 3469 |
close(ERO); |
| 3470 |
if($multi == 1) { |
| 3471 |
open(SRXY, ">>$logfile") |
| 3472 |
or print "Can not append to file \"$logfile\"!\n"; |
| 3473 |
print SRXY "\nRipping started: $ripstart"; |
| 3474 |
close(SRXY); |
| 3475 |
} |
| 3476 |
|
| 3477 |
# Write a toc-file. |
| 3478 |
if($cdtoc == 1) { |
| 3479 |
my $cdtocartis = $artistag; |
| 3480 |
oct_char($cdtocartis); |
| 3481 |
my $cdtocalbum = $albumtag; |
| 3482 |
oct_char($cdtocalbum); |
| 3483 |
# Again, in case we have a multi disc release and operator wants |
| 3484 |
# to merge discs in directory using $trackoffset, it might be |
| 3485 |
# appropriate not to merge the cd.toc (as it is done for the play |
| 3486 |
# list file), but to backup the existing file and write a new one. |
| 3487 |
if(-f "$wavdir/cd.toc" |
| 3488 |
and ($addtrackoffset == 1 or $trackoffset > 0)) { |
| 3489 |
my $medium = 1; # TODO: use the medium counter from MB part. |
| 3490 |
my $fmedium = sprintf("%02d", $medium); |
| 3491 |
while(-f "$wavdir/cd_$fmedium.toc") { |
| 3492 |
$medium++; |
| 3493 |
last if($medium > 20); # Hard coded exit condition... |
| 3494 |
$fmedium = sprintf("%02d", $medium); |
| 3495 |
} |
| 3496 |
print "Existing cd.toc will be renamed to cd_$fmedium.toc.\n" |
| 3497 |
if($verbose > 3); |
| 3498 |
rename("$wavdir/cd.toc", "$wavdir/cd_$fmedium.toc"); |
| 3499 |
} |
| 3500 |
open(CDTOC, ">$wavdir/cd.toc") |
| 3501 |
or print "Can not write to file \"$wavdir/cd.toc\"!\n"; |
| 3502 |
print CDTOC "CD_DA\n//Ripit $version cd.toc file generated ", |
| 3503 |
"$date at $ripstart.", |
| 3504 |
"\n//Use command >cdrdao scanbus< to detect device.", |
| 3505 |
"\n//Assume the device found is: 1,0,0 : _NEC ", |
| 3506 |
" then use e. g. command", |
| 3507 |
"\n//>cdrdao write --device 1,0,0 ", |
| 3508 |
"--speed 4 cd.toc< to burn the CD.", |
| 3509 |
"\n//Note: Not all CD (DVD) burners are able to burn", |
| 3510 |
" CD-text!\n//Test your device!"; |
| 3511 |
print CDTOC "\n//CDDBID=$cddbid"; |
| 3512 |
print CDTOC "\n//DISCID=$discid" if($discid ne ""); # New 4.0 |
| 3513 |
print CDTOC "\n\n//CD Text:\nCD_TEXT{LANGUAGE_MAP {0 : EN}\n\t"; |
| 3514 |
print CDTOC "LANGUAGE 0 {\n\t\tTITLE \"$cdtocalbum\"\n\t\t"; |
| 3515 |
print CDTOC "PERFORMER \"$cdtocartis\"\n"; |
| 3516 |
# print CDTOC "\t\tGENRE \"$genreno\"\n" if($genreno); |
| 3517 |
print CDTOC "\t\tDISC_ID \"$cddbid\"\n\t}\n}\n"; |
| 3518 |
close(CDTOC); |
| 3519 |
} |
| 3520 |
|
| 3521 |
# Start to rip the hidden track if there's one: First check if |
| 3522 |
# cdparanoia is available. |
| 3523 |
if($ripper != 1) { |
| 3524 |
unless(log_system("cdparanoia -V")) { |
| 3525 |
print "Cdparanoia not installed? Can't rip the hidden track "; |
| 3526 |
print "without cdparanoia!\n" |
| 3527 |
if($hiddenflag == 1); |
| 3528 |
$hiddenflag = 0; |
| 3529 |
} |
| 3530 |
} |
| 3531 |
|
| 3532 |
# Get delimiter for VA style. |
| 3533 |
# No messages to be printed. |
| 3534 |
($delim, $dummy) = check_va(0) if($vatag > 0); |
| 3535 |
$delim = quotemeta($delim) if(defined $delim); |
| 3536 |
|
| 3537 |
# Check if the hidden track has been done in a previous session. |
| 3538 |
my $checknextflag = 0; |
| 3539 |
if($resumerip) { |
| 3540 |
$riptrackname = "Hidden Track"; |
| 3541 |
$riptrackname = change_case($riptrackname, "t"); |
| 3542 |
$riptrackname =~ s/ /_/g if($underscore == 1); |
| 3543 |
$riptrackname = get_trackname(0, $riptrackname, 0, $artist, "Hidden Track"); |
| 3544 |
if(-r "$wavdir/$riptrackname.rip") { |
| 3545 |
unlink("$wavdir/$riptrackname.rip"); |
| 3546 |
print "Found $riptrackname.rip.\n" if($verbose >= 1); |
| 3547 |
} |
| 3548 |
elsif(-r "$wavdir/$riptrackname.wav") { |
| 3549 |
$checknextflag = 1; |
| 3550 |
print "Found $riptrackname.wav.\n" if($verbose >= 1); |
| 3551 |
md5_sum("$wavdir", "$riptrackname.wav", 0) |
| 3552 |
if($md5sum == 1 && $wav == 1); |
| 3553 |
} |
| 3554 |
else{ |
| 3555 |
for(my $c=0; $c<=$#coder; $c++) { |
| 3556 |
if(-r "$sepdir[$c]/$riptrackname.$suffix[$c]") { |
| 3557 |
$checknextflag = 1; |
| 3558 |
print "Found file $riptrackname.$suffix[$c].\n"; |
| 3559 |
} |
| 3560 |
} |
| 3561 |
} |
| 3562 |
if($checknextflag == 1) { |
| 3563 |
$riptrackname = "Hidden Track"; |
| 3564 |
unshift(@tracktags, $riptrackname); |
| 3565 |
unshift(@seltrack, 0); |
| 3566 |
unshift(@tracklist, $riptrackname); |
| 3567 |
} |
| 3568 |
} |
| 3569 |
|
| 3570 |
# Define some counters: |
| 3571 |
# Because cdtoc is written in different subroutines, define a counter |
| 3572 |
# for each track written into the toc file. This way, ghost songs are |
| 3573 |
# sorted in the toc file, while they aren't in the @seltrack array. |
| 3574 |
my $cdtocn = 0 + $trackoffset; |
| 3575 |
|
| 3576 |
# Write header of cue-file. |
| 3577 |
if($cdcue > 0) { |
| 3578 |
# Again, in case we have a multi disc release and operator wants |
| 3579 |
# to merge discs in directory using $trackoffset, it might be |
| 3580 |
# appropriate not to merge the cd.cue (as it is done for the play |
| 3581 |
# list file), but to backup the existing file and write a new one. |
| 3582 |
if(-f "$wavdir/cd.cue" |
| 3583 |
and ($addtrackoffset == 1 or $trackoffset > 0)) { |
| 3584 |
my $medium = 1; # TODO: use the medium counter from MB part. |
| 3585 |
my $fmedium = sprintf("%02d", $medium); |
| 3586 |
while(-f "$wavdir/cd_$fmedium.cue") { |
| 3587 |
$medium++; |
| 3588 |
last if($medium > 20); # Hard-coded exit condition... |
| 3589 |
$fmedium = sprintf("%02d", $medium); |
| 3590 |
} |
| 3591 |
print "Existing cd.cue will be renamed to cd_$fmedium.cue.\n" |
| 3592 |
if($verbose > 3); |
| 3593 |
rename("$wavdir/cd.cue", "$wavdir/cd_$fmedium.cue"); |
| 3594 |
} |
| 3595 |
open(CDCUE, ">$wavdir/cd.cue") |
| 3596 |
or print "Can not write to file \"$wavdir/cd.cue\"!\n"; |
| 3597 |
print CDCUE "TITLE \"$albumtag\"\nPERFORMER \"$artistag\"\n", |
| 3598 |
"FILE \"$wavdir/$album.wav\" WAVE\n"; |
| 3599 |
close(CDCUE); |
| 3600 |
} |
| 3601 |
# Process a possible hidden (first) track. |
| 3602 |
if($hiddenflag == 1 && $checknextflag == 0) { |
| 3603 |
$riptrackname = "Hidden Track"; |
| 3604 |
unshift @tracktags, $riptrackname; |
| 3605 |
my $cdtocname = $riptrackname; |
| 3606 |
$riptrackname = change_case($riptrackname, "t"); |
| 3607 |
$riptrackname =~ s/ /_/g if($underscore == 1); |
| 3608 |
unshift @seltrack, 0; |
| 3609 |
unshift @tracklist, $riptrackname; |
| 3610 |
$riptrackname = get_trackname(0, $tracklist[0], 0, $artist, "Hidden Track"); |
| 3611 |
# If a cuefile shall be created, use album for the track name. |
| 3612 |
$riptrackname = $album if($book == 1 or $cdcue == 2); |
| 3613 |
my $start_point = "[00:00]"; |
| 3614 |
# What if the operator wants to merge a hidden track with the 1st |
| 3615 |
# and so on tracks? Calculate the number of the last track to be |
| 3616 |
# merged with the hidden track. |
| 3617 |
my $endtrackno = 0; |
| 3618 |
if($pmerge) { |
| 3619 |
my @bea = split(/-|\+/, $merge[0]); |
| 3620 |
# Hm, always confused. Should we use defined here to enter the |
| 3621 |
# condition in case $bea[0] is defined, but zero? |
| 3622 |
#if($bea[0] && $bea[0] == 0) { |
| 3623 |
if(defined $bea[0] && $bea[0] == 0) { |
| 3624 |
$endtrackno = $bea[1]; |
| 3625 |
$endtrackno =~ s/^0.//; |
| 3626 |
$endtrackno++ unless($endtrackno == $seltrack[$#seltrack]); |
| 3627 |
$start_point .= "-$endtrackno"; |
| 3628 |
} |
| 3629 |
} |
| 3630 |
# Assemble the command for cdparanoia to rip the hidden track. |
| 3631 |
my $saveripopt = $ripopt; |
| 3632 |
$ripopt .= " -Z" if($parano == 0); |
| 3633 |
$ripopt .= " -q" if($verbose <= 1 && $ripopt !~ /\s-q/); |
| 3634 |
$ripopt .= " -O $offset" if($offset < 0 || $offset > 0); |
| 3635 |
$ripcom = "cdparanoia $ripopt -d $cddev $start_point \\ |
| 3636 |
\"$wavdir/$riptrackname.rip\""; |
| 3637 |
printf "\n%02d:%02d:%02d: ", sub {$_[2], $_[1], $_[0]}->(localtime) |
| 3638 |
if($verbose >= 1 && $rip == 1); |
| 3639 |
if($ripper == 3) { |
| 3640 |
print "Checking ripfile \"$riptrackname\"...\n" |
| 3641 |
if($verbose >= 1 && $rip == 1); |
| 3642 |
} |
| 3643 |
else { |
| 3644 |
print "Ripping \"$riptrackname\"...\n" |
| 3645 |
if($verbose >= 1 && $rip == 1); |
| 3646 |
} |
| 3647 |
|
| 3648 |
unless(log_system("$ripcom")) { |
| 3649 |
if($parano == 2) { |
| 3650 |
$ripopt .= " -Z" if($parano == 2); |
| 3651 |
$ripopt .= " -O $offset" if($offset < 0 || $offset > 0); |
| 3652 |
$ripcom = "cdparanoia $ripopt -d $cddev $start_point \\ |
| 3653 |
\"$wavdir/$riptrackname.rip\""; |
| 3654 |
print "\n\nTrying again without paranoia.\n" |
| 3655 |
if($verbose > 1); |
| 3656 |
unless(log_system("$ripcom")) { |
| 3657 |
# If no success, shift the hidden track stuff out of |
| 3658 |
# arrays. |
| 3659 |
$hiddenflag = 0; |
| 3660 |
shift(@secondlist); |
| 3661 |
shift(@seltrack); |
| 3662 |
shift(@tracklist); |
| 3663 |
shift(@tracktags); |
| 3664 |
} |
| 3665 |
} |
| 3666 |
else { |
| 3667 |
# If no success, shift the hidden track stuff out of arrays. |
| 3668 |
$hiddenflag = 0; |
| 3669 |
shift(@secondlist); |
| 3670 |
shift(@seltrack); |
| 3671 |
shift(@tracklist); |
| 3672 |
shift(@tracktags); |
| 3673 |
} |
| 3674 |
} |
| 3675 |
|
| 3676 |
# Write to the toc file. |
| 3677 |
if($cdtoc == 1 && $hiddenflag == 1) { |
| 3678 |
open(CDTOC ,">>$wavdir/cd.toc") |
| 3679 |
or print "Can not append to file \"$wavdir/cd.toc\"!\n"; |
| 3680 |
print CDTOC "\n//Track 0:\nTRACK AUDIO\nTWO_CHANNEL_AUDIO\n"; |
| 3681 |
print CDTOC "CD_TEXT {LANGUAGE 0 {\n\t\tTITLE \"$cdtocname\""; |
| 3682 |
print CDTOC "\n\t\tPERFORMER \"$artistag\"\n\t}\n}\n"; |
| 3683 |
print CDTOC "FILE \"$riptrackname.wav\" 0\n"; |
| 3684 |
close(CDTOC); |
| 3685 |
} |
| 3686 |
# Check the hidden track for gaps. We do not care about option |
| 3687 |
# merge... should we? Yes, we should. If option merge has been |
| 3688 |
# chosen for this track, splitting is not allowed, while |
| 3689 |
# extracting one chunk of sound may be desired. |
| 3690 |
my @times = (0); |
| 3691 |
if($ghost == 1 && $hiddenflag == 1) { |
| 3692 |
@times = get_chunks(0, $riptrackname); |
| 3693 |
unless($times[0] eq "blank") { |
| 3694 |
(my $shorten, @times) = |
| 3695 |
split_chunks(0, "$riptrackname", 0, @times); |
| 3696 |
($cdtocn, $cue_point) = |
| 3697 |
rename_chunks(0, "$riptrackname", "$riptrackname", 0, |
| 3698 |
$cue_point, $shorten, $artistag, $riptrackname, |
| 3699 |
@times); |
| 3700 |
} |
| 3701 |
} |
| 3702 |
if($hiddenflag == 1) { |
| 3703 |
rename("$wavdir/$riptrackname.rip", |
| 3704 |
"$wavdir/$riptrackname.wav"); |
| 3705 |
} |
| 3706 |
$ripopt = $saveripopt; |
| 3707 |
} |
| 3708 |
|
| 3709 |
# If ripping did not fail (on whatever track of the whole disc), |
| 3710 |
# write the hidden track info to the cue file. |
| 3711 |
if($cdcue == 2 && $hiddenflag == 1) { |
| 3712 |
my $points = track_length($framelist_orig[1] - $framelist_orig[0], 2); |
| 3713 |
# TODO: What if option span is used? |
| 3714 |
open(CDCUE ,">>$wavdir/cd.cue") |
| 3715 |
or print "Can not append to file \"$wavdir/cd.cue\"!\n"; |
| 3716 |
print CDCUE "TRACK 01 AUDIO\n", |
| 3717 |
" TITLE \"Hidden Track\"\n", |
| 3718 |
" PERFORMER \"$artistag\"\n", |
| 3719 |
" INDEX 01 $points\n"; |
| 3720 |
close(CDCUE); |
| 3721 |
} |
| 3722 |
# End preparation of ripping process. |
| 3723 |
# |
| 3724 |
# |
| 3725 |
# Start ripping each track. Note that we have to skip a possible |
| 3726 |
# hidden track. To prevent re-ripping ghost songs pushed into the |
| 3727 |
# @seltrack array, make a copy which will not be altered. |
| 3728 |
@tracksel = @seltrack; |
| 3729 |
|
| 3730 |
# Encoder messages are printed into a file which will be read by the |
| 3731 |
# ripper to prevent splitting ripper-messages. Lines already printed |
| 3732 |
# will not be printed again, use counter $encline. |
| 3733 |
my $encline = 0; |
| 3734 |
$trackcn = 0; |
| 3735 |
|
| 3736 |
foreach(@tracksel) { |
| 3737 |
next if($_ == 0); # Skip hidden track. |
| 3738 |
$trackcn++; |
| 3739 |
$riptracktag = $tracktags[$_ - 1]; |
| 3740 |
$riptracktag = $tracktags[$_] if($hiddenflag == 1); |
| 3741 |
|
| 3742 |
# Split the tracktag into its artist part and track part if |
| 3743 |
# VA style is used. |
| 3744 |
if(defined $delim && $va_flag > 0 && $riptracktag =~ /$delim/) { |
| 3745 |
($artistag, $riptracktag) = split_tags($riptracktag, $delim); |
| 3746 |
} |
| 3747 |
$artistag = clean_all($artist_utf8) unless(defined $artistag); |
| 3748 |
$trackartist = clean_all($artistag); |
| 3749 |
$trackartist = clean_name($trackartist); |
| 3750 |
$trackartist = clean_chars($trackartist); |
| 3751 |
$tracktitle = clean_all($riptracktag); |
| 3752 |
$tracktitle = clean_name($tracktitle); |
| 3753 |
$tracktitle = clean_chars($tracktitle); |
| 3754 |
$trackartist =~ s/ /_/g if($underscore == 1); |
| 3755 |
$tracktitle =~ s/ /_/g if($underscore == 1); |
| 3756 |
|
| 3757 |
$riptrackname = get_trackname($_, $tracklist[$_ - 1], 0, $trackartist, $tracktitle); |
| 3758 |
$riptrackname = get_trackname($_, $tracklist[$_], 0, $trackartist, $tracktitle) |
| 3759 |
if($hiddenflag == 1); |
| 3760 |
$riptrackname = $album if($book == 1 or $cdcue == 2); |
| 3761 |
|
| 3762 |
my $riptrackno = $_; |
| 3763 |
# If we use option merge, skip a previously merged track: |
| 3764 |
my $skipflag = 0; |
| 3765 |
if($pmerge) { |
| 3766 |
@skip = skip_tracks(0); |
| 3767 |
foreach my $skip (@skip) { |
| 3768 |
$skipflag = 1 if($_ == $skip); |
| 3769 |
} |
| 3770 |
} |
| 3771 |
if(($cdtoc == 1 || $cdcue > 0) && $failflag == 0) { |
| 3772 |
$cdtocn++; |
| 3773 |
} |
| 3774 |
# Don't write the cue entry again in case ripper failed with |
| 3775 |
# paranoia and retries ripping without. |
| 3776 |
if($cdcue == 2 && $failflag == 0) { |
| 3777 |
my $points = |
| 3778 |
track_length($framelist_orig[$_ - 1] - $framelist_orig[0], 2); |
| 3779 |
# In case span argument is used, update the cue file after |
| 3780 |
# ripping. Remember, in normal case cdcue == 1 and detection |
| 3781 |
# for ghost songs subroutine will ensure correct track lengths. |
| 3782 |
# This should only be needed in case cdcue == 2 and option |
| 3783 |
# span defined. |
| 3784 |
$points = "cue-span-seconds" if($span); |
| 3785 |
my $cuetrackno = sprintf("%02d", $cdtocn); |
| 3786 |
open(CDCUE, ">>$wavdir/cd.cue") |
| 3787 |
or print "Can not append to file \"$wavdir/cd.cue\"!\n"; |
| 3788 |
print CDCUE "TRACK $cuetrackno AUDIO\n", |
| 3789 |
" TITLE \"$riptracktag\"\n", |
| 3790 |
" PERFORMER \"$artistag\"\n", |
| 3791 |
" INDEX 01 $points\n"; |
| 3792 |
close(CDCUE); |
| 3793 |
} |
| 3794 |
|
| 3795 |
# Remember: $riptrackno is the track number passed to the encoder. |
| 3796 |
# If we want to merge, we substitute it with the interval, with a |
| 3797 |
# hyphen for cdparanoia and a plus sign for cdda2wav. |
| 3798 |
my $saveriptrackno = $riptrackno; |
| 3799 |
if($pmerge && $merge[0]) { |
| 3800 |
my @bea = split(/-|\+/, $merge[0]); |
| 3801 |
if($bea[0] && $riptrackno == $bea[0]) { |
| 3802 |
$riptrackno = shift(@merge); |
| 3803 |
$riptrackno =~ s/-/\+/ if($ripper == 2); |
| 3804 |
$riptrackno =~ s/\+/-/ if($ripper == 1); |
| 3805 |
# TODO: check for dagrab and sox... |
| 3806 |
} |
| 3807 |
} |
| 3808 |
# LCDproc |
| 3809 |
if($lcd == 1) { |
| 3810 |
my $_lcdtracks = scalar(@tracksel); |
| 3811 |
$lcdtrackno++; |
| 3812 |
my $lcdperc; |
| 3813 |
if($_lcdtracks eq $lcdtrackno) { |
| 3814 |
$lcdperc = "*100"; |
| 3815 |
} |
| 3816 |
else { |
| 3817 |
$lcdperc = sprintf("%04.1f", $lcdtrackno/$_lcdtracks*100); |
| 3818 |
} |
| 3819 |
$lcdline2 =~ s/\|\d\d.\d/\|$lcdperc/; |
| 3820 |
my $lcdtracknoF = sprintf("%02d", $lcdtrackno); |
| 3821 |
$lcdline2 =~ s/\r\d\d/\r$lcdtracknoF/; |
| 3822 |
substr($lcdline2,10,10) = substr($riptrackname,3,13); |
| 3823 |
ulcd(); |
| 3824 |
} |
| 3825 |
|
| 3826 |
# There is a problem with too long file names encountered e. g. |
| 3827 |
# with some classical CDs. Cdparanoia cuts the length of the file |
| 3828 |
# name, cdda2wav too... but how should RipIT know? Therefore use |
| 3829 |
# a shorter track name if total length (including the full path) |
| 3830 |
# > 190 characters. |
| 3831 |
my $rip_wavdir = $wavdir; |
| 3832 |
my $rip_wavnam = $riptrackname; |
| 3833 |
if(length($riptrackname) + length($wavdir) > 190) { |
| 3834 |
print "Warning: output track name is longer than 190 chars,\n", |
| 3835 |
"Ripit will use a temporary output name for the ", |
| 3836 |
"WAV-file.\n" |
| 3837 |
if($verbose > 2); |
| 3838 |
$riptrackname = get_trackname($_, $_ . "short", "short", $trackartist, $tracktitle); |
| 3839 |
# We still have problems in case total path is too long: |
| 3840 |
$rip_wavdir = "/tmp" |
| 3841 |
if(length($riptrackname) + length($wavdir) > 250); |
| 3842 |
} |
| 3843 |
# Worse, if the directory name has periods in, cdda2wav freaks |
| 3844 |
# out completely. |
| 3845 |
if($ripper == 2 && $wavdir =~ /\./) { |
| 3846 |
$rip_wavdir = "/tmp"; |
| 3847 |
} |
| 3848 |
# Write the toc entry only if wav present, don't write it again in |
| 3849 |
# case ripper failed with paranoia and retries ripping without. |
| 3850 |
# In case we check for ghost songs, these might be deleted, so |
| 3851 |
# don't write the toc file here. |
| 3852 |
if($cdtoc == 1 && $failflag == 0 && $ghost == 0) { |
| 3853 |
my $cdtoctitle = $riptracktag; |
| 3854 |
oct_char($cdtoctitle); |
| 3855 |
my $cdtocartis = $artistag; |
| 3856 |
oct_char($cdtocartis); |
| 3857 |
my $cdtoctrckartis = $trackartist; |
| 3858 |
oct_char($cdtoctrckartis); |
| 3859 |
my $points = 0; |
| 3860 |
$points = |
| 3861 |
track_length($framelist_orig[$_ - 1] - $framelist_orig[0], 2) |
| 3862 |
. " " . |
| 3863 |
track_length($framelist_orig[$_] - $framelist_orig[$_ - 1], 2) |
| 3864 |
if($book > 0 || $cdcue > 0); |
| 3865 |
open(CDTOC, ">>$wavdir/cd.toc") |
| 3866 |
or print "Can not append to file \"$wavdir/cd.toc\"!\n"; |
| 3867 |
print CDTOC "\n//Track $cdtocn:\nTRACK AUDIO\n"; |
| 3868 |
print CDTOC "TWO_CHANNEL_AUDIO\nCD_TEXT {LANGUAGE 0 {\n\t\t"; |
| 3869 |
print CDTOC "TITLE \"$cdtoctitle\"\n\t\t"; |
| 3870 |
print CDTOC "PERFORMER \"$cdtocartis\""; |
| 3871 |
print CDTOC "\n\t\tSONGWRITER \"$cdtoctrckartis\"" if($vatag > 0); |
| 3872 |
print CDTOC "\n\t}\n}\n"; |
| 3873 |
print CDTOC "FILE \"$rip_wavnam.wav\" $points\n"; |
| 3874 |
print CDTOC "ISRC " . $isrcs[$_-1] . "\n" |
| 3875 |
if($isrc == 1 and $isrcs[$_-1] ne ""); |
| 3876 |
close(CDTOC); |
| 3877 |
} |
| 3878 |
|
| 3879 |
print "\nRipper skips track $_ merged into previous one.\n" |
| 3880 |
if($verbose >=1 && $skipflag == 1); |
| 3881 |
next if($skipflag == 1); |
| 3882 |
|
| 3883 |
# Check for tracks already done if option --resume is on. |
| 3884 |
$checknextflag = 0; |
| 3885 |
if($resumerip) { |
| 3886 |
if($normalize == 0 and $cdcue == 0) { |
| 3887 |
# Start the encoder in the background, but only once. |
| 3888 |
# We do it already here, because: |
| 3889 |
# i) if all wavs are done, the encoding process at the end |
| 3890 |
# of this subroutine will not be started at all! |
| 3891 |
# ii) why should we wait for the first missing wav, if |
| 3892 |
# other wavs are already here and encoding could start |
| 3893 |
# (continue) right away? |
| 3894 |
if($startenc == 0 && $encode == 1) { |
| 3895 |
$startenc = 1; |
| 3896 |
open(ENCLOG, ">$wavdir/enc.log"); |
| 3897 |
close(ENCLOG); |
| 3898 |
unless(fork) { |
| 3899 |
enc_cd(); |
| 3900 |
} |
| 3901 |
} |
| 3902 |
} |
| 3903 |
|
| 3904 |
if(-r "$wavdir/$riptrackname.rip") { |
| 3905 |
unlink("$wavdir/$riptrackname.rip"); |
| 3906 |
print "Found $riptrackname.rip.\n" if($verbose >= 1); |
| 3907 |
} |
| 3908 |
elsif(-r "$wavdir/$riptrackname\_rip.wav" && $ripper == 2) { |
| 3909 |
unlink("$wavdir/$riptrackname\_rip.wav"); |
| 3910 |
print "Found $riptrackname\_rip.wav.\n" if($verbose >= 1); |
| 3911 |
} |
| 3912 |
elsif(-r "$wavdir/$riptrackname.wav") { |
| 3913 |
$checknextflag = 1; |
| 3914 |
print "Found $riptrackname.wav.\n" if($verbose >= 1); |
| 3915 |
if($md5sum == 1 && $wav == 1) { |
| 3916 |
md5_sum("$wavdir", "$riptrackname.wav", 0); |
| 3917 |
} |
| 3918 |
} |
| 3919 |
elsif($wav == 0) { |
| 3920 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 3921 |
if(-r "$sepdir[$c]/$riptrackname.$suffix[$c]") { |
| 3922 |
$checknextflag = 1; |
| 3923 |
print "Found file $riptrackname.$suffix[$c].\n" |
| 3924 |
if($verbose >= 1); |
| 3925 |
} |
| 3926 |
else { |
| 3927 |
$checknextflag = 2; |
| 3928 |
} |
| 3929 |
last if($checknextflag == 2); |
| 3930 |
} |
| 3931 |
} |
| 3932 |
# Cdda2wav is somehow unpleasant. It dies not quick enough with |
| 3933 |
# ^+c. I. e. even if a track has not been ripped to the end, |
| 3934 |
# the *.rip file will become a *.wav. So we have to check for |
| 3935 |
# completely encoded files and assume, that for not encoded |
| 3936 |
# files, there is no fully ripped file. OK, perhaps it would be |
| 3937 |
# better to check for the last *.wav file and re-rip only that |
| 3938 |
# one. But on a modern machine, the encoder won't be far from |
| 3939 |
# catching up the ripper, so deleting all *.wavs for missing |
| 3940 |
# encoded files won't hurt, because cdda2wav is quite fast, |
| 3941 |
# ripping those tracks again doesn't cost a lot of time. |
| 3942 |
if($ripper == 2 && $checknextflag == 1) { |
| 3943 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 3944 |
if(-r "$sepdir[$c]/$riptrackname.$suffix[$c]") { |
| 3945 |
$checknextflag = 1; |
| 3946 |
} |
| 3947 |
else { |
| 3948 |
$checknextflag = 2; |
| 3949 |
} |
| 3950 |
last if($checknextflag == 2); |
| 3951 |
} |
| 3952 |
} |
| 3953 |
} |
| 3954 |
# Skip that track, i.e. restart the foreach-loop of tracks if a |
| 3955 |
# wav file or other (mp3, ogg, flac, m4a) was found. |
| 3956 |
next if($checknextflag == 1); |
| 3957 |
# Don't resume anymore if we came until here. |
| 3958 |
$resumerip = 0; |
| 3959 |
|
| 3960 |
# Now do the job of ripping: |
| 3961 |
printf "\n%02d:%02d:%02d: ", sub {$_[2], $_[1], $_[0]}->(localtime) |
| 3962 |
if($verbose >= 1 && $rip == 1); |
| 3963 |
print "Ripping \"$riptrackname\"...\n" |
| 3964 |
if($verbose >= 1 && $rip == 1); |
| 3965 |
# Choose the cdaudio ripper to use. |
| 3966 |
# |
| 3967 |
# TODO: Check behaviour of all rippers on data tracks. |
| 3968 |
# Choose to use print instead of die if ripper stops itself! |
| 3969 |
# Dagrab fails @ data-track, so don't die and create an error.log, |
| 3970 |
# cdparanoia fails @ data-track, so don't die and create an |
| 3971 |
# error.log. |
| 3972 |
# cdda2wav prints errors @ data-track, therefore die! |
| 3973 |
if($ripper == 0 && $rip == 1) { |
| 3974 |
if($trackcn == 1) { |
| 3975 |
$ripopt .= " -r 3" if($parano == 0 && $ripopt !~ /\s-r\s3/); |
| 3976 |
$ripopt .= " -v" if($verbose >= 2 && $ripopt !~ /\s-v/); |
| 3977 |
} |
| 3978 |
$ripcom = "(dagrab $ripopt -d $cddev \\ |
| 3979 |
-f \"$rip_wavdir/$riptrackname.rip\" \\ |
| 3980 |
$riptrackno 3>&1 1>&2 2>&3 \\ |
| 3981 |
| tee -a \"$wavdir/error.log\") 3>&1 1>&2 2>&3 "; |
| 3982 |
$ripcom =~ s/\$/\\\$/g; |
| 3983 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 3984 |
unless(log_system("$ripcom")) { |
| 3985 |
print "Dagrab detected some read errors on ", |
| 3986 |
"$tracklist[$_ - 1]\n\n"; |
| 3987 |
# Create error message in CD-directory for encoder: don't |
| 3988 |
# wait. |
| 3989 |
open(ERO,">>$wavdir/error.log") |
| 3990 |
or print "Can not append to file ", |
| 3991 |
"\"$wavdir/error.log\"!\n"; |
| 3992 |
print ERO "Dagrab detected some read errors at $riptrackno"; |
| 3993 |
print ERO " on CD $artist - $album, do not worry!\n"; |
| 3994 |
close(ERO); |
| 3995 |
} |
| 3996 |
print "\n"; |
| 3997 |
} |
| 3998 |
elsif($ripper == 1 && $rip == 1) { |
| 3999 |
if($trackcn == 1) { |
| 4000 |
$ripopt .= " -Z" if($parano == 0 && $ripopt !~ /\s-Z/); |
| 4001 |
$ripopt .= " -q" if($verbose < 2 && $ripopt !~ /\s-q/); |
| 4002 |
$ripopt .= " -O $offset" |
| 4003 |
if($ripopt !~ /\s-O/ && ($offset < 0 || $offset > 0)); |
| 4004 |
} |
| 4005 |
# Introduce the span argument into the track number, adjust the |
| 4006 |
# track number suffix according to cdparanoia and recalculate |
| 4007 |
# the track length (used in the playlist file). |
| 4008 |
if($span) { |
| 4009 |
my @bea = split(/-/, $span); |
| 4010 |
my $offset = 0; |
| 4011 |
my $chunk = 0; |
| 4012 |
$offset = span_length($bea[0]) if($bea[0]); |
| 4013 |
$chunk = span_length($bea[1]) if($bea[1]); |
| 4014 |
$bea[0] = "0.0" unless($bea[0]); |
| 4015 |
$bea[1] = " " unless($bea[1]); |
| 4016 |
$bea[0] = "[" . $bea[0] . "]" if($bea[0] =~ /\d+/); |
| 4017 |
$bea[1] = "[" . $bea[1] . "]" if($bea[1] =~ /\d+/); |
| 4018 |
if($riptrackno =~ /-/) { |
| 4019 |
my($i, $j) = split(/-/, $riptrackno); |
| 4020 |
# Special case: if the chunk of sound is larger than the |
| 4021 |
# (last) track, use the true track length instead of chunk |
| 4022 |
# size. |
| 4023 |
if($hiddenflag == 0 && $secondlist[$j - 1] < $chunk) { |
| 4024 |
$chunk = 0; |
| 4025 |
$bea[1] = " "; |
| 4026 |
} |
| 4027 |
elsif($hiddenflag == 1 && $secondlist[$j] < $chunk) { |
| 4028 |
$chunk = 0; |
| 4029 |
$bea[1] = " "; |
| 4030 |
} |
| 4031 |
if($chunk <= 0) { |
| 4032 |
$chunk = $secondlist[$j - 1] if($hiddenflag == 0); |
| 4033 |
$chunk = $secondlist[$j] if($hiddenflag == 1); |
| 4034 |
} |
| 4035 |
$secondlist[$_ - 1] = $secondlist[$_ - 1] - $secondlist[$j - 1] + $chunk - $offset if($hiddenflag == 0); |
| 4036 |
$secondlist[$_] = $secondlist[$_] - $secondlist[$j] + $chunk - $offset if($hiddenflag == 1); |
| 4037 |
$riptrackno = $i . $bea[0] . "-" . $j . $bea[1]; |
| 4038 |
} |
| 4039 |
else { |
| 4040 |
# Special case: if the chunk of sound is larger than the |
| 4041 |
# (last) track, use the true track length instead of chunk |
| 4042 |
# size. |
| 4043 |
if($hiddenflag == 0 && $secondlist[$_ - 1] < $chunk) { |
| 4044 |
$chunk = 0; |
| 4045 |
$bea[1] = " "; |
| 4046 |
} |
| 4047 |
elsif($hiddenflag == 1 && $secondlist[$_] < $chunk) { |
| 4048 |
$chunk = 0; |
| 4049 |
$bea[1] = " "; |
| 4050 |
} |
| 4051 |
$riptrackno = $riptrackno . $bea[0] . "-" . $riptrackno . $bea[1]; |
| 4052 |
# Variable $chunk is zero if span reaches the end of the |
| 4053 |
# track. |
| 4054 |
if($chunk <= 0) { |
| 4055 |
$chunk = $secondlist[$_ - 1] if($hiddenflag == 0); |
| 4056 |
$chunk = $secondlist[$_] if($hiddenflag == 1); |
| 4057 |
} |
| 4058 |
$chunk -= $offset; |
| 4059 |
$secondlist[$_ - 1] = $chunk if($hiddenflag == 0); |
| 4060 |
$secondlist[$_] = $chunk if($hiddenflag == 1); |
| 4061 |
} |
| 4062 |
} |
| 4063 |
if($multi == 0) { |
| 4064 |
# Handle special paranoia mode for single failed tracks. |
| 4065 |
my $save_ripopt = $ripopt; |
| 4066 |
my $save_failflag = $failflag; |
| 4067 |
if($parano == 2 && $failflag == 1) { |
| 4068 |
$ripopt = $ripopt . " -Z" if($parano == 2); |
| 4069 |
print "\n\nTrying again without paranoia.\n" |
| 4070 |
if($verbose > 1); |
| 4071 |
} |
| 4072 |
# Make sure $failflag is set to 0 if success. |
| 4073 |
$failflag = 0; |
| 4074 |
$ripcom = "cdparanoia -d $cddev $riptrackno $ripopt \\ |
| 4075 |
\"$rip_wavdir/$riptrackname.rip\""; |
| 4076 |
$ripcom =~ s/\$/\\\$/g; |
| 4077 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4078 |
# Loop for $verify number of times or until identical rips |
| 4079 |
# are detected. |
| 4080 |
my $xcnter = 1; |
| 4081 |
my @md5 = (); |
| 4082 |
while($xcnter <= $verify) { |
| 4083 |
unless(log_system("$ripcom")) { |
| 4084 |
print "cdparanoia failed on track ", $_, |
| 4085 |
" $tracklist[$_ - 1]\n\n" if($hiddenflag == 0); |
| 4086 |
print "cdparanoia failed on track ", $_, |
| 4087 |
" $tracklist[$_]\n\n" if($hiddenflag == 1); |
| 4088 |
# Create error message in CD-directory for encoder: |
| 4089 |
# don't wait. |
| 4090 |
if($parano == 2 && $save_failflag == 1 || $parano < 2 ) { |
| 4091 |
open(ERO,">>$wavdir/error.log") |
| 4092 |
or print "Can not append to file ", |
| 4093 |
"\"$wavdir/error.log\"!\n"; |
| 4094 |
print ERO "Track $saveriptrackno on CD $artist "; |
| 4095 |
print ERO "- $album failed!\n"; |
| 4096 |
close(ERO); |
| 4097 |
} |
| 4098 |
# Leave loop as we do not want continue with |
| 4099 |
# paranoia mode. |
| 4100 |
$xcnter = $verify; |
| 4101 |
$failflag = $save_failflag + 1; |
| 4102 |
} |
| 4103 |
if($verify > 1) { |
| 4104 |
open(SND, "< $rip_wavdir/$riptrackname.rip") or |
| 4105 |
print "Can not open $rip_wavdir/$riptrackname.rip: ", |
| 4106 |
"$!\n"; |
| 4107 |
binmode(SND); |
| 4108 |
my $md5 = Digest::MD5->new->addfile(*SND)->hexdigest; |
| 4109 |
close(SND); |
| 4110 |
print "\nThe MD5-sum for $rip_wavdir/$riptrackname", |
| 4111 |
".rip is: $md5.\n" if($verbose > 3); |
| 4112 |
my $lastflag = 0; |
| 4113 |
foreach (@md5) { |
| 4114 |
if($md5 eq $_) { |
| 4115 |
print "Rip no. $xcnter resulted in identical ", |
| 4116 |
"rip and will be kept.\n"; |
| 4117 |
$lastflag = 1; |
| 4118 |
last; |
| 4119 |
} |
| 4120 |
else { |
| 4121 |
print "Rip no. $xcnter gave different result, ", |
| 4122 |
"will rip again.\n"; |
| 4123 |
} |
| 4124 |
} |
| 4125 |
last if($lastflag == 1); |
| 4126 |
rename("$rip_wavdir/$riptrackname.rip", |
| 4127 |
"$rip_wavdir/$riptrackname\_$xcnter.rip") |
| 4128 |
if($verify > 1 && $xcnter < $verify); |
| 4129 |
print "Rip file $rip_wavdir/$riptrackname.rip ", |
| 4130 |
"renamed using counter $xcnter.\n" |
| 4131 |
if($verify > 1 && $xcnter < $verify && $verbose > 3); |
| 4132 |
push(@md5, $md5); |
| 4133 |
} |
| 4134 |
$xcnter++; |
| 4135 |
} |
| 4136 |
for(my $c = 1; $c < $xcnter; $c++) { |
| 4137 |
print "Rip file $rip_wavdir/$riptrackname\_$c.rip will ", |
| 4138 |
"be deleted.\n" if($verbose > 3); |
| 4139 |
unlink("$rip_wavdir/$riptrackname\_$c.rip"); |
| 4140 |
} |
| 4141 |
$ripopt = $save_ripopt; |
| 4142 |
} |
| 4143 |
elsif($multi == 1) { |
| 4144 |
my $save_ripopt = $ripopt; |
| 4145 |
my $save_failflag = $failflag; |
| 4146 |
if($parano == 2 && $failflag == 1) { |
| 4147 |
$ripopt .= " -Z" if($parano == 2); |
| 4148 |
print "\n\nTrying again without paranoia.\n" |
| 4149 |
if($verbose > 1); |
| 4150 |
} |
| 4151 |
$ripcom = "cdparanoia -d $cddev $riptrackno $ripopt \\ |
| 4152 |
\"$rip_wavdir/$riptrackname.rip\""; |
| 4153 |
# Log the ripping output only when using paranoia! |
| 4154 |
$ripcom .= " 2>> \"$logfile.$saveriptrackno.txt\"" |
| 4155 |
if($parano == 2 && $failflag == 1 || $parano < 2 ); |
| 4156 |
$ripcom =~ s/\$/\\\$/g; |
| 4157 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4158 |
$failflag = 0; |
| 4159 |
unless(log_system("$ripcom")) { |
| 4160 |
if($parano == 2 && $save_failflag == 1 || $parano < 2 ) { |
| 4161 |
# Append error message to file srXY for rip2m to start |
| 4162 |
# checktrack. |
| 4163 |
open(SRXY,">>$logfile") |
| 4164 |
or print "Can not append to file \"$logfile\"!\n"; |
| 4165 |
print SRXY "\ncdparanoia failed on $tracklist[$_ - 1] " |
| 4166 |
if($hiddenflag == 0); |
| 4167 |
print SRXY "\ncdparanoia failed on $tracklist[$_] " |
| 4168 |
if($hiddenflag == 1); |
| 4169 |
print SRXY "in device $logfile"; |
| 4170 |
close(SRXY); |
| 4171 |
# Create error message in CD-directory for encoder: |
| 4172 |
# don't wait. |
| 4173 |
open(ERO,">>$wavdir/error.log") |
| 4174 |
or print "Can not append to file ", |
| 4175 |
"\"$wavdir/error.log\"!\n"; |
| 4176 |
print ERO "Track $saveriptrackno on CD $artist - $album "; |
| 4177 |
print ERO "failed!\n"; |
| 4178 |
close(ERO); |
| 4179 |
# Kill failed CD only if it is not the last track. Last |
| 4180 |
# track may be data/video track. |
| 4181 |
# I.e. print error message to file srXY.Z.txt, checktrack |
| 4182 |
# will grep for string |
| 4183 |
# "cdparanoia failed" and kill the CD immediately! |
| 4184 |
if($riptrackno != $tracksel[$#tracksel]) { |
| 4185 |
open(SRTF,">>$logfile.$saveriptrackno.txt") |
| 4186 |
or print "Can not append to file ", |
| 4187 |
"\"$logfile.$saveriptrackno.txt\"!\n"; |
| 4188 |
print SRTF "cdparanoia failed on $tracklist[$_ - 1]" |
| 4189 |
if($hiddenflag == 0); |
| 4190 |
print SRTF "cdparanoia failed on $tracklist[$_ - 1]" |
| 4191 |
if($hiddenflag == 1); |
| 4192 |
print SRTF "\nin device $logfile, error !"; |
| 4193 |
close(SRTF); |
| 4194 |
# Create on the fly error message in log-directory. |
| 4195 |
my $devnam = $cddev; |
| 4196 |
$devnam =~ s/.*dev.//; |
| 4197 |
open(ERO,">>$outputdir/failed.log") |
| 4198 |
or print "Can not append to file ", |
| 4199 |
"\"$outputdir/failed.log\"!\n"; |
| 4200 |
print ERO "$artist;$album;$genre;$categ;$cddbid;"; |
| 4201 |
print ERO "$devnam;$hostnam; Cdparanoia failure!\n"; |
| 4202 |
close(ERO); |
| 4203 |
# Now wait to be terminated by checktrack. |
| 4204 |
sleep 360; |
| 4205 |
exit; |
| 4206 |
} |
| 4207 |
} |
| 4208 |
$failflag = $save_failflag + 1; |
| 4209 |
} |
| 4210 |
$ripopt = $save_ripopt; |
| 4211 |
} |
| 4212 |
# This is an awkward workaround introduced because of the |
| 4213 |
# enhanced --paranoia option. Failures on data tracks are not |
| 4214 |
# captured anymore. Force update of error.log for encoder. |
| 4215 |
# Remember, because of option --span $riptrackno can be a |
| 4216 |
# string. Use $saveriptrackno instead. |
| 4217 |
if(! -f "$rip_wavdir/$riptrackname.rip") { |
| 4218 |
if($saveriptrackno == $tracksel[$#tracksel] && |
| 4219 |
$riptrackname =~ /data|video/i) { |
| 4220 |
open(ERO,">>$wavdir/error.log") |
| 4221 |
or print "Can not append to file ", |
| 4222 |
"\"$wavdir/error.log\"!\n"; |
| 4223 |
print ERO "Track $saveriptrackno on CD $artist - $album "; |
| 4224 |
print ERO "failed!\n"; |
| 4225 |
close(ERO); |
| 4226 |
if($multi == 1) { |
| 4227 |
# Append error message to file srXY for rip2m to start |
| 4228 |
# checktrack. |
| 4229 |
open(SRXY,">>$logfile") |
| 4230 |
or print "Can not append to file \"$logfile\"!\n"; |
| 4231 |
print SRXY "\ncdparanoia failed on $tracklist[$_ - 1] " |
| 4232 |
if($hiddenflag == 0); |
| 4233 |
print SRXY "\ncdparanoia failed on $tracklist[$_] " |
| 4234 |
if($hiddenflag == 1); |
| 4235 |
print SRXY "in device $logfile"; |
| 4236 |
close(SRXY); |
| 4237 |
} |
| 4238 |
# Misuse of variable failflag, we don't care, it's the |
| 4239 |
# last track! |
| 4240 |
$failflag = 3; |
| 4241 |
} |
| 4242 |
else { |
| 4243 |
print "\nRip file $riptrackname.rip not found...\n" |
| 4244 |
if($verbose > 2); |
| 4245 |
} |
| 4246 |
} |
| 4247 |
} |
| 4248 |
elsif($ripper == 2 && $rip == 1) { |
| 4249 |
if($trackcn == 1) { |
| 4250 |
$ripopt .= " -q" if($verbose <= 1 && $ripopt !~ /\s-q/); |
| 4251 |
# Cdda2wav has no sample offset, do not use it here and |
| 4252 |
# therefore exclude ripper from checking accuracy. |
| 4253 |
} |
| 4254 |
$ripcom = "cdda2wav -D $cddev -H $ripopt "; |
| 4255 |
# Introduce the span argument into the track number and |
| 4256 |
# recalculate the track length (used in the playlist file). |
| 4257 |
# We use $duration instead of $chunk in the cdparanoia part |
| 4258 |
# above. |
| 4259 |
if($span) { |
| 4260 |
my @bea = split(/-/, $span); |
| 4261 |
my $offset = 0; |
| 4262 |
my $duration = 0; |
| 4263 |
$offset = span_length($bea[0]) if($bea[0]); |
| 4264 |
$duration = span_length($bea[1]) if($bea[1]); |
| 4265 |
if($riptrackno =~ /\+/) { |
| 4266 |
my($i, $j) = split(/\+/, $riptrackno); |
| 4267 |
if($hiddenflag == 0) { |
| 4268 |
if($secondlist[$j - 1] < $duration) { |
| 4269 |
$duration = 0; |
| 4270 |
} |
| 4271 |
else { |
| 4272 |
$duration = $secondlist[$_ - 1] = |
| 4273 |
$secondlist[$_ - 1] - $secondlist[$j - 1] + |
| 4274 |
$duration - $offset; |
| 4275 |
} |
| 4276 |
} |
| 4277 |
elsif($hiddenflag == 1) { |
| 4278 |
# TODO: Oops, why is the counter reduced? |
| 4279 |
if($secondlist[$j - 1] < $duration) { |
| 4280 |
$duration = 0; |
| 4281 |
} |
| 4282 |
else { |
| 4283 |
$duration = $secondlist[$_] = $secondlist[$_] - |
| 4284 |
$secondlist[$j] + $duration - $offset; |
| 4285 |
} |
| 4286 |
} |
| 4287 |
} |
| 4288 |
else { |
| 4289 |
if($hiddenflag == 0 && $secondlist[$_ - 1] < $duration) { |
| 4290 |
$duration = 0; |
| 4291 |
} |
| 4292 |
elsif($hiddenflag == 1 && $secondlist[$_] < $duration) { |
| 4293 |
$duration = 0; |
| 4294 |
} |
| 4295 |
else { |
| 4296 |
$duration -= int($offset); |
| 4297 |
$secondlist[$_ - 1] = $duration if($hiddenflag == 0); |
| 4298 |
$secondlist[$_] = $duration if($hiddenflag == 1); |
| 4299 |
} |
| 4300 |
} |
| 4301 |
$duration = 0 if($duration < 0); |
| 4302 |
$offset *= 75; |
| 4303 |
$ripcom .= "-o $offset "; |
| 4304 |
$ripcom .= "-d $duration " if($duration > 0); |
| 4305 |
} |
| 4306 |
if($multi == 0) { |
| 4307 |
$ripcom .= "-t $riptrackno \"$rip_wavdir/$riptrackname\""; |
| 4308 |
$ripcom .= "_rip"; |
| 4309 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4310 |
$ripcom =~ s/\$/\\\$/g; |
| 4311 |
# Loop for $verify number of times or until identical rips |
| 4312 |
# are detected. |
| 4313 |
my $xcnter = 1; |
| 4314 |
my @md5 = (); |
| 4315 |
while($xcnter <= $verify) { |
| 4316 |
unless(log_system("$ripcom")) { |
| 4317 |
print "cdda2wav failed on <$tracklist[$_ - 1]>.\n" |
| 4318 |
if($hiddenflag == 0); |
| 4319 |
print "cdda2wav failed on <$tracklist[$_]>.\n" |
| 4320 |
if($hiddenflag == 1); |
| 4321 |
open(ERO,">>$wavdir/error.log") |
| 4322 |
or print "Can not append to file ", |
| 4323 |
"\"$wavdir/error.log\"!\n"; |
| 4324 |
print ERO "Track $saveriptrackno on CD $artist - "; |
| 4325 |
print ERO "$album failed!\n"; |
| 4326 |
close(ERO); |
| 4327 |
# Leave loop as we do not want continue with |
| 4328 |
# paranoia mode. |
| 4329 |
$xcnter = $verify; |
| 4330 |
$failflag++; |
| 4331 |
} |
| 4332 |
if($verify > 1) { |
| 4333 |
open(SND, "< $rip_wavdir/$riptrackname\_rip.wav") or |
| 4334 |
print "Can not open $rip_wavdir/$riptrackname\_rip", |
| 4335 |
".wav: $!\n"; |
| 4336 |
binmode(SND); |
| 4337 |
my $md5 = Digest::MD5->new->addfile(*SND)->hexdigest; |
| 4338 |
close(SND); |
| 4339 |
print "\nThe MD5-sum for $rip_wavdir/$riptrackname", |
| 4340 |
"\_rip.wav is: $md5.\n" if($verbose > 3); |
| 4341 |
my $lastflag = 0; |
| 4342 |
foreach (@md5) { |
| 4343 |
if($md5 eq $_) { |
| 4344 |
print "Rip no. $xcnter resulted in identical ", |
| 4345 |
"rip and will be kept.\n"; |
| 4346 |
$lastflag = 1; |
| 4347 |
last; |
| 4348 |
} |
| 4349 |
else { |
| 4350 |
print "Rip no. $xcnter gave different result, ", |
| 4351 |
"will rip again.\n"; |
| 4352 |
} |
| 4353 |
} |
| 4354 |
last if($lastflag == 1); |
| 4355 |
rename("$rip_wavdir/$riptrackname\_rip.wav", |
| 4356 |
"$rip_wavdir/$riptrackname\_$xcnter.rip") |
| 4357 |
if($verify > 1 && $xcnter < $verify); |
| 4358 |
print "Rip file $rip_wavdir/$riptrackname\_rip.wav ", |
| 4359 |
"renamed using counter $xcnter.\n" |
| 4360 |
if($verify > 1 && $xcnter < $verify && $verbose > 3); |
| 4361 |
push(@md5, $md5); |
| 4362 |
} |
| 4363 |
$xcnter++; |
| 4364 |
} |
| 4365 |
for(my $c = 1; $c < $xcnter; $c++) { |
| 4366 |
print "Rip file $rip_wavdir/$riptrackname\_$c.rip will ", |
| 4367 |
"be deleted.\n" if($verbose > 3); |
| 4368 |
unlink("$rip_wavdir/$riptrackname\_$c.rip"); |
| 4369 |
} |
| 4370 |
} |
| 4371 |
elsif($multi == 1) { |
| 4372 |
$ripcom .= "-t $riptrackno \"$rip_wavdir/$riptrackname\_rip\" \\ |
| 4373 |
2>> \"$logfile.$saveriptrackno.txt\""; |
| 4374 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4375 |
$ripcom =~ s/\$/\\\$/g; |
| 4376 |
unless(log_system("$ripcom")) { |
| 4377 |
# Append error message to file srXY for rip2m to start |
| 4378 |
# checktrack. |
| 4379 |
open(SRXY,">>$logfile") |
| 4380 |
or print "Can not append to file \"$logfile\"!\n"; |
| 4381 |
print SRXY "\ncdda2wav failed on $tracklist[$_ - 1] in " |
| 4382 |
if($hiddenflag == 0); |
| 4383 |
print SRXY "\ncdda2wav failed on $tracklist[$_] in " |
| 4384 |
if($hiddenflag == 1); |
| 4385 |
print SRXY "device $logfile"; |
| 4386 |
close(SRXY); |
| 4387 |
# Create error message in CD-directory for encoder: |
| 4388 |
# don't wait. |
| 4389 |
open(ERO,">>$wavdir/error.log") |
| 4390 |
or print "Can not append to file ", |
| 4391 |
"\"$wavdir/error.log\"!\n"; |
| 4392 |
print ERO "Track $saveriptrackno on CD $artist - $album "; |
| 4393 |
print ERO "failed!\n"; |
| 4394 |
close(ERO); |
| 4395 |
# Kill failed CD only if it is not the last track. |
| 4396 |
# Last track may be data/video track. |
| 4397 |
# I.e. print error message to file srXY.Z.txt, checktrack |
| 4398 |
# will grep for string |
| 4399 |
# "cdparanoia failed" and kill the CD immediately! |
| 4400 |
if($riptrackno != $tracksel[$#tracksel]) { |
| 4401 |
open(SRTF,">>$logfile.$saveriptrackno.txt") |
| 4402 |
or print "Can not append to file ", |
| 4403 |
"\"$logfile.$saveriptrackno.txt\"!\n"; |
| 4404 |
print SRTF "cdda2wav failed on $tracklist[$_ - 1]\n" |
| 4405 |
if($hiddenflag == 0); |
| 4406 |
print SRTF "cdda2wav failed on $tracklist[$_]\n" |
| 4407 |
if($hiddenflag == 1); |
| 4408 |
print SRTF "in device $logfile, error !"; |
| 4409 |
close(SRTF); |
| 4410 |
# Create on the fly error message in log-directory. |
| 4411 |
my $devnam = $cddev; |
| 4412 |
$devnam =~ s/.*dev.//; |
| 4413 |
open(ERO,">>$outputdir/failed.log") |
| 4414 |
or print "Can not append to file ", |
| 4415 |
"\"$outputdir/failed.log\"!\n"; |
| 4416 |
print ERO "$artist;$album;$genre;$categ;$cddbid;"; |
| 4417 |
print ERO "$devnam;$hostnam; Cdda2wav failure!\n"; |
| 4418 |
close(ERO); |
| 4419 |
# Now wait to be terminated by checktrack. |
| 4420 |
sleep 360; |
| 4421 |
exit; |
| 4422 |
} |
| 4423 |
} |
| 4424 |
} |
| 4425 |
print "\n" if($verbose > 1); |
| 4426 |
} |
| 4427 |
elsif($ripper == 3 && $rip == 1) { |
| 4428 |
# Start renaming the files to the ripper format to be treated. |
| 4429 |
my $riptracknoF = sprintf("%02d", $saveriptrackno); |
| 4430 |
# Test presence of file in case ripper failed on a data track. |
| 4431 |
if(-f "$wavdir/$riptracknoF\_Morituri-Rip.wav") { |
| 4432 |
log_system( |
| 4433 |
"cp \"$wavdir/$riptracknoF\_Morituri-Rip.wav\" \\ |
| 4434 |
\"$wavdir/$riptrackname.rip\"") |
| 4435 |
or print "Can not copy $riptracknoF\_Morituri-Rip.wav ", |
| 4436 |
"to \"$wavdir/$riptrackname.rip\": $!\n"; |
| 4437 |
} |
| 4438 |
elsif(-f "$wavdir/$mori_dirs/$riptracknoF\_Morituri-Rip.wav") { |
| 4439 |
log_system( |
| 4440 |
"mv \"$wavdir/$mori_dirs/$riptracknoF\_Morituri-Rip.wav\" \\ |
| 4441 |
\"$wavdir/$riptracknoF\_Morituri-Rip.wav\"") |
| 4442 |
or print "Can not move $riptracknoF\_Morituri-Rip.wav ", |
| 4443 |
"to \"$wavdir/$riptrackname.rip\": $!\n"; |
| 4444 |
log_system( |
| 4445 |
"cp \"$wavdir/$riptracknoF\_Morituri-Rip.wav\" \\ |
| 4446 |
\"$wavdir/$riptrackname.rip\"") |
| 4447 |
or print "Can not copy $riptracknoF\_Morituri-Rip.wav ", |
| 4448 |
"to \"$wavdir/$riptrackname.rip\": $!\n"; |
| 4449 |
} |
| 4450 |
else { |
| 4451 |
open(ERO,">>$wavdir/error.log") |
| 4452 |
or print "Can not append to file ", |
| 4453 |
"\"$wavdir/error.log\"!\n"; |
| 4454 |
print ERO "Track $saveriptrackno on CD $artist "; |
| 4455 |
print ERO "- $album failed!\n"; |
| 4456 |
close(ERO); |
| 4457 |
# Prevent creating inf file. |
| 4458 |
# Misuse of variable failflag, we don't care as with ripper |
| 4459 |
# rip (Morituri) we do not verify the same track several |
| 4460 |
# times and do not want to spoil option inf in case loop |
| 4461 |
# is used. |
| 4462 |
$failflag = 3 if($inf == 1); |
| 4463 |
} |
| 4464 |
} |
| 4465 |
elsif($ripper == 4 && $rip == 1) { |
| 4466 |
my $cdd_dev = $cddev; |
| 4467 |
$cdd_dev =~ s/^\/dev\/r//; |
| 4468 |
$cdd_dev =~ s/c$//; |
| 4469 |
$ripcom = "cdd -t $riptrackno -q -f $cdd_dev - 2> /dev/null \\ |
| 4470 |
| sox -t cdr -x - \"$rip_wavdir/$riptrackname.wav\""; |
| 4471 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4472 |
unless(log_system("$ripcom")) { |
| 4473 |
die "cdd failed on $tracklist[$_ - 1]"; |
| 4474 |
} |
| 4475 |
} |
| 4476 |
elsif($rip == 1) { |
| 4477 |
print "No CD Ripper defined.\n"; |
| 4478 |
} |
| 4479 |
|
| 4480 |
redo if($ripper == 1 && $failflag == 1 && $parano == 2); |
| 4481 |
|
| 4482 |
# If we had problems in case total path is too long (note: the |
| 4483 |
# riptrackname is still the short one): |
| 4484 |
if(length($riptrackname) + length($wavdir) > 250) { |
| 4485 |
log_system("cd \"$wavdir\" && mv \"/tmp/$riptrackname.rip\" \"$riptrackname.rip\""); |
| 4486 |
} |
| 4487 |
if($ripper == 2 && $wavdir =~ /\./) { |
| 4488 |
if($riptrackname =~ /\./) { |
| 4489 |
# See below for comments on this. |
| 4490 |
my $cddatrackname = $riptrackname . "end"; |
| 4491 |
my @riptrackname = split(/\./, $cddatrackname); |
| 4492 |
delete($riptrackname[$#riptrackname]); |
| 4493 |
$cddatrackname = join('.', @riptrackname); |
| 4494 |
log_system("cd \"$wavdir\" && mv \"/tmp/$cddatrackname.wav\" \"$cddatrackname.wav\""); |
| 4495 |
} |
| 4496 |
else { |
| 4497 |
log_system("cd \"$wavdir\" && mv \"/tmp/$riptrackname\_rip.wav\" \"$riptrackname\_rip.wav\""); |
| 4498 |
} |
| 4499 |
} |
| 4500 |
|
| 4501 |
# Cdda2wav output is not easy to handle. Everything beyond a last |
| 4502 |
# period . has been erased. Example: riptrackname is something |
| 4503 |
# like "never ending...", then we assign cdda2wav in the above |
| 4504 |
# section to rip a file called: "never ending..._rip", but |
| 4505 |
# cdda2wav misbehaves and the file is called "never ending...". |
| 4506 |
# Therefore rename the ripped file to the standard name |
| 4507 |
# riptrackname.rip first (if cdda2wav was used). |
| 4508 |
if($ripper == 2) { |
| 4509 |
if($riptrackname =~ /\./) { |
| 4510 |
# But split is too clever! If a track name ends with "bla..." |
| 4511 |
# all points get lost, so we've to add a word at the end! |
| 4512 |
my $cddatrackname = $riptrackname . "end"; |
| 4513 |
my @riptrackname = split(/\./, $cddatrackname); |
| 4514 |
delete($riptrackname[$#riptrackname]); |
| 4515 |
$cddatrackname = join('.', @riptrackname); |
| 4516 |
rename("$wavdir/$cddatrackname.wav", |
| 4517 |
"$wavdir/$riptrackname.rip"); |
| 4518 |
} |
| 4519 |
else { |
| 4520 |
rename("$wavdir/$riptrackname\_rip.wav", |
| 4521 |
"$wavdir/$riptrackname.rip"); |
| 4522 |
} |
| 4523 |
} |
| 4524 |
# Before checking for gaps and silence in wavs make sure to save |
| 4525 |
# an original copy of the rip rile in case accuracy check should |
| 4526 |
# be done once all tracks are ripped. |
| 4527 |
# Note that we're not going to check accuracy if option merge has |
| 4528 |
# been used, so we can assume that $riptrackno is a single number, |
| 4529 |
# nevertheless we use $saveriptrackno. |
| 4530 |
if($accuracy == 1 and $ripper != 3) { |
| 4531 |
my $riptracknoF = sprintf("%02d", $saveriptrackno); |
| 4532 |
# Test presence of file in case ripper failed on a data track. |
| 4533 |
if(-f "$wavdir/$riptrackname.rip") { |
| 4534 |
log_system( |
| 4535 |
"cp \"$wavdir/$riptrackname.rip\" \\ |
| 4536 |
\"$wavdir/$riptracknoF\_Morituri-Rip.wav\"") |
| 4537 |
or print "Can not copy $riptrackname to ", |
| 4538 |
"\"$wavdir/$riptracknoF\_Morituri-Rip.rip\": $!\n"; |
| 4539 |
} |
| 4540 |
} |
| 4541 |
# Check for gaps and silence in tracks. |
| 4542 |
my @times = (0); |
| 4543 |
my $save_cdtocn = $cdtocn; |
| 4544 |
if(-r "$wavdir/$riptrackname.rip") { |
| 4545 |
# Remember: $saveriptrackno is the single track number, whereas |
| 4546 |
# $riptrackno may hold an interval if option merge is used. |
| 4547 |
if($ghost == 1 && $failflag == 0) { |
| 4548 |
@times = get_chunks($saveriptrackno, $riptrackname); |
| 4549 |
unless($times[0] eq "blank") { |
| 4550 |
(my $shorten, @times) = |
| 4551 |
split_chunks($saveriptrackno, "$riptrackname", |
| 4552 |
$cdtocn, @times); |
| 4553 |
($cdtocn, $cue_point) = |
| 4554 |
rename_chunks($saveriptrackno, "$riptrackname", |
| 4555 |
"$rip_wavnam", |
| 4556 |
$cdtocn, $cue_point, $shorten, |
| 4557 |
$artistag, $riptracktag, @times); |
| 4558 |
} |
| 4559 |
} |
| 4560 |
} |
| 4561 |
# A blank track has been deleted. |
| 4562 |
$cdtocn-- if(($cdtoc == 1 || $cdcue > 0) && $times[0] eq "blank"); |
| 4563 |
next if($times[0] eq "blank"); |
| 4564 |
# |
| 4565 |
# Final stuff. |
| 4566 |
# Rename rip file to a wav for encoder so that it will be picked |
| 4567 |
# up by the encoder background process. |
| 4568 |
# If the track has been splitted into chunks, check if the file |
| 4569 |
# name holds information about the ghost song. If so, don't use it |
| 4570 |
# in the file name! Change in 4.0 |
| 4571 |
if(defined $times[1] && $times[1] =~ /\d\s\d/) { |
| 4572 |
if($riptracktag =~ /\// and ( |
| 4573 |
$vatag == 0 or ($vatag == 1 and $delim and $delim !~ /\//))) { |
| 4574 |
my ($wavname, $dummy) = split(/\//, $riptracktag); |
| 4575 |
$wavname =~ s/^\s+|\s+$//; |
| 4576 |
# The new riptracktag is needed for inf files. |
| 4577 |
$riptracktag = $wavname; |
| 4578 |
$wavname = clean_all($wavname); |
| 4579 |
$wavname = clean_name($wavname); |
| 4580 |
$wavname = clean_chars($wavname) if($chars); |
| 4581 |
$wavname = change_case($wavname, "t"); |
| 4582 |
$wavname =~ s/ /_/g if($underscore == 1); |
| 4583 |
$wavname = get_trackname($saveriptrackno, $wavname, 0 , $trackartist, $wavname); |
| 4584 |
rename("$wavdir/$riptrackname.rip", "$wavdir/$wavname.wav"); |
| 4585 |
$riptrackname = $wavname; |
| 4586 |
} |
| 4587 |
else { |
| 4588 |
log_info("perl rename \"$wavdir/$riptrackname.rip\", \"$wavdir/$riptrackname.wav\""); |
| 4589 |
rename("$wavdir/$riptrackname.rip", "$wavdir/$riptrackname.wav"); |
| 4590 |
} |
| 4591 |
} |
| 4592 |
else { |
| 4593 |
log_info("perl rename \"$wavdir/$riptrackname.rip\", \"$wavdir/$riptrackname.wav\""); |
| 4594 |
rename("$wavdir/$riptrackname.rip", "$wavdir/$riptrackname.wav"); |
| 4595 |
} |
| 4596 |
|
| 4597 |
# Update cue file if span is used with the true track length. |
| 4598 |
if($cdcue > 0 && $span) { |
| 4599 |
my $duration = 0; |
| 4600 |
$duration = $secondlist[$_ - 1] if($hiddenflag == 0); |
| 4601 |
$duration = $secondlist[$_] if($hiddenflag == 1); |
| 4602 |
$duration = $duration * 75 + $framelist_orig[$_]; |
| 4603 |
my $points = track_length($duration, 2); |
| 4604 |
open(CDCUE, "<$wavdir/cd.cue") |
| 4605 |
or print "Can not read file cd.cue!\n"; |
| 4606 |
my @cuelines = <CDCUE>; |
| 4607 |
close(CDCUE); |
| 4608 |
open(CDCUE, ">$wavdir/cd.cue") |
| 4609 |
or print "Can not write to file \"$wavdir/cd.cue\"!\n"; |
| 4610 |
foreach (@cuelines) { |
| 4611 |
s/INDEX 01 cue-span-seconds/INDEX 01 $points/; |
| 4612 |
print CDCUE $_; |
| 4613 |
} |
| 4614 |
close(CDCUE); |
| 4615 |
} |
| 4616 |
# Delete the "single-track" wav if cdcue is used. The track is |
| 4617 |
# already merged, no need to keep it. |
| 4618 |
log_info("perl unlink $wavdir/$riptrackname.wav") |
| 4619 |
if($sshflag == 0 && $cdcue > 0); |
| 4620 |
unlink("$wavdir/$riptrackname.wav") |
| 4621 |
if($sshflag == 0 && $cdcue > 0); |
| 4622 |
md5_sum("$wavdir", "$riptrackname.wav", 0) |
| 4623 |
if($md5sum == 1 && $normalize == 0 && |
| 4624 |
$wav == 1 && $failflag == 0); |
| 4625 |
# Writing inf files for cdburning. |
| 4626 |
# We use the $save_cdtocn counter as track counter instead of the |
| 4627 |
# $riptrackno because $riptrackno might hold a span argument and |
| 4628 |
# does not reflect the exact number of tracks created. |
| 4629 |
# Use failflag == 3 to prevent writing inf file for failed data |
| 4630 |
# track. |
| 4631 |
# Use $artist instead of $trackartist for get_trackname used on |
| 4632 |
# ghost songs (only). |
| 4633 |
if($inf >= 1 && $failflag < 3) { |
| 4634 |
# If the file name was too long for ripper, $riptrackname holds |
| 4635 |
# the short name, use the original copy instead. |
| 4636 |
$trackstart = write_inf($wavdir, $riptrackname, $artistag, |
| 4637 |
$albumtag, $riptracktag, $save_cdtocn, $cdtocn, $trackstart, |
| 4638 |
$artist, $tracktitle, $rip_wavnam); |
| 4639 |
} |
| 4640 |
chmod oct($fpermission), "$wavdir/$riptrackname.wav" |
| 4641 |
if($fpermission); |
| 4642 |
unlink("$logfile.$riptrackno.txt") if($multi == 1); |
| 4643 |
$failflag = 0; |
| 4644 |
|
| 4645 |
if($normalize == 0 and $cdcue == 0) { |
| 4646 |
# Start the encoder in the background, but only once. |
| 4647 |
if($startenc == 0 && $encode == 1) { |
| 4648 |
my $encstart = sprintf("%02d:%02d", |
| 4649 |
sub {$_[2], $_[1]}->(localtime)); |
| 4650 |
chomp $encstart; |
| 4651 |
if($multi == 1) { |
| 4652 |
open(SRXY,">>$logfile") |
| 4653 |
or print "Can not append to file \"$logfile\"!\n"; |
| 4654 |
print SRXY "\nEncoding started: $encstart"; |
| 4655 |
close(SRXY); |
| 4656 |
} |
| 4657 |
$startenc = 1; |
| 4658 |
open(ENCLOG,">$wavdir/enc.log"); |
| 4659 |
close(ENCLOG); |
| 4660 |
unless(fork) { |
| 4661 |
enc_cd(); |
| 4662 |
} |
| 4663 |
} |
| 4664 |
} |
| 4665 |
|
| 4666 |
# Print encoder messages saved in enc.log not to spoil the |
| 4667 |
# ripper output. Maybe it would be better to test existence of the |
| 4668 |
# file instead of testing all these conditions. |
| 4669 |
if($encode == 1 && $normalize == 0 && $cdcue == 0) { |
| 4670 |
$encline = enc_report($encline, $trackcn); |
| 4671 |
} |
| 4672 |
} |
| 4673 |
|
| 4674 |
# Check for accuracy, let encoder fill enc.log not to spoil |
| 4675 |
# output, operator needs to know if Morituri starts re-ripping. |
| 4676 |
# Question: should the offset be added via option $ripopt, but |
| 4677 |
# what if other arguments are passed for ripper of first |
| 4678 |
# instance? |
| 4679 |
if($accuracy == 1 && $ripper != 3) { |
| 4680 |
print "Checking accuracy of wavs in \"$wavdir\" using rip:\n" |
| 4681 |
if($verbose > 3); |
| 4682 |
$ripcom = "rip cd -d $cddev rip --profile=wav -U \\ |
| 4683 |
--track-template=\"%t\_Morituri-Rip\" \\ |
| 4684 |
--disc-template=\"\" -O \"$wavdir\""; |
| 4685 |
$ripcom .= " -o $offset" if($offset < 0 || $offset > 0); |
| 4686 |
# TODO $ripcom .= " $ripopt" if($ripopt ne ""); |
| 4687 |
$ripcom = "nice -n $nicerip " . $ripcom if($nicerip != 0); |
| 4688 |
|
| 4689 |
unless(log_system("$ripcom")) { |
| 4690 |
print "Morituri (rip) failed checking accuracy of wavs."; |
| 4691 |
} |
| 4692 |
print "\nChecking accuracy finished.\n\n" if($verbose > 3); |
| 4693 |
if($encode == 1 && $normalize == 0 && $cdcue == 0) { |
| 4694 |
$encline = enc_report($encline, $trackcn); |
| 4695 |
} |
| 4696 |
} |
| 4697 |
|
| 4698 |
# If morituri had to rip into an existing dir, delete the dummy |
| 4699 |
# direcotry in case it is empty. |
| 4700 |
if($ripper == 3 && $rip == 1 && -d "$wavdir/$mori_dirs") { |
| 4701 |
# I don't like the -p option. |
| 4702 |
log_system("rmdir -p \"$wavdir/$mori_dirs\" 2> /dev/null"); |
| 4703 |
} |
| 4704 |
|
| 4705 |
unlink("$wavdir/enc.log") if(-r "$wavdir/enc.log"); |
| 4706 |
|
| 4707 |
# Hack to tell the child process that we are waiting for it to |
| 4708 |
# finish. |
| 4709 |
my $ripend = sprintf("%02d:%02d", sub {$_[2], $_[1]}->(localtime)); |
| 4710 |
open(ERR, ">>$wavdir/error.log") |
| 4711 |
or print "Can not append to file error.log!\n"; |
| 4712 |
print ERR "The audio CD ripper reports: all done!\n"; |
| 4713 |
print ERR "Ripping ended: $ripend\n"; |
| 4714 |
close(ERR); |
| 4715 |
if($multi == 1) { |
| 4716 |
open(SRXY,">>$logfile") |
| 4717 |
or print "Can not append to file \"$logfile\"!\n"; |
| 4718 |
print SRXY "\nRipping complete: $ripend"; |
| 4719 |
close(SRXY); |
| 4720 |
} |
| 4721 |
} |
| 4722 |
######################################################################## |
| 4723 |
# |
| 4724 |
# Normalize the wav. |
| 4725 |
# Using normalize will disable parallel ripping & encoding. |
| 4726 |
# |
| 4727 |
sub norm_cd { |
| 4728 |
|
| 4729 |
print "Normalizing the wav-files...\n" if($verbose >= 1); |
| 4730 |
my($escdir, $norm, $normtrackname); |
| 4731 |
$escdir = $wavdir; |
| 4732 |
$escdir = esc_char($escdir, 0); |
| 4733 |
|
| 4734 |
my $album = clean_all($album_utf8); |
| 4735 |
$album = clean_name($album); |
| 4736 |
$album = clean_chars($album) if($chars); |
| 4737 |
$album =~ s/ /_/g if($underscore == 1); |
| 4738 |
$album = esc_char($album, 0); |
| 4739 |
# New parameters for tracktemplate used for file names only, i.e. |
| 4740 |
# less verbose than the corresponding tags $artistag and tracktag. |
| 4741 |
my $trackartist; |
| 4742 |
my $tracktitle; |
| 4743 |
|
| 4744 |
my ($delim, $dummy) = check_va(0) if($vatag > 0); |
| 4745 |
$delim = quotemeta($delim) if(defined $delim); |
| 4746 |
|
| 4747 |
# Generate file list to be processed: |
| 4748 |
if($book == 1 or $cdcue > 0) { |
| 4749 |
$normtrackname = "$escdir/$album.wav"; |
| 4750 |
} |
| 4751 |
else { |
| 4752 |
foreach (@seltrack) { |
| 4753 |
my $riptracktag = $tracktags[$_ - 1]; |
| 4754 |
$riptracktag = $tracktags[$_] if($hiddenflag == 1); |
| 4755 |
|
| 4756 |
# Split the tracktag into its artist part and track part if |
| 4757 |
# VA style is used, no messages to be printed. |
| 4758 |
if($va_flag > 0 && $riptracktag =~ /$delim/) { |
| 4759 |
($trackartist, $tracktitle) = split_tags($riptracktag, $delim); |
| 4760 |
} |
| 4761 |
# Actually, we do not need the "full" tags, only names for files. |
| 4762 |
$trackartist = clean_all($trackartist); |
| 4763 |
$trackartist = clean_name($trackartist); |
| 4764 |
$trackartist = clean_chars($trackartist); |
| 4765 |
$tracktitle = clean_all($tracktitle); |
| 4766 |
$tracktitle = clean_name($tracktitle); |
| 4767 |
$tracktitle = clean_chars($tracktitle); |
| 4768 |
$trackartist =~ s/ /_/g if($underscore == 1); |
| 4769 |
$tracktitle =~ s/ /_/g if($underscore == 1); |
| 4770 |
|
| 4771 |
my $riptrackname = get_trackname($_, $tracklist[$_ - 1], 0, $trackartist, $tracktitle); |
| 4772 |
$riptrackname = get_trackname($_, $tracklist[$_], 0, $trackartist, $tracktitle) |
| 4773 |
if($hiddenflag == 1); |
| 4774 |
|
| 4775 |
# If the file name was too long for ripper, look for special |
| 4776 |
# name. |
| 4777 |
my $wavname = $riptrackname; |
| 4778 |
if(length($riptrackname) + length($wavdir) > 190) { |
| 4779 |
$wavname = get_trackname($_, $_ . "short", "short", $trackartist, $tracktitle); |
| 4780 |
} |
| 4781 |
# Normalize is picky about certain characters - get them |
| 4782 |
# escaped! |
| 4783 |
$wavname = esc_char($wavname, 0); |
| 4784 |
$normtrackname .= "$escdir/$wavname.wav" . " \\\n "; |
| 4785 |
} |
| 4786 |
} |
| 4787 |
$normtrackname =~ s/\s*$//; |
| 4788 |
$normtrackname =~ s/\$/\\\$/g; |
| 4789 |
|
| 4790 |
# Add verbosity: |
| 4791 |
$normopt .= "q" if($verbose == 0); |
| 4792 |
$normopt .= "v" if($verbose >= 2 && $normopt !~ /q/); |
| 4793 |
$normopt .= "vv" if($verbose >= 4 && $normopt !~ /q/); |
| 4794 |
|
| 4795 |
$norm = "$normcmd $normopt -- $normtrackname"; |
| 4796 |
|
| 4797 |
if(log_system("$norm")) { |
| 4798 |
log_info("\nNormalizing complete.\n"); |
| 4799 |
print "\nNormalizing complete.\n" if($verbose >= 1); |
| 4800 |
} |
| 4801 |
else { |
| 4802 |
print "\nWarning: normalizing failed.\n"; |
| 4803 |
} |
| 4804 |
} |
| 4805 |
######################################################################## |
| 4806 |
# |
| 4807 |
# Encode the wav. |
| 4808 |
# This runs as a separate process from the main program which |
| 4809 |
# allows it to continuously encode as the ripping is being done. |
| 4810 |
# The encoder will also wait for the ripped wav in-case the encoder |
| 4811 |
# is faster than the CDROM. In fact it will be waited 3 times the length |
| 4812 |
# of the track to be encoded. |
| 4813 |
# |
| 4814 |
sub enc_cd { |
| 4815 |
my ($enc, $riptrackno, $riptrackname, $riptracktag, $suffix, $tagtrackno); |
| 4816 |
my ($albumlametag, $albumartistlametag, $artislametag, $commentlametag, $tracklametag); |
| 4817 |
my ($ripcomplete, $trackcn, $totalencs) = (0, 0, 0); |
| 4818 |
my $lastskip = $tracksel[0]; |
| 4819 |
my $resumenc = $resume; |
| 4820 |
my $encodername = ""; |
| 4821 |
my @md5tracks = (); # List of tracks to be re-taged (coverart etc.). |
| 4822 |
|
| 4823 |
# Cleaning. |
| 4824 |
my $albumtag = clean_all($album_utf8); |
| 4825 |
my $artistag = clean_all($artist_utf8); |
| 4826 |
my $album = $albumtag; |
| 4827 |
my $artist = $artistag; |
| 4828 |
my $albumartistag = $artistag; |
| 4829 |
$album = clean_name($album); |
| 4830 |
$artist = clean_name($artist); |
| 4831 |
$album = clean_chars($album) if($chars); |
| 4832 |
$artist = clean_chars($artist) if($chars); |
| 4833 |
$album =~ s/ /_/g if($underscore == 1); |
| 4834 |
$artist =~ s/ /_/g if($underscore == 1); |
| 4835 |
|
| 4836 |
# New parameters for tracktemplate used for file names only, i.e. |
| 4837 |
# less verbose than the corresponding tags $artistag and tracktag. |
| 4838 |
my $trackartist; |
| 4839 |
my $tracktitle; |
| 4840 |
|
| 4841 |
# Create special variables for Lame-tags because of UTF8 problem. |
| 4842 |
if($utftag == 0) { |
| 4843 |
$albumartistlametag = back_encoding($albumartistag); |
| 4844 |
$albumlametag = back_encoding($albumtag); |
| 4845 |
$commentlametag = back_encoding($commentag); |
| 4846 |
} |
| 4847 |
else{ |
| 4848 |
$albumlametag = $albumtag; |
| 4849 |
$commentlametag = $commentag; |
| 4850 |
} |
| 4851 |
# Strange timeout to prevent warnings on ghost.logs when using rip |
| 4852 |
# (Morituri) But this might not solve the weird behaviour. |
| 4853 |
sleep 6 if($ghost == 1 && $ripper == 3); |
| 4854 |
|
| 4855 |
# Write header of playlist file. Prevent overwriting of playlist file |
| 4856 |
# if operator re-encodes into same directory. Furthermore we do not |
| 4857 |
# have any clue about what effects have been applied to the existing |
| 4858 |
# sound files. Probably better to copy existing playlist files in |
| 4859 |
# case of re-encoding. Wrong: In case tags have been updated the |
| 4860 |
# the playlist should be rewritten and existing playlist should not |
| 4861 |
# be overwritten... |
| 4862 |
my $playfile; |
| 4863 |
if($playlist >= 1 or $cue > 0) { |
| 4864 |
$playfile = "$artist" . " - " . "$album" . ".m3u"; |
| 4865 |
$playfile =~ s/\.m3u$/.rec/ if($rip == 0); |
| 4866 |
$playfile =~ s/ /_/g if($underscore == 1); |
| 4867 |
if($limit_flag == 255) { |
| 4868 |
$playfile = substr($playfile, 0, 250); |
| 4869 |
} |
| 4870 |
# Do not overwrite existing playlist files from re-encoding. |
| 4871 |
# Rename existing playlist file. |
| 4872 |
if(-f "$wavdir/$playfile" and |
| 4873 |
($rip == 0 or $addtrackoffset == 1 or $trackoffset > 0)) { |
| 4874 |
my $nplayfile = $playfile; |
| 4875 |
$nplayfile =~ s/\.rec$/_rec.bkp/; |
| 4876 |
# Warn if the backup file exists. |
| 4877 |
if(-r "$wavdir/$nplayfile") { |
| 4878 |
print "Existing playlist backup file $nplayfile will be ", |
| 4879 |
"orverwritten, too many checks failed.\n" |
| 4880 |
if($verbose >= 3); |
| 4881 |
} |
| 4882 |
rename("$wavdir/$playfile", "$wavdir/$nplayfile"); |
| 4883 |
print "Existing $playfile renamed to $nplayfile.\n" |
| 4884 |
if($verbose >= 3); |
| 4885 |
} |
| 4886 |
my $time = sprintf("%02d:%02d:%02d", |
| 4887 |
sub {$_[2], $_[1], $_[0]}->(localtime)); |
| 4888 |
my $date = sprintf("%04d-%02d-%02d", |
| 4889 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 4890 |
open(PLST, ">$wavdir/$playfile") or |
| 4891 |
print "Can't open $wavdir/$playfile! $!\n"; |
| 4892 |
print PLST "#EXTM3U\n"; |
| 4893 |
print PLST "#CREATION=$date $time Ripit verion $version\n"; |
| 4894 |
print PLST "#CDDBID=$cddbid\n" if($cddbid ne ""); |
| 4895 |
print PLST "#DISCID=$discid\n" |
| 4896 |
if(defined $discid && $discid ne ""); # New 4.0 |
| 4897 |
print PLST "#MBREID=", $cd{mbreid}, "\n" |
| 4898 |
if(defined $cd{mbreid} && $cd{mbreid} ne ""); # New 4.0 |
| 4899 |
} |
| 4900 |
|
| 4901 |
# Read the cdcue file (once) to be copied to the encoder directories. |
| 4902 |
my @cuelines = (); |
| 4903 |
if($cdcue > 0) { |
| 4904 |
open(CDCUE, "<$wavdir/cd.cue") |
| 4905 |
or print "Can not read file cue sheet!\n"; |
| 4906 |
@cuelines = <CDCUE>; |
| 4907 |
close(CDCUE); |
| 4908 |
} |
| 4909 |
|
| 4910 |
# If using book-option define a chapter file. |
| 4911 |
my $chapterfile; |
| 4912 |
if($book >= 1) { |
| 4913 |
$chapterfile = "$artist" . " - " . "$album" . ".chapters.txt"; |
| 4914 |
$chapterfile =~ s/ /_/g if($underscore == 1); |
| 4915 |
if($limit_flag == 255) { |
| 4916 |
$chapterfile = substr($chapterfile, 0, 235); |
| 4917 |
$chapterfile .= ".chapters.txt"; |
| 4918 |
} |
| 4919 |
} |
| 4920 |
|
| 4921 |
my $ghostflag = 0; |
| 4922 |
my $ghostcn = 0; |
| 4923 |
|
| 4924 |
if($commentag =~ /^discid|cddbid$/) { |
| 4925 |
if($commentag =~ /^discid$/) { |
| 4926 |
$commentag = $cd{discid} |
| 4927 |
} |
| 4928 |
elsif($commentag =~ /^cddbid$/) { |
| 4929 |
$commentag = $cd{id}; |
| 4930 |
} |
| 4931 |
elsif($commentag =~ /^mbreid$/) { |
| 4932 |
$commentag = $cd{mbreid}; |
| 4933 |
} |
| 4934 |
$commentag = "" unless($commentag); |
| 4935 |
$commentlametag = $commentag; |
| 4936 |
} |
| 4937 |
|
| 4938 |
# Prevent using genre "other" if genre is not lame compliant but |
| 4939 |
# other encoders than Lame are used: |
| 4940 |
my $genre_tag = $genre; |
| 4941 |
$genre_tag = $cd{genre} |
| 4942 |
if($genre =~ /Other/ && $cd{genre} !~ /Other/ && $cd{genre} ne ""); |
| 4943 |
|
| 4944 |
# Create a coverart array supposing its exactly in the same order as |
| 4945 |
# encoder array. |
| 4946 |
my @coverart = (); |
| 4947 |
if($coverart) { |
| 4948 |
@coverart = split(/,/, $coverart); |
| 4949 |
} |
| 4950 |
|
| 4951 |
# Loop all track names for a last VA style detection needed for |
| 4952 |
# tagging the files. Note that nothing is known about ghost songs. |
| 4953 |
my ($delim, $dummy) = check_va(0) if($vatag > 0); |
| 4954 |
$delim = quotemeta($delim) if(defined $delim); |
| 4955 |
$vatag = 0 if(!defined $delim or $delim eq ""); |
| 4956 |
|
| 4957 |
my $lamever = 0; |
| 4958 |
if($lameflag == 1) { |
| 4959 |
open(LAME, "lame --version 2>&1|"); |
| 4960 |
my @response = <LAME>; |
| 4961 |
close(LAME); |
| 4962 |
$lamever = $response[0] if(@response); |
| 4963 |
$lamever =~ s/^.*\sversion\s(\d\.\d+).*/$1/; |
| 4964 |
} |
| 4965 |
|
| 4966 |
# Start encoding each track. |
| 4967 |
$riptrackno = $tracksel[0] - 1; # Prevent warnings |
| 4968 |
foreach(@tracksel) { |
| 4969 |
# A lot of hacking for ghost songs. Remember, array @tracksel is |
| 4970 |
# the original one, without ghost songs as long as we did not get |
| 4971 |
# to the end. Once all tracks are done, this array will be |
| 4972 |
# updated if ghost songs were found by the ripper. |
| 4973 |
# Now: if only one track in the middle of the album has been |
| 4974 |
# selected, problems occur if this track has ghost songs. Why? |
| 4975 |
# Because the updated array @tracksel will be e.g. 4 4 4 4 if the |
| 4976 |
# track 4 has 3 ghost songs. But the track-list and tag-list |
| 4977 |
# arrays have all track names of the whole CD, so after track |
| 4978 |
# number 4 will come track number 5! Therefor no track |
| 4979 |
# "04 name of track 5" will be found and the encoder fails! |
| 4980 |
# To prevent this: Once all (selected) tracks are done, we have to |
| 4981 |
# set the $ghostcn to the total number of tracks of the CD to |
| 4982 |
# access names of ghost songs added to the end of the list by the |
| 4983 |
# ripper process. |
| 4984 |
|
| 4985 |
if($ghostflag == 1 && $riptrackno >= $_) { |
| 4986 |
$ghostflag = 2 |
| 4987 |
} |
| 4988 |
$ghostcn = $#{$cd{track}} + 1 if($ghostflag == 0); |
| 4989 |
# Prevent subroutine check_wav to give up because of missing lock |
| 4990 |
# files in case ssh or threads is used. |
| 4991 |
if($sshflag > 0 and $ghostflag > 0) { |
| 4992 |
open(LOCK, ">$wavdir/ghost.lock"); |
| 4993 |
print LOCK "Wait for ghost songs added to array tracksel.\n"; |
| 4994 |
close(LOCK); |
| 4995 |
} |
| 4996 |
$riptrackno = $_; |
| 4997 |
$tagtrackno = $_ + $trackoffset; |
| 4998 |
$trackcn++; |
| 4999 |
my $tracktag = ""; |
| 5000 |
if($rip == 1) { |
| 5001 |
$tracktag = $tracktags[$_ - 1]; |
| 5002 |
$tracktag = $tracktags[$_] if($hiddenflag == 1); |
| 5003 |
if($ghostflag >= 1) { |
| 5004 |
$ghostcn++; |
| 5005 |
$tracktag = $tracktags[$ghostcn - 1]; |
| 5006 |
$tracktag = $tracktags[$ghostcn] if($hiddenflag == 1); |
| 5007 |
} |
| 5008 |
} |
| 5009 |
else { |
| 5010 |
# See above for explanation. Keep the same scheme, even if |
| 5011 |
# ridicoulus. |
| 5012 |
$tracktag = $tracktags[$trackcn - 1]; |
| 5013 |
# Hiddenflag is set to 1 if a track number 0 has been detected |
| 5014 |
# in the track tag of flac file in sub get_cdid. |
| 5015 |
$tracktag = $tracktags[$trackcn - 1] if($hiddenflag == 1); |
| 5016 |
} |
| 5017 |
|
| 5018 |
# Split the tracktag into its artist part and track part if |
| 5019 |
# VA style is used. |
| 5020 |
if(defined $delim && $delim ne "" && $va_flag > 0 && $tracktag =~ /$delim/) { |
| 5021 |
($artistag, $tracktag) = split_tags($tracktag, $delim); |
| 5022 |
} |
| 5023 |
$artistag = clean_all($artist_utf8) unless(defined $artistag); |
| 5024 |
$trackartist = clean_all($artistag); |
| 5025 |
$trackartist = clean_name($trackartist); |
| 5026 |
$trackartist = clean_chars($trackartist); |
| 5027 |
$tracktitle = clean_all($tracktag); |
| 5028 |
$tracktitle = clean_name($tracktitle); |
| 5029 |
$tracktitle = clean_chars($tracktitle); |
| 5030 |
$trackartist =~ s/ /_/g if($underscore == 1); |
| 5031 |
$tracktitle =~ s/ /_/g if($underscore == 1); |
| 5032 |
|
| 5033 |
# A new problem arises if the track names of ghost (and original) |
| 5034 |
# songs are changed (if the track name with ghost song has a slash |
| 5035 |
# in) or operator changed wording while re-encoding. |
| 5036 |
# In this case, the resume option and the part that waits for |
| 5037 |
# the ripped files to appear will fail. |
| 5038 |
# Why? Because the encoder process we're in takes the tag info to |
| 5039 |
# deduce the track names. Stupid method from the old days. |
| 5040 |
# To prevent failure in case ghost is used: |
| 5041 |
# ghost.log needs to be checked. But the ghost.log might not yet |
| 5042 |
# be present if ripper is still ripping that file (the resume |
| 5043 |
# function in the ripper process failed for the same reason). So |
| 5044 |
# don't care here and let the resume function fail again. An |
| 5045 |
# additional test will be done in the waiting part below. |
| 5046 |
# But no matter what arguments option ghost has, while reencoding |
| 5047 |
# the @tracklist is a hole mess. |
| 5048 |
if($rip == 1) { |
| 5049 |
$riptrackname = get_trackname($_, $tracklist[$_ - 1], 0, $trackartist, $tracktitle); |
| 5050 |
$riptrackname = get_trackname($_, $tracklist[$_], 0, $trackartist, $tracktitle) |
| 5051 |
if($hiddenflag == 1); |
| 5052 |
|
| 5053 |
if($ghostflag >= 1) { |
| 5054 |
$riptrackname = get_trackname($_, $tracklist[$ghostcn - 1], 0, $trackartist, $tracktitle); |
| 5055 |
$riptrackname = get_trackname($_, $tracklist[$ghostcn], 0, $trackartist, $tracktitle) |
| 5056 |
if($hiddenflag == 1); |
| 5057 |
} |
| 5058 |
} |
| 5059 |
else { |
| 5060 |
# Use $trackcn instead of $_ as index number as it might be |
| 5061 |
# possible that in the inputdir some tracks are missing, giving |
| 5062 |
# a tracksel e.g. like this: (1 13) but tracklist only has two |
| 5063 |
# entries, entry number 13 would be empty... |
| 5064 |
# But why on earth is this so complex? Why do we do a |
| 5065 |
# look-up if we still use the old filenames? OK, filenames |
| 5066 |
# don't bother if at least the tags are updated, but with |
| 5067 |
# option trackoffset we're gonna totally mess it up. And how |
| 5068 |
# do I know that for the above mentioned problem tags get |
| 5069 |
# not totally messed up too, i.e. the 2nd track number 13 |
| 5070 |
# will get tags of track 2? Gosh, this code sucks. |
| 5071 |
my $dectrackname = $tracklist[$trackcn - 1]; |
| 5072 |
$dectrackname = $tracklist[$trackcn - 1] if($hiddenflag == 1); |
| 5073 |
# |
| 5074 |
# More problems: this will disable the trackoffset info, if |
| 5075 |
# retrieved while re-checking for DB-data... |
| 5076 |
my $tracktitle_modif = $tracklist_modif[$trackcn - 1]; |
| 5077 |
$tracktitle_modif = $tracklist_modif[$trackcn - 1] if($hiddenflag == 1); |
| 5078 |
$riptrackname = get_trackname($_, $tracktitle_modif, 0, $trackartist, $tracktitle); |
| 5079 |
# Hiddenflag is set to 1 if a track number 0 has been detected |
| 5080 |
# in the track tag of flac file in sub get_cdid. |
| 5081 |
$riptrackname = get_trackname($_, $tracktitle_modif, 0, $trackartist, $tracktitle) if($hiddenflag == 1); |
| 5082 |
if(-f "$wavdir/$dectrackname.wav" && $dectrackname ne $riptrackname) { |
| 5083 |
print "\nWarning\n", |
| 5084 |
"the detected trackname $dectrackname.wav is not", |
| 5085 |
"the expected trackname $riptrackname.wav\n" |
| 5086 |
if($verbose > 6); |
| 5087 |
log_system("mv \"$wavdir/$dectrackname.wav\" \\ |
| 5088 |
\"$wavdir/$riptrackname.wav\""); |
| 5089 |
} |
| 5090 |
} |
| 5091 |
# Once the file is ripped and merged, it is called $album, no |
| 5092 |
# matter if $cdcue == 1 or 2. |
| 5093 |
$riptrackname = $album if($book == 1 or $cdcue > 0); |
| 5094 |
# If we want to merge, skip a previously merged track: |
| 5095 |
my $skipflag = 0; |
| 5096 |
if($pmerge) { |
| 5097 |
@skip = skip_tracks(0); |
| 5098 |
foreach my $skip (@skip) { |
| 5099 |
$skipflag = 1 if($_ == $skip); |
| 5100 |
} |
| 5101 |
if($skipflag == 1 && $_ == $tracksel[$#tracksel] && $ghost == 1 && $ghostflag < 2) { |
| 5102 |
# We need to check if merged tracks have ghost songs. |
| 5103 |
# This is rather weird, but one never knows... imagine! |
| 5104 |
$ghostflag = 1; |
| 5105 |
$riptrackno++; |
| 5106 |
$skipflag = 2; |
| 5107 |
# The $ghostcn will be increased during the following redo |
| 5108 |
# loop. |
| 5109 |
$ghostcn--; |
| 5110 |
} |
| 5111 |
elsif($skipflag == 1 && $_ == $tracksel[$#tracksel] && $ghost == 1 && $ghostflag == 2) { |
| 5112 |
$skipflag = 3 if(-r "$wavdir/ghost.log"); |
| 5113 |
$_++; |
| 5114 |
} |
| 5115 |
if($book == 1) { |
| 5116 |
# Search the index number of encoder faac. |
| 5117 |
my $index = 0; |
| 5118 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 5119 |
$index = $c if($coder[$c] == 3); |
| 5120 |
} |
| 5121 |
# Write the *.chapter.txt file. |
| 5122 |
open(CHAP, ">>$sepdir[$index]/$chapterfile") or |
| 5123 |
print "Can't open $sepdir[$index]/$chapterfile! $!\n"; |
| 5124 |
# Use timestamps, not the true track lengths. Where are the |
| 5125 |
# specifications, please? |
| 5126 |
# Note: array framelist has been hacked and holds the total |
| 5127 |
# duration in the second entry. |
| 5128 |
my $points = track_length($framelist_orig[$_ - 1] - $framelist_orig[0], 1); |
| 5129 |
my $chapname = $tracktags[$_ - 1]; |
| 5130 |
# Remember: merge writes all merged track names into the |
| 5131 |
# first track of an interval. |
| 5132 |
$chapname =~ s/\s\+\s.*$// if($_ == 1); |
| 5133 |
print CHAP "$points $chapname\n"; |
| 5134 |
close(CHAP); |
| 5135 |
} |
| 5136 |
} |
| 5137 |
next if($skipflag == 1); |
| 5138 |
redo if($skipflag == 2); |
| 5139 |
$lastskip = $_; |
| 5140 |
|
| 5141 |
# LCDproc |
| 5142 |
if($lcd == 1) { |
| 5143 |
my $_lcdtracks = scalar(@tracksel); |
| 5144 |
my $_lcdenctrack = $trackcn; |
| 5145 |
my $lcdperc; |
| 5146 |
if($_lcdtracks eq $_lcdenctrack) { |
| 5147 |
$lcdperc = "*100"; |
| 5148 |
} |
| 5149 |
else { |
| 5150 |
$lcdperc = sprintf("%04.1f", $_lcdenctrack / $_lcdtracks * 100); |
| 5151 |
} |
| 5152 |
$lcdline3 =~ s/\|\d\d.\d/\|$lcdperc/; |
| 5153 |
my $_lcdenctrackF = sprintf("%02d", $_lcdenctrack); |
| 5154 |
# orig, gives warnings: $lcdline3 =~ s/\E\d\d/\E$_lcdenctrackF/; |
| 5155 |
$lcdline3 =~ s/\d\d/$_lcdenctrackF/; |
| 5156 |
substr($lcdline3, 10, 10) = substr($riptrackname, 3, 13); |
| 5157 |
ulcd(); |
| 5158 |
} |
| 5159 |
|
| 5160 |
# Adjust encoding of tracktag for Lame. |
| 5161 |
if($utftag == 0) { |
| 5162 |
$tracklametag = back_encoding($tracktag); |
| 5163 |
$artislametag = back_encoding($artistag); |
| 5164 |
} |
| 5165 |
else{ |
| 5166 |
$tracklametag = $tracktag; |
| 5167 |
$artislametag = $artistag; |
| 5168 |
} |
| 5169 |
$artistag = clean_all($artist_utf8) if($artistag eq ""); |
| 5170 |
$tracktag = $album if($cdcue > 0); |
| 5171 |
|
| 5172 |
# If the file name was too long for ripper, look for special name. |
| 5173 |
# Remember: this is a ripper problem, don't do that in case of |
| 5174 |
# re-encoding. |
| 5175 |
my $wavname = $riptrackname; |
| 5176 |
if((length($riptrackname) + length($wavdir) > 190) && $rip > 0) { |
| 5177 |
$wavname = get_trackname($_, $_ . "short", "short"); |
| 5178 |
} |
| 5179 |
|
| 5180 |
# Check for tracks already done. |
| 5181 |
my $checknextflag = 1; |
| 5182 |
if($resumenc) { |
| 5183 |
for(my $c=0; $c<=$#coder; $c++) { |
| 5184 |
if(! -r "$sepdir[$c]/$riptrackname.$suffix[$c]") { |
| 5185 |
$checknextflag = 0; |
| 5186 |
} |
| 5187 |
else{ |
| 5188 |
print "Found $riptrackname.$suffix[$c]:\n" |
| 5189 |
if($verbose >= 1); |
| 5190 |
print "Will calculate and write md5sum for:\n" |
| 5191 |
if($verbose >= 4 && $md5sum == 1); |
| 5192 |
print "$sepdir[$c], $riptrackname.$suffix[$c]\n" |
| 5193 |
if($verbose >= 4 && $md5sum == 1); |
| 5194 |
} |
| 5195 |
last if($checknextflag == 0); |
| 5196 |
} |
| 5197 |
if($checknextflag == 1 and ($playlist >= 1 or $cue > 0)) { |
| 5198 |
print PLST "#EXTINF:$secondlist[$_ - 1],$tracktag\n" |
| 5199 |
if($hiddenflag == 0); |
| 5200 |
print PLST "#EXTINF:$secondlist[$_],$tracktag\n" |
| 5201 |
if($hiddenflag == 1); |
| 5202 |
print PLST "Sepdir/$riptrackname.suffix\n" |
| 5203 |
if($playlist == 1); |
| 5204 |
print PLST "$riptrackname.suffix\n" if($playlist == 2); |
| 5205 |
print PLST "Add Ghost Song $_ Here.\n" if($ghost == 1); |
| 5206 |
} |
| 5207 |
unlink("$wavdir/$riptrackname.wav") |
| 5208 |
if($wav == 0 && $sshflag == 0 && $checknextflag == 1); |
| 5209 |
} |
| 5210 |
# Skip that track, i. e. restart the foreach-loop of tracks if a |
| 5211 |
# compressed file (mp3, ogg, ma4, flac) was found. |
| 5212 |
next if($resumenc && $checknextflag == 1); |
| 5213 |
# Don't resume anymore, if we came until here. |
| 5214 |
$resumenc = 0; |
| 5215 |
|
| 5216 |
# Keep looping until the wav file appears, i.e. wait for |
| 5217 |
# ripper timeout. Timeout is 3 times the length of track |
| 5218 |
# to rip/encode. Then leave that one and finish the job! |
| 5219 |
my $slength = $secondlist[$_ - 1]; |
| 5220 |
my $mlength = (int($slength / 60) + 1) * 3; |
| 5221 |
my $tlength = (int($slength / 10) + 6) * 3; |
| 5222 |
print "\nWarning, got negative timeout: $tlength.\nThis should ", |
| 5223 |
"not happen and may lead to problems.\nMaybe the track ", |
| 5224 |
"lengths are corrupt and need to be fixed.\n" |
| 5225 |
if($verbose > 0 and $tlength < 0); |
| 5226 |
|
| 5227 |
# We could believe not needing this for ghost songs, as they are |
| 5228 |
# fully ripped when the (original) last track was successfully |
| 5229 |
# ripped. But be aware, the last track might have changed name... |
| 5230 |
my $dataflag = 0; |
| 5231 |
my $xtime = 0; |
| 5232 |
my $ripsize = 0; |
| 5233 |
while(! -r "$wavdir/$wavname.wav" && $ghostflag == 0) { |
| 5234 |
$xtime++; |
| 5235 |
last if($xtime > $tlength); |
| 5236 |
print "\nWaiting for \"$wavdir/$wavname.wav\" to appear.\n" |
| 5237 |
if($verbose > 3); |
| 5238 |
# There might be a ghost song with an other name. If ripping |
| 5239 |
# is done, ghost.log would help, but the ghost.log file |
| 5240 |
# might not be present yet! Change in 4.0 |
| 5241 |
if($ghost == 1) { |
| 5242 |
next unless(defined $tracktag); |
| 5243 |
my ($ghost_rtn, $dummy) = split(/\//, $tracktag) |
| 5244 |
if($vatag == 0 or $vatag == 1 and $delim and $delim !~ /\//); |
| 5245 |
if($ghost_rtn) { |
| 5246 |
$ghost_rtn =~ s/^\s+|\s+$//; |
| 5247 |
my $ghost_trt = $ghost_rtn; |
| 5248 |
$ghost_rtn = clean_all($ghost_rtn); |
| 5249 |
$ghost_rtn = clean_name($ghost_rtn); |
| 5250 |
$ghost_rtn = clean_chars($ghost_rtn) if($chars); |
| 5251 |
$ghost_rtn = change_case($ghost_rtn, "t"); |
| 5252 |
$ghost_rtn =~ s/ /_/g if($underscore == 1); |
| 5253 |
$ghost_rtn = get_trackname($riptrackno, $ghost_rtn, 0, $artist, $ghost_rtn); |
| 5254 |
# Rename the riptrackname to wavname to exit the |
| 5255 |
# while-loop. Do it only when the wav appeared and the |
| 5256 |
# rip file disappeared in case it's the last track and |
| 5257 |
# the following check of ghost.log is mandatory. Else |
| 5258 |
# we would leave this loop and possibly read an old |
| 5259 |
# ghost.log not yet updated, because ripper is still |
| 5260 |
# ripping. |
| 5261 |
if(!-r "$wavdir/$wavname.rip" and |
| 5262 |
!-r "$wavdir/$ghost_rtn.rip" and |
| 5263 |
-r "$wavdir/$ghost_rtn.wav") { |
| 5264 |
$wavname = $riptrackname = $ghost_rtn; |
| 5265 |
$tracktag = $ghost_trt; |
| 5266 |
if($utftag == 0) { |
| 5267 |
$tracklametag = back_encoding($tracktag); |
| 5268 |
# TODO: maybe a copy has to be done here too. -> UTF-8 |
| 5269 |
} |
| 5270 |
else{ |
| 5271 |
$tracklametag = $tracktag; |
| 5272 |
} |
| 5273 |
} |
| 5274 |
} |
| 5275 |
} |
| 5276 |
# Condition 1: Too long waiting for the track! |
| 5277 |
if($xtime >= $tlength) { |
| 5278 |
# If the rip file has been found, give a chance to |
| 5279 |
# continue if the rip-file increases in size. |
| 5280 |
my $old_ripsize = $ripsize; |
| 5281 |
# |
| 5282 |
if(-r "$wavdir/$wavname.rip") { |
| 5283 |
$ripsize = -s "$wavdir/$wavname.rip"; |
| 5284 |
} |
| 5285 |
if($multi != 1) { |
| 5286 |
if($ripsize > $old_ripsize * 1.2) { |
| 5287 |
$tlength = $tlength * 1.5; |
| 5288 |
} |
| 5289 |
else { |
| 5290 |
print "Encoder waited $mlength minutes for file\n"; |
| 5291 |
print "$riptrackname.wav to appear, now giving up!\n"; |
| 5292 |
print "with $artist - $album in device $cddev\n"; |
| 5293 |
log_info("Encoder waited $mlength minutes for file"); |
| 5294 |
log_info("$riptrackname.wav to appear, now giving up!"); |
| 5295 |
log_info("with $artist - $album in device $cddev"); |
| 5296 |
} |
| 5297 |
} |
| 5298 |
else { |
| 5299 |
print "Encoder waited $mlength minutes for file\n"; |
| 5300 |
print "$riptrackname.wav to appear\n"; |
| 5301 |
print "with $artist - $album in device $cddev.\n"; |
| 5302 |
# If the rip file has been found, give a chance to |
| 5303 |
# continue if the rip-file increases in size. |
| 5304 |
if(-r "$wavdir/$wavname.rip") { |
| 5305 |
if($ripsize > $old_ripsize * 1.2) { |
| 5306 |
$tlength = $tlength * 1.5; |
| 5307 |
} |
| 5308 |
else { |
| 5309 |
$xtime = 0 unless($riptrackname =~ /00 Hidden Track/); |
| 5310 |
open(ERR, ">>$wavdir/error.log"); |
| 5311 |
print ERR "Ripping ended: 00:00!\n"; |
| 5312 |
close(ERR); |
| 5313 |
} |
| 5314 |
} |
| 5315 |
else { |
| 5316 |
$xtime = 0 unless($riptrackname =~ /00 Hidden Track/); |
| 5317 |
open(ERR, ">>$wavdir/error.log"); |
| 5318 |
print ERR "Ripping ended: 00:00!\n"; |
| 5319 |
close(ERR); |
| 5320 |
} |
| 5321 |
} |
| 5322 |
} |
| 5323 |
sleep 10; |
| 5324 |
# Condition 2: Check the error log! |
| 5325 |
# If at this moment the ripper did not start with |
| 5326 |
# the riptrackname.rip, assume it was a data track! |
| 5327 |
# If cdparanoia failed on a data track, there will |
| 5328 |
# be an entry in the error.log. |
| 5329 |
# If dagrab gave error messages, but the wav file |
| 5330 |
# was created, we won't get to this point, so don't |
| 5331 |
# worry. |
| 5332 |
if(-r "$wavdir/error.log") { |
| 5333 |
open(ERR, "$wavdir/error.log") |
| 5334 |
or print "Encoder can't read $wavdir/error.log!\n"; |
| 5335 |
my @errlines = <ERR>; |
| 5336 |
close(ERR); |
| 5337 |
# Note that the ripper wrote the $savetrackno into the |
| 5338 |
# errorlog, we check for $riptrackno not $tagtrackno. |
| 5339 |
chomp(my $errtrack = join(' ', grep(/^Track $riptrackno /, @errlines))); |
| 5340 |
if($errtrack) { |
| 5341 |
$xtime = $tlength + 1; |
| 5342 |
$dataflag = 1; |
| 5343 |
if($verbose >= 2) { |
| 5344 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5345 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5346 |
print ENCLOG "\nDid not detect track $errtrack ", |
| 5347 |
"($riptrackname.rip),\n assume ", |
| 5348 |
"ripper failure!\n"; |
| 5349 |
close(ENCLOG); |
| 5350 |
} |
| 5351 |
elsif($rip == 0) { |
| 5352 |
print "\nDid not detect track $errtrack ", |
| 5353 |
"($riptrackname.rip), assume decoder ", |
| 5354 |
"failure!\n"; |
| 5355 |
} |
| 5356 |
else { |
| 5357 |
print "\nDid not detect track $errtrack ", |
| 5358 |
"($riptrackname.rip), assume ripper ", |
| 5359 |
"failure!\n"; |
| 5360 |
} |
| 5361 |
} |
| 5362 |
if($verbose >= 2 && $sshflag == 0) { |
| 5363 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5364 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5365 |
print ENCLOG "\nRipIT will finish the job! ", |
| 5366 |
"Check the error.log!\n"; |
| 5367 |
close(ENCLOG); |
| 5368 |
} |
| 5369 |
else { |
| 5370 |
print "RipIT will finish the job! ", |
| 5371 |
"Check the error.log!\n"; |
| 5372 |
} |
| 5373 |
} |
| 5374 |
} |
| 5375 |
chomp(my $rip_ended = join(' ', grep(/^Ripping\sended:\s\d\d:\d\d/, @errlines))); |
| 5376 |
if($rip_ended and $xtime == 0 and $multi == 1) { |
| 5377 |
print "Ripper reported having ripped all wavs.\n"; |
| 5378 |
print "There is a problem with $riptrackname.wav.\n"; |
| 5379 |
print "with $artist - $album in device $cddev.\n"; |
| 5380 |
open(SRTF,">>$logfile.$riptrackno.txt") |
| 5381 |
or print "Can not append to file ", |
| 5382 |
"\"$logfile.$riptrackno.txt\"!\n"; |
| 5383 |
print SRTF "cdparanoia failed on $tracklist[$_ - 1]" |
| 5384 |
if($hiddenflag == 0); |
| 5385 |
print SRTF "cdparanoia failed on $tracklist[$_ - 1]" |
| 5386 |
if($hiddenflag == 1); |
| 5387 |
print SRTF "\nin device $logfile, error !"; |
| 5388 |
close(SRTF); |
| 5389 |
# Create on the fly error message in log-directory. |
| 5390 |
my $devnam = $cddev; |
| 5391 |
$devnam =~ s/.*dev.//; |
| 5392 |
open(ERO,">>$outputdir/failed.log") |
| 5393 |
or print "Can not append to file ", |
| 5394 |
"\"$outputdir/failed.log\"!\n"; |
| 5395 |
print ERO "$artist;$album;$genre;$categ;$cddbid;"; |
| 5396 |
print ERO "$devnam;$hostnam; Cdparanoia failure!\n"; |
| 5397 |
close(ERO); |
| 5398 |
# Now wait to be terminated by checktrack. |
| 5399 |
sleep 360; |
| 5400 |
exit; |
| 5401 |
} |
| 5402 |
} |
| 5403 |
} |
| 5404 |
|
| 5405 |
# This is an other hack to update the track-arrays modified by the |
| 5406 |
# ripper if ghost songs were found. Is there another way to |
| 5407 |
# communicate with the parent process? |
| 5408 |
# This loop was supposed to be at the end of this sub-routine, |
| 5409 |
# but we need it here in case of data tracks. The encoder would |
| 5410 |
# stop here after a data track and fail to encode previously found |
| 5411 |
# ghost songs because @tracksel has not yet been updated. |
| 5412 |
if($ghost == 1 && $_ == $tracksel[$#tracksel] |
| 5413 |
&& -r "$wavdir/ghost.log") { |
| 5414 |
open(GHOST, "<$wavdir/ghost.log") |
| 5415 |
or print "Can not read file ghost.log!\n"; |
| 5416 |
my @errlines = <GHOST>; |
| 5417 |
close(GHOST); |
| 5418 |
my @selines = grep(s/^Array seltrack: //, @errlines); |
| 5419 |
@tracksel = split(/ /, $selines[$#selines]); |
| 5420 |
chomp($_) foreach(@tracksel); |
| 5421 |
my @seclines = grep(s/^Array secondlist: //, @errlines); |
| 5422 |
@secondlist = split(/ /, $seclines[$#seclines]); |
| 5423 |
chomp($_) foreach(@secondlist); |
| 5424 |
@tracklist = grep(s/^Array tracklist: //, @errlines); |
| 5425 |
chomp($_) foreach(@tracklist); |
| 5426 |
@tracktags = grep(s/^Array tracktags: //, @errlines); |
| 5427 |
chomp($_) foreach(@tracktags); |
| 5428 |
# Do not delete ghost.log here because as it contains info |
| 5429 |
# about trimmed tracks. But the problem is, that it will be |
| 5430 |
# checked in md5sum calculation below expecting it only, if |
| 5431 |
# ghost songs have been found and exist. Else md5sum |
| 5432 |
# calculation will screw-up. |
| 5433 |
# unlink("$wavdir/ghost.log"); # Commented in 4.0.0 XXX |
| 5434 |
$ghost = 0; |
| 5435 |
$ghostflag = 1; |
| 5436 |
$resumenc = $resume; # Continue to resume ghost songs. |
| 5437 |
} |
| 5438 |
# If we come from merge hack, then the actual track $_ does not |
| 5439 |
# exist, continue to loop to the first ghost track. |
| 5440 |
next if($skipflag == 3); |
| 5441 |
|
| 5442 |
# Jump to the next track if wav wasn't found. Note that the |
| 5443 |
# $tlength does not exist for additional ghost songs, so don't |
| 5444 |
# test this condition when encoding ghost songs, furthermore we |
| 5445 |
# assume that ghost songs are present as soon as one was found. |
| 5446 |
next if($ghostflag == 0 && $xtime >= $tlength || $dataflag == 1); |
| 5447 |
|
| 5448 |
# It seems that long filenames need to berenamed in a subshell, |
| 5449 |
# because the rename function does not work if the full path is |
| 5450 |
# even longer. NOTE: There is a problem with UTF8, when special |
| 5451 |
# characters are true wide characters... Too many of them, and |
| 5452 |
# it will fail again. Maybe one should check the length with the |
| 5453 |
# unpack function. |
| 5454 |
if(length($riptrackname) + length($wavdir) > 190) { |
| 5455 |
# Is there a reason why all files should have no file name |
| 5456 |
# longer than 190 character? Removed in version 4.0 |
| 5457 |
# $riptrackname = substr($riptrackname, 0, 190); |
| 5458 |
# $riptrackname =~ s/\s*$//; |
| 5459 |
log_system("cd \"$wavdir\" && mv \"$wavname.wav\" \"$riptrackname.wav\""); |
| 5460 |
} |
| 5461 |
|
| 5462 |
my $delwav = 0; |
| 5463 |
my $starts = sprintf("%3d", sub {$_[1]*60+$_[0]}->(localtime)); |
| 5464 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5465 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5466 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5467 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5468 |
if($verbose >= 3); |
| 5469 |
print ENCLOG "Encoding \"$riptrackname\"...\n" |
| 5470 |
if($verbose >= 3); |
| 5471 |
close(ENCLOG); |
| 5472 |
} |
| 5473 |
else { |
| 5474 |
printf "\n%02d:%02d:%02d: ", |
| 5475 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5476 |
if($verbose >= 3); |
| 5477 |
print "Encoding \"$riptrackname\"...\n" if($verbose >= 3); |
| 5478 |
} |
| 5479 |
|
| 5480 |
my $covertag; |
| 5481 |
my $failflag = 0; |
| 5482 |
my $shortname = ""; |
| 5483 |
my $shortstring = "short-$$"; |
| 5484 |
# Set the encoder(s) we are going to use. |
| 5485 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 5486 |
# Initialization of coverart variables. |
| 5487 |
$covertag = " "; |
| 5488 |
$coverart[$c] = 0 unless($coverart[$c]); |
| 5489 |
# Get the command for the encoder to use! |
| 5490 |
$genre = "" unless($genre); |
| 5491 |
if($coder[$c] == 0) { |
| 5492 |
$encodername = "Lame"; |
| 5493 |
$lameopt = $globopt[$c]; |
| 5494 |
|
| 5495 |
push(@mp3tags, "TPOS=$discno") if($discno > 0 && $c == 0); |
| 5496 |
|
| 5497 |
# Coverart tagging will be done below because MP3::TAG |
| 5498 |
# module will be used. Don't handle the whole picture-data |
| 5499 |
# in this command. |
| 5500 |
# Starting with Lame 3.99 it is said to be possible (Lame |
| 5501 |
# should support APIC-frames > 128kb), but we keep it the |
| 5502 |
# way it is implemented. |
| 5503 |
|
| 5504 |
# Look at that: |
| 5505 |
# 11:55:11: Lame -b 128 encoding track 1 of 2 |
| 5506 |
# Writing of ID3v2.4 is not fully supported (prohibited now via `write_v24'). |
| 5507 |
# http://www.perlmonks.org/?node_id=844582 |
| 5508 |
# use MP3::Tag; |
| 5509 |
# MP3::Tag->config(write_v24 => 1); |
| 5510 |
|
| 5511 |
if($utftag == 0) { |
| 5512 |
# Change file names for Lame when tagging with Latin-1 |
| 5513 |
# to prevent breaking options ssh / threads because |
| 5514 |
# the whole string becomes Latin-1 flagged and non ASCII |
| 5515 |
# chars in the path will be corrupted... |
| 5516 |
$shortname = get_trackname($_, $_ . $shortstring, "short"); |
| 5517 |
# Copy the file to a non UTF-8 path. The file should |
| 5518 |
# be available as all checks have been done above. |
| 5519 |
# Don't do it more than once if Lame is used several |
| 5520 |
# times, because else the first Lame process would |
| 5521 |
# suddenly get a new partially copied wav and quit |
| 5522 |
# abruptly if option sshlist or threads is used. |
| 5523 |
if(-f "$wavdir/$wavname.wav") { |
| 5524 |
log_system("cp \"$wavdir/$wavname.wav\" \"/tmp/$shortname.wav\"") |
| 5525 |
unless(-f "/tmp/$shortname.wav"); |
| 5526 |
} |
| 5527 |
else { |
| 5528 |
# This is dangerous... assume $riptrackname exists |
| 5529 |
# instead of $wavname and copy without further |
| 5530 |
# testing. |
| 5531 |
log_system("cp \"$wavdir/$riptrackname.wav\" \"/tmp/$shortname.wav\"") |
| 5532 |
unless(-f "/tmp/$shortname.wav"); |
| 5533 |
} |
| 5534 |
my $id3v2_cmd = "--id3v2-latin1"; |
| 5535 |
if($lamever < 3.99) { |
| 5536 |
$id3v2_cmd = ""; |
| 5537 |
} |
| 5538 |
$enc = "lame $lameopt --quiet $id3v2_cmd \\ |
| 5539 |
--tt \"$tracklametag\" \\ |
| 5540 |
--ta \"$artislametag\" --tl \"$albumlametag\" \\ |
| 5541 |
--ty \"$year\" --tg \"$genre\" --tn $tagtrackno \\ |
| 5542 |
--tc \"$commentlametag\" --add-id3v2 \\ |
| 5543 |
\"/tmp/$shortname.wav\" \\ |
| 5544 |
\"/tmp/$shortname-$c.$suffix[$c]\""; |
| 5545 |
if($lamever >= 3.99) { |
| 5546 |
# Decode lame string to Latin-1 if encoder supports it. |
| 5547 |
$enc .= "_done"; |
| 5548 |
$enc = decode("latin1", $enc); |
| 5549 |
} |
| 5550 |
} |
| 5551 |
else { |
| 5552 |
$enc = "lame $lameopt --quiet --tt \"$tracklametag\" \\ |
| 5553 |
--ta \"$artislametag\" --tl \"$albumlametag\" \\ |
| 5554 |
--ty \"$year\" --tg \"$genre\" --tn $tagtrackno \\ |
| 5555 |
--tc \"$commentlametag\" --add-id3v2 \\ |
| 5556 |
\"$wavdir/$riptrackname.wav\" \\ |
| 5557 |
\"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\""; |
| 5558 |
} |
| 5559 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5560 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5561 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5562 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5563 |
if($verbose >= 3); |
| 5564 |
print ENCLOG "Lame $lameopt encoding track $trackcn" . |
| 5565 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5566 |
close(ENCLOG); |
| 5567 |
} |
| 5568 |
else { |
| 5569 |
printf "\n%02d:%02d:%02d: ", |
| 5570 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5571 |
if($verbose >= 3); |
| 5572 |
print "Lame $lameopt encoding track $trackcn of " . |
| 5573 |
($#tracksel + 1) if($verbose >= 3); |
| 5574 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5575 |
print "\n" if($verbose >= 3); |
| 5576 |
} |
| 5577 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5578 |
if($va_flag > 0) { |
| 5579 |
# Note, this does not work if option sshflag or threads |
| 5580 |
# is used. |
| 5581 |
push(@mp3tags, "TPE2=$albumartistlametag") |
| 5582 |
unless("@mp3tags" =~ /TPE2/); |
| 5583 |
} |
| 5584 |
} |
| 5585 |
elsif($coder[$c] == 1) { |
| 5586 |
$encodername = "Oggenc"; |
| 5587 |
$oggencopt = $globopt[$c]; |
| 5588 |
# Don't know if the COMPILATION-tag is supported but it |
| 5589 |
# should not harm at all. |
| 5590 |
$oggencopt .= " -c \"DISCNUMBER=$discno\"" if($discno > 0); |
| 5591 |
$oggencopt .= " -c \"COMPILATION=1\"" if($va_flag > 0); |
| 5592 |
$oggencopt .= " -c \"ALBUMARTIST=$albumartistag\"" |
| 5593 |
if($va_flag > 0); |
| 5594 |
|
| 5595 |
# Some info about coverart tagging. |
| 5596 |
# This will happen below, after encoding, because we use |
| 5597 |
# vorbiscomment. Don't handle the whole picture-data |
| 5598 |
# in this command. |
| 5599 |
|
| 5600 |
# http://www.hydrogenaudio.org/forums/lofiversion/index.php/t48386.html |
| 5601 |
|
| 5602 |
# CLI solutions: |
| 5603 |
# first: base64 encoding of the image: |
| 5604 |
# |
| 5605 |
# perl -MMIME::Base64 -0777 -ne 'print encode_base64($_, "")' < thumb.png > temp |
| 5606 |
# |
| 5607 |
# note the double quotes to prevent the newlines. |
| 5608 |
# Redirect this output to a file. |
| 5609 |
# |
| 5610 |
# second: use vorbiscomment to tag the file: (http://darcs.tonywhitmore.co.uk/repos/podcoder/podcoder) |
| 5611 |
# |
| 5612 |
# vorbiscomment -a 01.ogg -t "COVERARTMIME=image/png" -t "COVERART=`cat temp`" |
| 5613 |
# |
| 5614 |
# and you're done. |
| 5615 |
|
| 5616 |
# My personal solution: |
| 5617 |
# me@ripstation:~/Mo/ogg> echo -n COVERART= > temp && perl -MMIME::Base64 -0777 -ne 'print encode_base64($_, "")' < cover.jpg >> temp |
| 5618 |
# me@ripstation:~/Mo/ogg> vorbiscomment -a 05_Mo.ogg < temp |
| 5619 |
|
| 5620 |
|
| 5621 |
# Use of METADATA_BLOCK_PICTURE |
| 5622 |
# http://wiki.xiph.org/index.php/VorbisComment |
| 5623 |
# http://lists.xiph.org/pipermail/vorbis-dev/2009-April/019853.html |
| 5624 |
|
| 5625 |
# Proposals for extending Ogg Vorbis comments |
| 5626 |
# http://reallylongword.org/vorbiscomment/ |
| 5627 |
|
| 5628 |
$enc = "oggenc $oggencopt -Q -t \"$tracktag\" \\ |
| 5629 |
-a \"$artistag\" -l \"$albumtag\" \\ |
| 5630 |
-d \"$year\" -G \"$genre_tag\" \\ |
| 5631 |
-N $tagtrackno -c \"DESCRIPTION=$commentag\" \\ |
| 5632 |
-o \"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\" \\ |
| 5633 |
\"$wavdir/$riptrackname.wav\""; |
| 5634 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5635 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5636 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5637 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5638 |
if($verbose >= 3); |
| 5639 |
print ENCLOG "Oggenc $globopt[$c] encoding track" . |
| 5640 |
" $trackcn of " . ($#tracksel + 1) . "\n" |
| 5641 |
if($verbose >= 3); |
| 5642 |
close(ENCLOG); |
| 5643 |
} |
| 5644 |
else { |
| 5645 |
printf "\n%02d:%02d:%02d: ", |
| 5646 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5647 |
if($verbose >= 3); |
| 5648 |
print "Oggenc $globopt[$c] encoding track $trackcn of " . |
| 5649 |
($#tracksel + 1) if($verbose >= 3); |
| 5650 |
print " merged tracks" if($verbose >= 3 && $cdcue > 0); |
| 5651 |
print ".\n" if($verbose >= 3); |
| 5652 |
} |
| 5653 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5654 |
} |
| 5655 |
elsif($coder[$c] == 2) { |
| 5656 |
$encodername = "Flac"; |
| 5657 |
$flacopt = $globopt[$c]; |
| 5658 |
my $save_flacopt = $flacopt; |
| 5659 |
my $flactags = ""; |
| 5660 |
$flacopt .= " -f" if($resume); |
| 5661 |
# Don't know if the COMPILATION-tag is supported but it |
| 5662 |
# should not harm at all. |
| 5663 |
$flacopt .= " --tag=DISCNUMBER=$discno" if($discno > 0); |
| 5664 |
$flacopt .= " --tag=COMPILATION=1" if($va_flag > 0); |
| 5665 |
$flacopt .= " --tag=ALBUMARTIST=\"$albumartistag\"" |
| 5666 |
if($va_flag > 0); |
| 5667 |
$flacopt .= " --tag=CATEGORY=\"$categ\"" |
| 5668 |
if(defined $categ and $categ ne ""); |
| 5669 |
$flacopt .= " --tag=GENRE=\"$genre_tag\"" |
| 5670 |
if(defined $genre_tag && "Unknown" ne $genre_tag); |
| 5671 |
# $flacopt .= " --tag=MUSICBRAINZ_ALBUMID=\"$cd{mbreid}\"" |
| 5672 |
# if(defined $cd{mbreid}); |
| 5673 |
# $flacopt .= " --tag=MUSICBRAINZ_DISCID=\"$cd{discid}\"" |
| 5674 |
# if(defined $cd{discid}); |
| 5675 |
# $flacopt .= " --tag=CATALOGNUMBER=\"$cd{catalog}\"" |
| 5676 |
# if(defined $cd{catalog}); |
| 5677 |
if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5678 |
if($coverpath =~ /[|\\\\:*?\$]/) { |
| 5679 |
$covertag = "--picture=/tmp/ripit-flac-cov-$$.jpg"; |
| 5680 |
log_system("cp \"$coverpath\" /tmp/ripit-flac-cov-$$.jpg"); |
| 5681 |
} |
| 5682 |
else { |
| 5683 |
$covertag = "--picture=\"$coverpath\""; |
| 5684 |
} |
| 5685 |
} |
| 5686 |
if(@flactags) { |
| 5687 |
foreach (@flactags) { |
| 5688 |
my ($frame, $content) = split(/=/, $_); |
| 5689 |
$content = tag_eval($frame, $content); |
| 5690 |
$flactags .= " --tag=$frame=\"$content\"" |
| 5691 |
if(defined $content && $content ne ""); |
| 5692 |
} |
| 5693 |
$flactags =~ s/^\s+//; |
| 5694 |
} |
| 5695 |
$enc = "flac $flacopt \\ |
| 5696 |
--totally-silent \\ |
| 5697 |
--tag=TITLE=\"$tracktag\" \\ |
| 5698 |
--tag=ARTIST=\"$artistag\" --tag=ALBUM=\"$albumtag\" \\ |
| 5699 |
--tag=DATE=\"$year\" --tag=TRACKNUMBER=\"$tagtrackno\" \\ |
| 5700 |
--tag=DESCRIPTION=\"$commentag\" --tag=CDID=\"$cddbid\" \\ |
| 5701 |
$covertag \\ |
| 5702 |
$flactags \\ |
| 5703 |
-o \"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\" \\ |
| 5704 |
\"$wavdir/$riptrackname.wav\""; |
| 5705 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5706 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5707 |
printf ENCLOG "%02d:%02d:%02d: ", |
| 5708 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5709 |
if($verbose >= 3); |
| 5710 |
print ENCLOG "Flac $globopt[$c] encoding track $trackcn" . |
| 5711 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5712 |
close(ENCLOG); |
| 5713 |
} |
| 5714 |
else { |
| 5715 |
printf "\n%02d:%02d:%02d: ", |
| 5716 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5717 |
if($verbose >= 3); |
| 5718 |
print "Flac $globopt[$c] encoding track $trackcn of " . |
| 5719 |
($#tracksel + 1) if($verbose >= 3); |
| 5720 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5721 |
print "\n" if($verbose >= 3); |
| 5722 |
} |
| 5723 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5724 |
my $flacopt = $save_flacopt if($resume); |
| 5725 |
} |
| 5726 |
elsif($coder[$c] == 3) { |
| 5727 |
$encodername = "Faac"; |
| 5728 |
$faacopt = $globopt[$c]; |
| 5729 |
if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5730 |
$covertag = "--cover-art \"$coverpath\""; |
| 5731 |
} |
| 5732 |
$faacopt .= " --compilation" if($va_flag > 0); |
| 5733 |
$faacopt .= " --disc $discno" if($discno > 0); |
| 5734 |
$enc = "faac $faacopt -w --title \"$tracktag\" \\ |
| 5735 |
--artist \"$artistag\" --album \"$albumtag\" \\ |
| 5736 |
--year \"$year\" --genre \"$genre_tag\" --track $tagtrackno \\ |
| 5737 |
--comment \"$commentag\" \\ |
| 5738 |
$covertag \\ |
| 5739 |
-o \"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\" \\ |
| 5740 |
\"$wavdir/$riptrackname.wav\" \\ |
| 5741 |
> /dev/null 2>&1"; |
| 5742 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5743 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5744 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5745 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5746 |
if($verbose >= 3); |
| 5747 |
print ENCLOG "Faac $globopt[$c] encoding track $trackcn" . |
| 5748 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5749 |
close(ENCLOG); |
| 5750 |
} |
| 5751 |
else { |
| 5752 |
printf "\n%02d:%02d:%02d: ", |
| 5753 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5754 |
if($verbose >= 3); |
| 5755 |
print "Faac $globopt[$c] encoding track $trackcn of " . |
| 5756 |
($#tracksel + 1) if($verbose >= 3); |
| 5757 |
print " merged tracks." |
| 5758 |
if($verbose >= 3 && ($book > 0 || $cdcue > 0)); |
| 5759 |
print "\n" if($verbose >= 3); |
| 5760 |
} |
| 5761 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5762 |
} |
| 5763 |
elsif($coder[$c] == 4) { |
| 5764 |
$encodername = "mp4als"; |
| 5765 |
$mp4alsopt = $globopt[$c]; |
| 5766 |
$enc = "mp4als $mp4alsopt \\ |
| 5767 |
\"$wavdir/$riptrackname.wav\" \\ |
| 5768 |
\"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\" \\ |
| 5769 |
> /dev/null 2>&1 \\ |
| 5770 |
"; |
| 5771 |
# Only add tags if MP4 container is set up, use artwork for |
| 5772 |
# coverart. |
| 5773 |
my $mp4suffix = $suffix[$c]; |
| 5774 |
if($mp4alsopt =~ /MP4/) { |
| 5775 |
$mp4suffix = "mp4"; |
| 5776 |
if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5777 |
$covertag = "-P \"$coverpath\""; |
| 5778 |
} |
| 5779 |
$enc .= " && mp4tags -s \"$tracktag\" -a \"$artistag\" \\ |
| 5780 |
-A \"$albumtag\" -y \"$year\" -g \"$genre_tag\" \\ |
| 5781 |
-t $tagtrackno -c \"$commentag\" -e Ripit -E mp4als \\ |
| 5782 |
$covertag \\ |
| 5783 |
\"$sepdir[$c]/$riptrackname.$suffix[$c]_enc\""; |
| 5784 |
} |
| 5785 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5786 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5787 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5788 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5789 |
if($verbose >= 3); |
| 5790 |
print ENCLOG "Mp4als $globopt[$c] encoding track $trackcn" . |
| 5791 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5792 |
close(ENCLOG); |
| 5793 |
} |
| 5794 |
else { |
| 5795 |
printf "\n%02d:%02d:%02d: ", |
| 5796 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5797 |
if($verbose >= 3); |
| 5798 |
print "Mp4als $globopt[$c] encoding track $trackcn of " . |
| 5799 |
($#tracksel + 1) if($verbose >= 3); |
| 5800 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5801 |
print "\n" if($verbose >= 3); |
| 5802 |
} |
| 5803 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5804 |
} |
| 5805 |
elsif($coder[$c] == 5) { |
| 5806 |
$encodername = "Musepack"; |
| 5807 |
$museopt = $globopt[$c]; |
| 5808 |
# TODO: check availability |
| 5809 |
# Discnumber is not yet supported |
| 5810 |
# $museopt .= " --discnumber=$discno" if($discno > 0); |
| 5811 |
# $museopt .= " --compilation=1" if($va_flag > 0); |
| 5812 |
# $museopt .= " --albumartist=\"$albumartistag\"" |
| 5813 |
# if($va_flag > 0); |
| 5814 |
# Musepack seems not to support coverart, the developers |
| 5815 |
# probably assume that coverart has nothing to do with a |
| 5816 |
# track... i.e. with sound. |
| 5817 |
$enc = "$musenc --silent $museopt --title \"$tracktag\" \\ |
| 5818 |
--artist \"$artistag\" --album \"$albumtag\" \\ |
| 5819 |
--year \"$year\" --genre \"$genre_tag\" --track $tagtrackno --comment \"$commentag\" \\ |
| 5820 |
\"$wavdir/$riptrackname.wav\" \\ |
| 5821 |
\"$sepdir[$c]/$riptrackname\_enc.$suffix[$c]\""; |
| 5822 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5823 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5824 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5825 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5826 |
if($verbose >= 3); |
| 5827 |
print ENCLOG "Mppenc $globopt[$c] encoding track $trackcn" . |
| 5828 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5829 |
close(ENCLOG); |
| 5830 |
} |
| 5831 |
else { |
| 5832 |
printf "\n%02d:%02d:%02d: ", |
| 5833 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5834 |
if($verbose >= 3); |
| 5835 |
print "Mppenc $globopt[$c] encoding track $trackcn of " . |
| 5836 |
($#tracksel + 1) if($verbose >= 3); |
| 5837 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5838 |
print "\n" if($verbose >= 3); |
| 5839 |
} |
| 5840 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5841 |
} |
| 5842 |
elsif($coder[$c] == 6) { |
| 5843 |
$encodername = "wavpack"; |
| 5844 |
$wavpacopt = $globopt[$c]; |
| 5845 |
$wavpacopt .= " -w \"Part=$discno\"" if($discno > 0); |
| 5846 |
$wavpacopt .= " -w \"Compilation=1\"" if($va_flag > 0); |
| 5847 |
$wavpacopt .= " -w \"Albumartist=$albumartistag\"" |
| 5848 |
if($va_flag > 0); |
| 5849 |
$wavpacopt .= " -w \"MUSICBRAINZ_ALBUMID=$cd{mbreid}\"" |
| 5850 |
if(defined $cd{mbreid}); |
| 5851 |
$wavpacopt .= " -w \"MUSICBRAINZ_DISCID=$cd{discid}\"" |
| 5852 |
if(defined $cd{discid}); |
| 5853 |
$wavpacopt .= " -w \"CATALOGNUMBER=$cd{catalog}\"" |
| 5854 |
if(defined $cd{catalog}); |
| 5855 |
# Use command wvunpack -ss filename.wv to check if the cover |
| 5856 |
# art is present or not. See: |
| 5857 |
# www.hydrogenaudio.org/forums/index.php?showtopic=74828 |
| 5858 |
if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5859 |
$covertag = "--write-binary-tag \"Cover Art (Front)=\@$coverpath\""; |
| 5860 |
} |
| 5861 |
$enc = "wavpack $wavpacopt -q \\ |
| 5862 |
-w \"Title=$tracktag\" \\ |
| 5863 |
-w \"Artist=$artistag\" -w \"Album=$albumtag\" \\ |
| 5864 |
-w \"Year=$year\" -w \"Genre=$genre_tag\" \\ |
| 5865 |
-w \"Track=$tagtrackno\" -w \"Comment=$commentag\" \\ |
| 5866 |
$covertag \\ |
| 5867 |
\"$wavdir/$riptrackname.wav\" \\ |
| 5868 |
-o \"$sepdir[$c]/$riptrackname\_enc\""; |
| 5869 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5870 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5871 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5872 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5873 |
if($verbose >= 3); |
| 5874 |
print ENCLOG "Wavpack $globopt[$c] encoding track $trackcn" . |
| 5875 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5876 |
close(ENCLOG); |
| 5877 |
} |
| 5878 |
else { |
| 5879 |
printf "\n%02d:%02d:%02d: ", |
| 5880 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5881 |
if($verbose >= 3); |
| 5882 |
print "Wavpack $globopt[$c] encoding track $trackcn of " . |
| 5883 |
($#tracksel + 1) if($verbose >= 3); |
| 5884 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5885 |
print "\n" if($verbose >= 3); |
| 5886 |
} |
| 5887 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5888 |
} |
| 5889 |
elsif($coder[$c] == 7) { |
| 5890 |
$encodername = "ffmpeg"; |
| 5891 |
# Trying to solve the tag problem of tagging with ffmpeg in |
| 5892 |
# general and within alac files in special: |
| 5893 |
# First, I tried to use ffmpeg and the -map_meta_tag option: |
| 5894 |
# ffmpeg -i 05\ I\ Beg\ For\ You.flac -acodec alac \\ |
| 5895 |
# 05\ I\ Beg\ For\ You.m4a -map_meta_data outfile:infile |
| 5896 |
# Note: do not replace outfile:infile by the file names, use |
| 5897 |
# the command as stated! |
| 5898 |
# |
| 5899 |
# OK, this works and we see, that the four character code |
| 5900 |
# used in the m4a tags are "ART" and "wrt". So, what we need |
| 5901 |
# is author to access these tags! |
| 5902 |
# |
| 5903 |
# http://archives.free.net.ph/message/20090925.222527.f3078d30.en.html |
| 5904 |
# http://atomicparsley.sourceforge.net/mpeg-4files.html |
| 5905 |
# http://code.google.com/p/mp4v2/wiki/iTunesMetadata |
| 5906 |
# |
| 5907 |
$ffmpegopt = $globopt[$c]; |
| 5908 |
$ffmpegopt .= " -y" if($overwrite eq "y"); |
| 5909 |
$ffmpegopt .= " -metadata compilation=1 " if($va_flag > 0 and $ffmpegopt =~ /alac/i); |
| 5910 |
$ffmpegopt .= " -metadata discnumber=$discno" if($discno > 0); |
| 5911 |
# Not yet supported... at least I don't know how to use the |
| 5912 |
# -atag fourcc/tag option. |
| 5913 |
# if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5914 |
# $covertag = "-metadata artwork=\'$coverpath\'"; |
| 5915 |
# } |
| 5916 |
$enc = "ffmpeg -i \"$wavdir/$riptrackname.wav\" \\ |
| 5917 |
$ffmpegopt \\ |
| 5918 |
-metadata author=\"$artistag\" -metadata album=\"$albumtag\" \\ |
| 5919 |
-metadata title=\"$tracktag\" -metadata genre=\"$genre_tag\" \\ |
| 5920 |
-metadata day=\"$year\" -metadata comment=\"$commentag\" \\ |
| 5921 |
-metadata track=\"$tagtrackno\" \\ |
| 5922 |
$covertag \\ |
| 5923 |
\"$sepdir[$c]/$riptrackname.$suffix[$c]\" > /dev/null 2>&1"; |
| 5924 |
# Only add artwork for coverart if alac is present. |
| 5925 |
if($coverart[$c] == 1 && -f "$coverpath" && -s "$coverpath") { |
| 5926 |
if($ffmpegopt =~ /alac/) { |
| 5927 |
$enc .= " && mp4art -q --add \"$coverpath\" \\ |
| 5928 |
\"$sepdir[$c]/$riptrackname.$suffix[$c]\""; |
| 5929 |
} |
| 5930 |
} |
| 5931 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 5932 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 5933 |
printf ENCLOG "\n%02d:%02d:%02d: ", |
| 5934 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5935 |
if($verbose >= 3); |
| 5936 |
print ENCLOG "ffmpeg $ffmpegopt encoding track $trackcn" . |
| 5937 |
" of " . ($#tracksel + 1) . "\n" if($verbose >= 3); |
| 5938 |
close(ENCLOG); |
| 5939 |
} |
| 5940 |
else { |
| 5941 |
printf "\n%02d:%02d:%02d: ", |
| 5942 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5943 |
if($verbose >= 3); |
| 5944 |
print "ffmpeg $ffmpegopt encoding track $trackcn of " . |
| 5945 |
($#tracksel + 1) if($verbose >= 3); |
| 5946 |
print " merged tracks." if($verbose >= 3 && $cdcue > 0); |
| 5947 |
print "\n" if($verbose >= 3); |
| 5948 |
} |
| 5949 |
log_info("new-mediafile: $sepdir[$c]/${riptrackname}.$suffix[$c]"); |
| 5950 |
} |
| 5951 |
# Set "last encoding of track" - flag. |
| 5952 |
$delwav = 1 if($wav == 0 && $c == $#coder); |
| 5953 |
# Set nice if wished. |
| 5954 |
$enc = "nice -n $nice " . $enc if($nice != 0); |
| 5955 |
# Make the output look nice, don't mess the messages! |
| 5956 |
my $ripmsg = "The audio CD ripper reports: all done!"; |
| 5957 |
if($ripcomplete == 0 ) { |
| 5958 |
if(-r "$wavdir/error.log") { |
| 5959 |
open(ERR, "$wavdir/error.log") |
| 5960 |
or print "Can not open file error.log!\n"; |
| 5961 |
my @errlines = <ERR>; |
| 5962 |
close(ERR); |
| 5963 |
my @ripcomplete = grep(/^$ripmsg/, @errlines); |
| 5964 |
$ripcomplete = 1 if(@ripcomplete); |
| 5965 |
} |
| 5966 |
} |
| 5967 |
|
| 5968 |
$enc =~ s/\$/\\\$/g; |
| 5969 |
# Finally, do the job of encoding. |
| 5970 |
if($sshflag == 1) { |
| 5971 |
if(-f "$sepdir[$c]/$riptrackname.$suffix[$c]" && ((-f "$coverpath" && -s "$coverpath") || @mp3tags)) { |
| 5972 |
printf "\n%02d:%02d:%02d: ", |
| 5973 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 5974 |
if($verbose > 0); |
| 5975 |
print "Warning, file ", |
| 5976 |
"$sepdir[$c]/$riptrackname.$suffix[$c]\n", |
| 5977 |
" already exists and post processing ", |
| 5978 |
"would be done before new file appears...\n", |
| 5979 |
" File will be deleted now!\n" |
| 5980 |
if($verbose > 0); |
| 5981 |
unlink("$sepdir[$c]/$riptrackname.$suffix[$c]"); |
| 5982 |
} |
| 5983 |
enc_ssh($delwav,$enc,$riptrackname,$sepdir[$c],$suffix[$c],$shortname,$c); |
| 5984 |
# Calculation of md5sum has been moved to the end, we still |
| 5985 |
# use the process to check the files already done to add |
| 5986 |
# coverart. Files not yet encoded will need to be post- |
| 5987 |
# processed in del_erlog subroutine. |
| 5988 |
push(@md5tracks, |
| 5989 |
"$sepdir[$c];#;$riptrackname.$suffix[$c]"); |
| 5990 |
my @waitracks; |
| 5991 |
foreach my $md5tr (@md5tracks) { |
| 5992 |
my ($sepdir, $donetrack) = split(/;#;/, $md5tr); |
| 5993 |
# Proceed only if file appeared. |
| 5994 |
if(-f "$sepdir/$donetrack") { |
| 5995 |
# Add additional mp3 tags. |
| 5996 |
if(@mp3tags && $donetrack =~ /mp3$/) { |
| 5997 |
mp3_tags("$sepdir/$donetrack") |
| 5998 |
if(defined $mp3tags[0] && $mp3tags[0] !~ /^\s*$/); |
| 5999 |
} |
| 6000 |
# Add special tags to ogg with strings to be evaluated |
| 6001 |
elsif(@oggtags && $donetrack =~ /ogg$/) { |
| 6002 |
ogg_tags("$sepdir/$donetrack") if($oggtags[0] ne ""); |
| 6003 |
} |
| 6004 |
# Add coverart if it is a mp3 or ogg. |
| 6005 |
if($donetrack =~ /mp3$/ && -f "$coverpath" && -s "$coverpath") { |
| 6006 |
mp3_cover("$sepdir/$donetrack", "$coverpath"); |
| 6007 |
} |
| 6008 |
elsif($donetrack =~ /ogg$/ && -f "$coverpath" && -s "$coverpath") { |
| 6009 |
ogg_cover("$sepdir/$donetrack", "$coverpath"); |
| 6010 |
} |
| 6011 |
} |
| 6012 |
# Only keep files in array @md5tracks if not yet |
| 6013 |
# processed. |
| 6014 |
else { |
| 6015 |
push(@waitracks, "$sepdir;#;$donetrack"); |
| 6016 |
} |
| 6017 |
} |
| 6018 |
# TODO: Check if array md5tracks gets cleared as expected. |
| 6019 |
# No md5sums can be calculated... |
| 6020 |
@md5tracks = @waitracks; |
| 6021 |
} |
| 6022 |
else { |
| 6023 |
if(log_system("$enc")) { |
| 6024 |
if($ripcomplete == 0) { |
| 6025 |
if(-r "$wavdir/error.log") { |
| 6026 |
open(ERR, "$wavdir/error.log") |
| 6027 |
or print "Can open file error.log!\n"; |
| 6028 |
my @errlines = <ERR>; |
| 6029 |
close(ERR); |
| 6030 |
my @ripcomplete = grep(/^$ripmsg/, @errlines); |
| 6031 |
$ripcomplete = 1 if(@ripcomplete); |
| 6032 |
} |
| 6033 |
} |
| 6034 |
if($coder[$c] == 4 && $mp4alsopt =~ /MP4/) { |
| 6035 |
rename("$sepdir[$c]/$riptrackname.$suffix[$c]_enc", |
| 6036 |
"$sepdir[$c]/$riptrackname.mp4"); |
| 6037 |
} |
| 6038 |
elsif($coder[$c] == 5) { |
| 6039 |
rename("$sepdir[$c]/$riptrackname\_enc.$suffix[$c]", |
| 6040 |
"$sepdir[$c]/$riptrackname.$suffix[$c]"); |
| 6041 |
} |
| 6042 |
elsif($coder[$c] == 6) { |
| 6043 |
rename("$sepdir[$c]/$riptrackname\_enc.$suffix[$c]", |
| 6044 |
"$sepdir[$c]/$riptrackname.$suffix[$c]"); |
| 6045 |
if(-r "$sepdir[$c]/$riptrackname\_enc.wvc") { |
| 6046 |
rename("$sepdir[$c]/$riptrackname\_enc.wvc", |
| 6047 |
"$sepdir[$c]/$riptrackname.wvc"); |
| 6048 |
} |
| 6049 |
} |
| 6050 |
elsif($coder[$c] == 0 and $utftag == 0) { |
| 6051 |
log_system("mv \"/tmp/$shortname-$c.mp3_done\" \\ |
| 6052 |
\"$sepdir[$c]/$riptrackname.mp3\""); |
| 6053 |
} |
| 6054 |
else { |
| 6055 |
rename("$sepdir[$c]/$riptrackname.$suffix[$c]_enc", |
| 6056 |
"$sepdir[$c]/$riptrackname.$suffix[$c]"); |
| 6057 |
} |
| 6058 |
# Add special mp3 tags. |
| 6059 |
if(@mp3tags && $coder[$c] == 0) { |
| 6060 |
mp3_tags("$sepdir[$c]/$riptrackname.$suffix[$c]") |
| 6061 |
if(defined $mp3tags[0] && $mp3tags[0] !~ /^\s*$/); |
| 6062 |
} |
| 6063 |
# Add special tags to ogg with strings to be evaluated |
| 6064 |
elsif(@oggtags && $coder[$c] == 1) { |
| 6065 |
ogg_tags("$sepdir[$c]/$riptrackname.$suffix[$c]") |
| 6066 |
if($oggtags[0] ne ""); |
| 6067 |
} |
| 6068 |
# Add coverart if it is a mp3 or ogg. |
| 6069 |
if($coder[$c] == 0 && $coverart[$c] == 1 && |
| 6070 |
-f "$coverpath" && -s "$coverpath") { |
| 6071 |
mp3_cover("$sepdir[$c]/$riptrackname.$suffix[$c]", "$coverpath"); |
| 6072 |
} |
| 6073 |
elsif($coder[$c] == 1 && $coverart[$c] == 1 && |
| 6074 |
-f "$coverpath" && -s "$coverpath") { |
| 6075 |
ogg_cover("$sepdir[$c]/$riptrackname.$suffix[$c]", "$coverpath"); |
| 6076 |
} |
| 6077 |
else { |
| 6078 |
print "Failed adding coverart to $suffix[$c].\n" |
| 6079 |
if($coverart[$c] == 1 && $verbose > 2 && $coder[$c] < 2); |
| 6080 |
} |
| 6081 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 6082 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 6083 |
print ENCLOG "Encoding of " . |
| 6084 |
"\"$riptrackname.$suffix[$c]\" " . |
| 6085 |
"complete.\n" if($verbose >= 1); |
| 6086 |
close(ENCLOG); |
| 6087 |
} |
| 6088 |
else { |
| 6089 |
print "Encoding of \"$riptrackname.$suffix[$c]\" " . |
| 6090 |
"complete.\n" if($verbose >= 1); |
| 6091 |
} |
| 6092 |
} |
| 6093 |
else { |
| 6094 |
print "Encoder $encodername failed on $tracklist[$_ - 1]\n", |
| 6095 |
"of disc in device $cddev.\n", |
| 6096 |
"Error message says: $?\n"; |
| 6097 |
$failflag = 1; |
| 6098 |
if($multi == 1) { |
| 6099 |
# Print error message to file srXY.Z.txt, checktrack |
| 6100 |
# will grep for string "encoder failed" and kill the |
| 6101 |
# CD immediately! |
| 6102 |
open(SRTF,">>$logfile.$riptrackno.txt") |
| 6103 |
or print "Can not append to file ", |
| 6104 |
"\"$logfile.$riptrackno.txt\"!\n"; |
| 6105 |
print SRTF "\nencoder failed on $tracklist[$_ - 1] "; |
| 6106 |
print SRTF "in device $cddev, error $? !"; |
| 6107 |
close(SRTF); |
| 6108 |
# Create on the fly error message in log-directory. |
| 6109 |
my $devnam = $cddev; |
| 6110 |
$devnam =~ s/.*dev.//; |
| 6111 |
open(ERO, ">>$outputdir/failed.log") |
| 6112 |
or print "Can not append to file ", |
| 6113 |
"\"$outputdir/failed.log\"!\n"; |
| 6114 |
print ERO "$artist;$album;$genre;$categ;$cddbid;"; |
| 6115 |
print ERO "$devnam;$hostnam; Encoder failure!\n"; |
| 6116 |
close(ERO); |
| 6117 |
# Wait to be terminated by checktrack. |
| 6118 |
sleep 360; |
| 6119 |
} |
| 6120 |
} |
| 6121 |
sleep 1; |
| 6122 |
} |
| 6123 |
# Copy the CDCUE file (once) to the directory of the encoded |
| 6124 |
# files. |
| 6125 |
if($cdcue > 0) { |
| 6126 |
my $cue_suffix = $suffix[$c]; |
| 6127 |
$cue_suffix =~ tr/a-z/A-Z/; |
| 6128 |
open(CDCUE, ">$sepdir[$c]/$album.cue") |
| 6129 |
or print "Can not write to file ", |
| 6130 |
"\"$sepdir[$c]/$album.cue\"!\n"; |
| 6131 |
foreach (@cuelines) { |
| 6132 |
chomp; |
| 6133 |
s/\.wav/.$suffix[$c]/; |
| 6134 |
s/\sWAVE/ $cue_suffix/; |
| 6135 |
print CDCUE "$_\n"; |
| 6136 |
} |
| 6137 |
close(CDCUE); |
| 6138 |
} |
| 6139 |
} |
| 6140 |
# Calculate time in seconds when encoding ended and total time |
| 6141 |
# encoder needed. |
| 6142 |
my $endsec = sprintf("%3d", sub {$_[1]*60+$_[0]}->(localtime)); |
| 6143 |
$endsec += 60 while($endsec <= $starts); |
| 6144 |
$totalencs = $totalencs + $endsec - $starts; |
| 6145 |
# Delete the wav if not wanted. |
| 6146 |
unlink("$wavdir/$riptrackname.wav") |
| 6147 |
if($delwav == 1 && $sshflag == 0 && $accuracy == 0); |
| 6148 |
unlink("/tmp/$shortname.wav") |
| 6149 |
if($lameflag == 1 && $utftag == 0); |
| 6150 |
|
| 6151 |
# Write the playlist file. This is somehow tricky, if ghost songs |
| 6152 |
# may appear. To ensure the files in the right order, introduce |
| 6153 |
# placeholders for possible ghost songs. |
| 6154 |
# The problem is that the secondlist with the true track lengths |
| 6155 |
# will only be updated when the last track has been encoded (the |
| 6156 |
# last track except ghost songs). But we need the true length |
| 6157 |
# right now. So, if $ghost == 1, check for the ghost.log file at |
| 6158 |
# any track. |
| 6159 |
# TODO: |
| 6160 |
# An other buggy behaviour: if the last encoder of a list fails, |
| 6161 |
# failflag will prevent writing playlist files, although encoding |
| 6162 |
# was successful for all other encoders (but the last one). |
| 6163 |
# Would it be better to write the playlist file in any case? |
| 6164 |
if($failflag == 0 and ($playlist >= 1 or $cue > 0 )) { |
| 6165 |
# Ghost songs follow after the last track, but $ghostflag was |
| 6166 |
# set to 1 just before last track is encoded. Therefore set |
| 6167 |
# $ghostflag to 2 after the last track has been done and |
| 6168 |
# inserted in the playlist file as a regular file (below), |
| 6169 |
# and insert sound files as ghost songs only when $ghostflag is |
| 6170 |
# 2. If only the last song has been split into chunks and |
| 6171 |
# the counter increased, continue to insert as regular file. |
| 6172 |
if($ghostflag == 2) { |
| 6173 |
print PLST "GS$_:#EXTINF:$secondlist[$ghostcn - 1],", |
| 6174 |
"$tracktag\n" |
| 6175 |
if($hiddenflag == 0); |
| 6176 |
print PLST "GS$_:#EXTINF:$secondlist[$ghostcn],$tracktag\n" |
| 6177 |
if($hiddenflag == 1); |
| 6178 |
print PLST "GS$_:Sepdir/$riptrackname.suffix\n" |
| 6179 |
if($playlist == 1); |
| 6180 |
print PLST "GS$_:$riptrackname.suffix\n" if($playlist == 2); |
| 6181 |
} |
| 6182 |
else { |
| 6183 |
if($ghost == 1 && -r "$wavdir/ghost.log") { |
| 6184 |
open(GHOST, "<$wavdir/ghost.log") |
| 6185 |
or print "Can not read file ghost.log!\n"; |
| 6186 |
my @errlines = <GHOST>; |
| 6187 |
close(GHOST); |
| 6188 |
my @seclines = grep(s/^Array secondlist: //, @errlines); |
| 6189 |
@secondlist = split(/ /, $seclines[$#seclines]); |
| 6190 |
chomp($_) foreach(@secondlist); |
| 6191 |
} |
| 6192 |
print PLST "#EXTINF:$secondlist[$_ - 1],$tracktag\n" |
| 6193 |
if($hiddenflag == 0); |
| 6194 |
print PLST "#EXTINF:$secondlist[$_],$tracktag\n" |
| 6195 |
if($hiddenflag == 1); |
| 6196 |
print PLST "Sepdir/$riptrackname.suffix\n" |
| 6197 |
if($playlist == 1); |
| 6198 |
print PLST "$riptrackname.suffix\n" if($playlist == 2); |
| 6199 |
print PLST "Add Ghost Song $_ Here.\n" |
| 6200 |
if($ghost == 1 || $ghostflag == 1); |
| 6201 |
} |
| 6202 |
} |
| 6203 |
last if($cdcue > 0); |
| 6204 |
} |
| 6205 |
|
| 6206 |
print "\n" if($verbose > 2); |
| 6207 |
# Only add albumgain and md5sum calculation if all tracks are done, |
| 6208 |
# this might not be the case when running with more than one thread |
| 6209 |
# or using remote process. In the later case, we need to add coverart |
| 6210 |
# and album gain before calculating md5sums, so: move all this stuff |
| 6211 |
# to del_erlog! |
| 6212 |
|
| 6213 |
# Tell the mother process the encoding time. |
| 6214 |
open(ERR, ">>$wavdir/error.log") |
| 6215 |
or print "Can not append to file error.log!\n"; |
| 6216 |
print ERR "Encoding needed $totalencs seconds!\n"; |
| 6217 |
print ERR "md5: $_\n" foreach(@md5tracks); |
| 6218 |
print ERR "mp3tags: $_\n" foreach(@mp3tags); |
| 6219 |
print ERR "flac-cover: /tmp/ripit-flac-cov-$$.jpg\n" |
| 6220 |
if(defined $coverpath and -f "/tmp/ripit-flac-cov-$$.jpg"); |
| 6221 |
close(ERR); |
| 6222 |
close(PLST); |
| 6223 |
exit unless($normalize == 1 or $cdcue > 0 or $rip == 0); |
| 6224 |
} |
| 6225 |
######################################################################## |
| 6226 |
# |
| 6227 |
# Finish the M3U file used by players such as Amarok, Noatun, X11Amp... |
| 6228 |
# Use this subroutine to create a cue file. |
| 6229 |
# |
| 6230 |
sub create_m3u { |
| 6231 |
my $playfile; |
| 6232 |
my @mp3s = (); |
| 6233 |
|
| 6234 |
my $albumtag = clean_all($album_utf8); |
| 6235 |
my $artistag = clean_all($artist_utf8); |
| 6236 |
my $album = $albumtag; |
| 6237 |
my $artist = $artistag; |
| 6238 |
$album = clean_name($album); |
| 6239 |
$artist = clean_name($artist); |
| 6240 |
$album = clean_chars($album) if($chars); |
| 6241 |
$artist = clean_chars($artist) if($chars); |
| 6242 |
|
| 6243 |
$playfile = "$artist" . " - " . "$album" . ".m3u"; |
| 6244 |
$playfile =~ s/\.m3u$/.rec/ if($rip == 0); |
| 6245 |
$playfile =~ s/ /_/g if($underscore == 1); |
| 6246 |
if($limit_flag == 255) { |
| 6247 |
$playfile = substr($playfile, 0, 240); |
| 6248 |
} |
| 6249 |
|
| 6250 |
# Prevent warnings in some rare cases if no tracks have been ripped. |
| 6251 |
return unless(-r "$wavdir/$playfile"); |
| 6252 |
|
| 6253 |
open(PLST, "<$wavdir/$playfile") |
| 6254 |
or print "Can not open file $wavdir/$playfile!\n"; |
| 6255 |
my @playlines = <PLST>; |
| 6256 |
close(PLST); |
| 6257 |
my @ghosts = grep(/^GS\d+:/, @playlines); |
| 6258 |
|
| 6259 |
unlink("$wavdir/$playfile"); |
| 6260 |
# Once the safe playlist-file from re-encoding is purged, use the |
| 6261 |
# common suffix. |
| 6262 |
$playfile =~ s/\.rec$/.m3u/ if($rip == 0); |
| 6263 |
|
| 6264 |
# Do not overwrite existing playlist-files. |
| 6265 |
# Rename existing playlist file. |
| 6266 |
if(-f "$wavdir/$playfile" and $rip == 0) { |
| 6267 |
my $nplayfile = $playfile; |
| 6268 |
my $counter = 1; |
| 6269 |
$nplayfile =~ s/\.m3u$/ orig.m3u/; |
| 6270 |
# Warn if the backup file exists. |
| 6271 |
while(-r "$wavdir/$nplayfile") { |
| 6272 |
$nplayfile =~ s/.orig\.m3u/.m3u/; |
| 6273 |
$nplayfile =~ s/.orig.\d+\.m3u/.m3u/; |
| 6274 |
$nplayfile =~ s/\.m3u$/ orig $counter.m3u/; |
| 6275 |
$nplayfile =~ s/ /_/g if($underscore == 1); |
| 6276 |
$counter++; |
| 6277 |
if($counter > 10) { |
| 6278 |
print "Existing playlist backup file $nplayfile will be ", |
| 6279 |
"orverwritten, too many checks failed.\n" |
| 6280 |
if($verbose >= 3); |
| 6281 |
} |
| 6282 |
last if($counter > 10); |
| 6283 |
} |
| 6284 |
rename("$wavdir/$playfile", "$wavdir/$nplayfile"); |
| 6285 |
print "Existing file $playfile renamed to $nplayfile.\n" |
| 6286 |
if($verbose >= 3); |
| 6287 |
} |
| 6288 |
|
| 6289 |
# Modify placeholders for ghostsongs |
| 6290 |
my @playlist = (); |
| 6291 |
foreach (@playlines) { |
| 6292 |
# All lines with GS have been extracted from the @playlines into |
| 6293 |
# array @ghosts, so skip them if encountered within @playlines. |
| 6294 |
next if($_ =~ /^GS\d+:/ || $_ =~ /^$/); |
| 6295 |
$_ =~ s/^Add Ghost Song (\d+) Here.$/$1/; |
| 6296 |
chomp $_; |
| 6297 |
if($_ =~ /^\d+$/) { |
| 6298 |
# Now keep track of remaining ghost songs: |
| 6299 |
my @ghosts_remain = (); |
| 6300 |
foreach my $ghostsong (@ghosts) { |
| 6301 |
if($ghostsong =~ s/^GS$_\://) { # Why not as a 1-liner? |
| 6302 |
$ghostsong =~ s/^GS$_\://; |
| 6303 |
chomp $ghostsong; |
| 6304 |
push(@playlist, $ghostsong); |
| 6305 |
} |
| 6306 |
else { |
| 6307 |
push(@ghosts_remain, $ghostsong); |
| 6308 |
} |
| 6309 |
} |
| 6310 |
@ghosts = @ghosts_remain; |
| 6311 |
} |
| 6312 |
else { |
| 6313 |
push @playlist, $_; |
| 6314 |
} |
| 6315 |
} |
| 6316 |
# Add trailing ghost songs |
| 6317 |
if(defined $ghosts[0]) { |
| 6318 |
foreach my $ghostsong (@ghosts) { |
| 6319 |
chomp $ghostsong; |
| 6320 |
$ghostsong =~ s/^GS\d+\://; |
| 6321 |
push(@playlist, $ghostsong); |
| 6322 |
} |
| 6323 |
} |
| 6324 |
|
| 6325 |
my $cplayfile; |
| 6326 |
my $nplayfile; |
| 6327 |
my @cuelist = @playlist; |
| 6328 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 6329 |
my $trackoffsetflag = 0; |
| 6330 |
my @mp3s = @playlist; |
| 6331 |
$_ =~ s/\.suffix$/.$suffix[$c]/i foreach (@mp3s); |
| 6332 |
$_ =~ s/^Sepdir/$sepdir[$c]/ foreach (@mp3s); |
| 6333 |
# Extension of playlist-file only needed when more than one |
| 6334 |
# encoder selected. Using separate dirs, this would not be |
| 6335 |
# necessary, but who says we use them? We keep the extension. |
| 6336 |
# Side note for the $rip == 0 case (re-encoding and recreation of |
| 6337 |
# a playlist file): Cleanup of paths for comparison. |
| 6338 |
$inputdir =~ s/\/$//; |
| 6339 |
if($#coder != 0 or ($rip == 0 and $inputdir eq $sepdir[$c])) { |
| 6340 |
$nplayfile = $playfile; |
| 6341 |
$nplayfile = change_case($nplayfile, "t"); |
| 6342 |
$nplayfile =~ s/\.m3u$/ - $suffix[$c].m3u/ |
| 6343 |
if($underscore == 0); |
| 6344 |
$nplayfile =~ s/\.m3u$/_-_$suffix[$c].m3u/ |
| 6345 |
if($underscore == 1); |
| 6346 |
$cplayfile = $nplayfile; |
| 6347 |
$cplayfile =~ s/m3u$/cue/; |
| 6348 |
# If file exists from previous run with --addtrackoffset or |
| 6349 |
# --trackoffset, do not overwrite it; read content first and |
| 6350 |
# append it afterwards. If this happens repeated times, this |
| 6351 |
# will screw up the playlist file. |
| 6352 |
if(-f "$sepdir[$c]/$nplayfile" and ($addtrackoffset == 1 and |
| 6353 |
$trackoffset > 0 )) { |
| 6354 |
open(PLST, "<$sepdir[$c]/$nplayfile") or |
| 6355 |
print "Can't open $sepdir[$c]/$nplayfile! $!\n"; |
| 6356 |
@playlines = <PLST>; |
| 6357 |
close PLST; |
| 6358 |
$trackoffsetflag = 1; |
| 6359 |
} |
| 6360 |
open(PLST, ">$sepdir[$c]/$nplayfile") or |
| 6361 |
print "Can't open $sepdir[$c]/$nplayfile! $!\n"; |
| 6362 |
# Not so sure what users want (what a cue sheet is needed for). |
| 6363 |
# Rather create a second file. |
| 6364 |
if(-f "$sepdir[$c]/$cplayfile" and ($addtrackoffset == 1 and |
| 6365 |
$trackoffset > 0 and $cue > 0)) { |
| 6366 |
$cplayfile =~ s/\.cue$/ $discno.cue/ if($underscore == 0); |
| 6367 |
$cplayfile =~ s/\.cue$/_$discno.cue/ if($underscore == 1); |
| 6368 |
} |
| 6369 |
if($cue > 0) { |
| 6370 |
open(CLST, ">$sepdir[$c]/$cplayfile") or |
| 6371 |
print "Can't open $sepdir[$c]/$cplayfile! $!\n"; |
| 6372 |
} |
| 6373 |
} |
| 6374 |
else { |
| 6375 |
$nplayfile = $playfile; |
| 6376 |
$cplayfile = $nplayfile; |
| 6377 |
$cplayfile =~ s/m3u$/cue/; |
| 6378 |
open(PLST, ">$sepdir[$c]/$nplayfile") or |
| 6379 |
print "Can't open $sepdir[$c]/$nplayfile! $!\n"; |
| 6380 |
if($cue > 0) { |
| 6381 |
open(CLST, ">$sepdir[$c]/$cplayfile") or |
| 6382 |
print "Can't open $sepdir[$c]/$cplayfile! $!\n"; |
| 6383 |
} |
| 6384 |
} |
| 6385 |
# Add original playlist-files to the playlist. |
| 6386 |
if($trackoffsetflag == 1) { |
| 6387 |
print "\nAdding playlist info from previous run, please check", |
| 6388 |
" the new playlist file\n$sepdir[$c]/$nplayfile", |
| 6389 |
"\nfor consistency.\n" |
| 6390 |
if($verbose > 2); |
| 6391 |
foreach(@playlines) { |
| 6392 |
chomp; |
| 6393 |
print PLST "$_\n"; |
| 6394 |
# Actually, do not add infos from previous runs, rather |
| 6395 |
# create a new file. |
| 6396 |
# print CLST "$_\n" if($cue > 0); |
| 6397 |
} |
| 6398 |
# Remove header line of new playlist file. |
| 6399 |
shift(@mp3s); |
| 6400 |
} |
| 6401 |
print PLST "$_\n" foreach(@mp3s); |
| 6402 |
close(PLST); |
| 6403 |
if($cue > 0) { |
| 6404 |
my $cn = 0; |
| 6405 |
my $pos = 0; |
| 6406 |
my $tn = ""; |
| 6407 |
@cuelist = @playlist; |
| 6408 |
foreach(@cuelist) { |
| 6409 |
s/^#\s*/REM /; |
| 6410 |
s/^Sepdir\///; |
| 6411 |
s/\.suffix$/.$suffix[$c]/i; |
| 6412 |
if($pos == 1) { |
| 6413 |
my $dcn = sprintf("%02d", $cn); |
| 6414 |
my $suf = uc($suffix[$c]); |
| 6415 |
print CLST "FILE \"$_\" $suf\n"; |
| 6416 |
print CLST " TRACK $dcn AUDIO\n TITLE \"$tn\"\n", |
| 6417 |
" PERFORMER \"$artistag\"\n INDEX 01 00:00:00\n"; |
| 6418 |
$pos = 0; |
| 6419 |
} |
| 6420 |
elsif(/^REM EXTINF/) { |
| 6421 |
$tn = $_; |
| 6422 |
$tn =~ s/^REM EXTINF:\d*,\s*//; |
| 6423 |
$pos = 1; |
| 6424 |
print CLST "TITLE \"$albumtag\"\n", |
| 6425 |
"PERFORMER \"$artistag\"\n" if($cn == 0); |
| 6426 |
$cn++; |
| 6427 |
} |
| 6428 |
else { |
| 6429 |
print CLST "$_\n" unless(/REM EXTM3U/); |
| 6430 |
} |
| 6431 |
} |
| 6432 |
close(CLST); |
| 6433 |
} |
| 6434 |
|
| 6435 |
chmod oct($fpermission), "$sepdir[$c]/$nplayfile" |
| 6436 |
if($fpermission); |
| 6437 |
chmod oct($fpermission), "$sepdir[$c]/$cplayfile" |
| 6438 |
if($fpermission && $cue > 0); |
| 6439 |
$trackoffsetflag = 0; |
| 6440 |
|
| 6441 |
if($cue > 0 and $c == $#coder and $wav == 1) { |
| 6442 |
open(CLST, "$sepdir[$c]/$cplayfile") or |
| 6443 |
print "Can't open $sepdir[$c]/$cplayfile! $!\n"; |
| 6444 |
@cuelist = <CLST>; |
| 6445 |
close(CLST); |
| 6446 |
foreach(@cuelist) { |
| 6447 |
s/\s$suffix[$c]$/ WAVE/i; |
| 6448 |
s/\.$suffix[$c]/.wav/; |
| 6449 |
} |
| 6450 |
} |
| 6451 |
} |
| 6452 |
# Recreate the wav-playlist if wavs aren't deleted. |
| 6453 |
if($wav == 1) { |
| 6454 |
my @mp3s = @playlist; |
| 6455 |
$_ =~ s/\.suffix$/\.wav/i foreach (@mp3s); |
| 6456 |
$_ =~ s/^Sepdir/$wavdir/ foreach (@mp3s); |
| 6457 |
$nplayfile = $playfile; |
| 6458 |
$nplayfile = change_case($nplayfile, "t"); |
| 6459 |
$nplayfile =~ s/\.m3u$/ - wav\.m3u/ |
| 6460 |
if($underscore == 0); |
| 6461 |
$nplayfile =~ s/\.m3u$/_-_wav\.m3u/ |
| 6462 |
if($underscore == 1); |
| 6463 |
open(PLST, ">$wavdir/$nplayfile") or |
| 6464 |
print "Can't open $wavdir/$nplayfile! $!\n"; |
| 6465 |
print PLST "$_\n" foreach(@mp3s); |
| 6466 |
close(PLST); |
| 6467 |
if($cue > 0) { |
| 6468 |
$cplayfile = $nplayfile; |
| 6469 |
$cplayfile =~ s/m3u$/cue/; |
| 6470 |
open(CLST, ">$wavdir/$cplayfile") or |
| 6471 |
print "Can't open $wavdir/$cplayfile! $!\n"; |
| 6472 |
foreach(@cuelist) { |
| 6473 |
print CLST "$_"; |
| 6474 |
} |
| 6475 |
close(CLST); |
| 6476 |
} |
| 6477 |
chmod oct($fpermission), "$wavdir/$nplayfile" |
| 6478 |
if($fpermission); |
| 6479 |
chmod oct($fpermission), "$wavdir/$cplayfile" |
| 6480 |
if($fpermission and $cue > 0); |
| 6481 |
} |
| 6482 |
} |
| 6483 |
######################################################################## |
| 6484 |
# |
| 6485 |
# Create a default or manual track list. |
| 6486 |
# |
| 6487 |
sub create_deftrack { |
| 6488 |
# Let operator chose to use default names or enter them manually. |
| 6489 |
# Do not ask if we come form CDDB submission, i.e. index == 0, |
| 6490 |
# or if $interaction == 0, then $index == 1. |
| 6491 |
my ($i, $j, $index) = (0,1,@_); |
| 6492 |
my ($album, $artist); |
| 6493 |
|
| 6494 |
my $tracks = substr($cddbid, 6); |
| 6495 |
$tracks = hex($tracks); |
| 6496 |
|
| 6497 |
$album = clean_all($album_utf8) if(defined $cd{title}); |
| 6498 |
$artist = clean_all($artist_utf8) if(defined $cd{artist}); |
| 6499 |
|
| 6500 |
# Preselect answer if no interaction requested. |
| 6501 |
$index = 1 if($interaction == 0); |
| 6502 |
|
| 6503 |
while($index !~ /^[0-1]$/ ) { |
| 6504 |
print "\nThis CD shall be labeled with:\n\n"; |
| 6505 |
print "1: Default album, artist and track names\n\n"; |
| 6506 |
print "0: Manual input\n\nChoose [0-1]: (0) "; |
| 6507 |
$index = <STDIN>; |
| 6508 |
chomp $index; |
| 6509 |
$index = 0 unless($index); |
| 6510 |
print "\n"; |
| 6511 |
} |
| 6512 |
# Create default tracklist and cd-hash. |
| 6513 |
# NOTE: here we define an additional key: revision, which does not |
| 6514 |
# exist if %cd is filled by CDDB_get. If this key exists we know |
| 6515 |
# that it is a new entry. |
| 6516 |
if($index == 1) { |
| 6517 |
$artist = "Unknown Artist"; |
| 6518 |
$album = "Unknown Album"; |
| 6519 |
%cd = ( |
| 6520 |
artist => $artist, |
| 6521 |
title => $album, |
| 6522 |
cat => $categ, |
| 6523 |
genre => $genre, |
| 6524 |
id => $cddbid, |
| 6525 |
revision => 0, |
| 6526 |
year => $year, |
| 6527 |
); |
| 6528 |
while($i < $tracks) { |
| 6529 |
$j = $i + 1; |
| 6530 |
$j = "0" . $j if($j < 10); |
| 6531 |
$cd{track}[$i] = "Track " . "$j"; |
| 6532 |
++$i; |
| 6533 |
} |
| 6534 |
$cddbsubmission = 0; |
| 6535 |
} |
| 6536 |
# Create manual tracklist. |
| 6537 |
elsif($index == 0) { |
| 6538 |
# In case of CDDB resubmission |
| 6539 |
if(defined $cd{artist}) { |
| 6540 |
print "\n Artist ($artist): "; |
| 6541 |
} |
| 6542 |
# In case of manual CDDB entry. |
| 6543 |
else { |
| 6544 |
print "\n Artist : "; |
| 6545 |
} |
| 6546 |
$artist = <STDIN>; |
| 6547 |
chomp $artist; |
| 6548 |
# If CDDB entry confirmed, take it. |
| 6549 |
if(defined $cd{artist} && $artist eq "") { |
| 6550 |
$artist = $artist_utf8; |
| 6551 |
} |
| 6552 |
# If CDDB entry CHANGED, submission OK. |
| 6553 |
elsif(defined $cd{artist} && $artist ne "") { |
| 6554 |
$cddbsubmission = 1; |
| 6555 |
$cd{artist} = $artist; |
| 6556 |
$artist_utf8 = $artist; |
| 6557 |
} |
| 6558 |
if($artist eq "") { |
| 6559 |
$artist = "Unknown Artist"; |
| 6560 |
$cddbsubmission = 0; |
| 6561 |
} |
| 6562 |
if(defined $cd{title}) { |
| 6563 |
print "\n Album ($album): "; |
| 6564 |
} |
| 6565 |
else { |
| 6566 |
print "\n Album : "; |
| 6567 |
} |
| 6568 |
$album = <STDIN>; |
| 6569 |
chomp $album; |
| 6570 |
while($year !~ /^\d{4}$/) { |
| 6571 |
if(defined $cd{year}) { |
| 6572 |
print "\n Year ($year): "; |
| 6573 |
} |
| 6574 |
else { |
| 6575 |
print "\n year : "; |
| 6576 |
} |
| 6577 |
$year = <STDIN>; |
| 6578 |
chomp $year; |
| 6579 |
last if($year eq ""); |
| 6580 |
} |
| 6581 |
# If CDDB entry confirmed, take it. |
| 6582 |
if(defined $cd{title} && $album eq "") { |
| 6583 |
$album = $album_utf8; |
| 6584 |
} |
| 6585 |
# If CDDB entry CHANGED, submission OK. |
| 6586 |
elsif(defined $cd{title} && $album ne "") { |
| 6587 |
$cddbsubmission = 1; |
| 6588 |
$cd{title} = $album; |
| 6589 |
$album_utf8 = $album; |
| 6590 |
} |
| 6591 |
if($album eq "") { |
| 6592 |
$album = "Unknown Album"; |
| 6593 |
$cddbsubmission = 0; |
| 6594 |
} |
| 6595 |
%cd = ( |
| 6596 |
artist => $artist, |
| 6597 |
title => $album, |
| 6598 |
cat => $categ, |
| 6599 |
genre => $genre, |
| 6600 |
id => $cddbid, |
| 6601 |
revision => 0, |
| 6602 |
year => $year, |
| 6603 |
) unless(defined $cd{title}); |
| 6604 |
print "\n"; |
| 6605 |
$i = 1; |
| 6606 |
while($i <= $tracks) { |
| 6607 |
if(defined $cd{track}[$i-1]) { |
| 6608 |
printf(" Track %02d (%s): ", $i + $trackoffset, $tracktags[$i-1]); |
| 6609 |
} |
| 6610 |
else { |
| 6611 |
printf(" Track %02d: ", $i + $trackoffset); |
| 6612 |
} |
| 6613 |
my $tracktag = <STDIN>; |
| 6614 |
chomp $tracktag; |
| 6615 |
$tracktag = clean_all($tracktag); |
| 6616 |
my $track = $tracktag; |
| 6617 |
$track = clean_name($track); |
| 6618 |
$track = clean_chars($track) if($chars); |
| 6619 |
$track = change_case($track, "t"); |
| 6620 |
$track =~ s/ /_/g if($underscore == 1); |
| 6621 |
# If CDDB entry confirmed, take and replace it in tracklist. |
| 6622 |
if(defined $cd{track}[$i-1] && $track ne "") { |
| 6623 |
splice @tracklist, $i-1, 1, $track; |
| 6624 |
splice @tracktags, $i-1, 1, $tracktag; |
| 6625 |
$cddbsubmission = 1; |
| 6626 |
} |
| 6627 |
elsif(!$cd{track}[$i-1] && $track eq "") { |
| 6628 |
$track = "Track " . sprintf("%02d", $i); |
| 6629 |
$cddbsubmission = 0; |
| 6630 |
} |
| 6631 |
# Fill the "empty" array @{$cd{track}}. |
| 6632 |
push(@{$cd{track}}, "$track"); |
| 6633 |
$i++; |
| 6634 |
} |
| 6635 |
print "\n"; |
| 6636 |
} |
| 6637 |
else { |
| 6638 |
# I don't like die, but I don't like if-loops without else. |
| 6639 |
# This should not happen because of previous while-loop! |
| 6640 |
die "Choose 0 or 1!\n\n"; |
| 6641 |
} |
| 6642 |
return; |
| 6643 |
} |
| 6644 |
######################################################################## |
| 6645 |
# |
| 6646 |
# Read the CD and generate a TOC with DiscID, track frames and total |
| 6647 |
# length. Then prepare CDDB-submission with entries from @tracklist. |
| 6648 |
# |
| 6649 |
sub pre_subm { |
| 6650 |
my($check,$i,$ans,$genreno,$line,$oldcat,$subject) = (0,0); |
| 6651 |
|
| 6652 |
my $tracks = $#framelist; |
| 6653 |
my $totals = int($framelist[$#framelist] / 75); |
| 6654 |
|
| 6655 |
my $album = clean_all($album_utf8); |
| 6656 |
my $artist = clean_all($artist_utf8); |
| 6657 |
|
| 6658 |
my $revision = get_rev() unless($cd{discid}); |
| 6659 |
if($revision) { |
| 6660 |
# TODO: if submission fails, set revision back. |
| 6661 |
$revision++; |
| 6662 |
print "Revision is set to $revision.\n" if($verbose > 4); |
| 6663 |
} |
| 6664 |
elsif(defined $cd{revsision}) { |
| 6665 |
$revision = $cd{revision}; |
| 6666 |
} |
| 6667 |
else { |
| 6668 |
$revision = 0; |
| 6669 |
} |
| 6670 |
|
| 6671 |
# Check for CDDB ID vs CD ID problems. |
| 6672 |
if($cddbid ne $cd{id} && defined $cd{id}) { |
| 6673 |
print "\nObsolet warning: CDID ($cddbid) is not identical to "; |
| 6674 |
print "CDDB entry ($cd{id})!"; |
| 6675 |
print "\nYou might get a collision error. Try anyway!\n"; |
| 6676 |
$revision = 0; |
| 6677 |
} |
| 6678 |
# Questioning to change CDDB entries and ask to fill missing fields. |
| 6679 |
if(defined $cd{year} && $year ne "") { |
| 6680 |
$year = get_answ("year",$year); |
| 6681 |
} |
| 6682 |
if(!$year) { |
| 6683 |
while($year !~ /^\d{4}$| / || !$year ) { |
| 6684 |
print "\nPlease enter the year (or none): "; |
| 6685 |
$year = <STDIN>; |
| 6686 |
chomp $year; |
| 6687 |
$cd{year} = $year; |
| 6688 |
last if(!$year); |
| 6689 |
$cddbsubmission = 1; |
| 6690 |
} |
| 6691 |
} |
| 6692 |
if($cd{year}) { |
| 6693 |
$cddbsubmission = 1 unless($year eq $cd{year}); |
| 6694 |
} |
| 6695 |
else { |
| 6696 |
$cddbsubmission = 1; |
| 6697 |
} |
| 6698 |
# Ask if CDDB category shall be changed and check if done; |
| 6699 |
# $categ will be an empty string if user wants to change it. |
| 6700 |
$oldcat = $categ; |
| 6701 |
if($cd{cat} && $categ) { |
| 6702 |
$categ = get_answ("CDDB category",$categ); |
| 6703 |
} |
| 6704 |
|
| 6705 |
my @categ = (); |
| 6706 |
my @categories = ( |
| 6707 |
"blues", "classical", "country", "data", |
| 6708 |
"folk", "jazz", "misc", "newage", |
| 6709 |
"reggae", "rock", "soundtrack" |
| 6710 |
); |
| 6711 |
|
| 6712 |
# If data is from musicbrainz, don't ask to check category and simply |
| 6713 |
# prepare a CD-DB file with category musicbrainz. User will have to |
| 6714 |
# find an unused category and submit the entry manually. |
| 6715 |
if(!$categ && !$cd{discid} && $submission != 0) { |
| 6716 |
print "Shall Ripit check for available categories?", |
| 6717 |
" [y/n] (y) "; |
| 6718 |
$ans = <STDIN>; |
| 6719 |
chomp $ans; |
| 6720 |
if($ans eq "") { |
| 6721 |
$ans = "y"; |
| 6722 |
} |
| 6723 |
if($ans =~ /^y/) { |
| 6724 |
print "\n\nAvailable categories:\n"; |
| 6725 |
foreach (@categories) { |
| 6726 |
my $templines = ""; |
| 6727 |
my $source = "http://www.freedb.org/freedb/" . |
| 6728 |
$_ . "/" . $cddbid; |
| 6729 |
$templines = LWP::Simple::get($source); |
| 6730 |
# Question: what is wrong that I need to put a \n in the print |
| 6731 |
# command to force perl to print right away, and not to print |
| 6732 |
# the whole bunch only when the foreach-loop is done??? |
| 6733 |
if($templines) { |
| 6734 |
push @categ, $_; |
| 6735 |
} |
| 6736 |
else { |
| 6737 |
print " $_\n" |
| 6738 |
} |
| 6739 |
} |
| 6740 |
if($categ[10]) { |
| 6741 |
print "\nAll 11 categories are used, bad luck!"; |
| 6742 |
print "\nSave the file locally with --archive!\n"; |
| 6743 |
print "\nUse one of the following categories:"; |
| 6744 |
print "\nblues, classical, country, data, folk"; |
| 6745 |
print "\njazz, misc, newage, reggae, rock, soundtrack\n"; |
| 6746 |
$cddbsubmission = 0; |
| 6747 |
} |
| 6748 |
|
| 6749 |
# Check if the $categ variable is correct. |
| 6750 |
while($categ !~ m/^blues$|^classical$|^country$|^data$|^folk$| |
| 6751 |
|^jazz$|^newage$|^reggae$|^rock$|^soundtrack$| |
| 6752 |
|^misc$/ ) { |
| 6753 |
print "\nPlease choose one of the available CDDB categories: " |
| 6754 |
if($categ[10]); |
| 6755 |
print "\nPlease choose one of the categories: " |
| 6756 |
unless($categ[10]); |
| 6757 |
$categ = <STDIN>; |
| 6758 |
chomp $categ; |
| 6759 |
} |
| 6760 |
$cddbsubmission = 1 unless($categ eq $cd{cat}); |
| 6761 |
} |
| 6762 |
} |
| 6763 |
elsif($cd{discid}) { |
| 6764 |
# Are we sure to use this condition to prevent further submission? |
| 6765 |
$categ = "musicbrainz"; |
| 6766 |
$cddbsubmission = 0; |
| 6767 |
} |
| 6768 |
# If one changes category for a new submission, set Revision to 0. |
| 6769 |
if($oldcat ne $categ && defined $cd{cat}) { |
| 6770 |
$revision = 0; |
| 6771 |
} |
| 6772 |
# Remind the user if genre is not ID3v2 compliant even if Lame is |
| 6773 |
# not used! Reason: There should be no garbage genres in the DB. |
| 6774 |
# If Lame is used, genre has already been checked! |
| 6775 |
if($lameflag != 1 && defined $genre) { |
| 6776 |
($genre,$genreno) = check_genre($genre); |
| 6777 |
$cddbsubmission = 1 unless($genre eq $cd{genre}); |
| 6778 |
} |
| 6779 |
# Do not to ask if genre has been passed from command line, except if |
| 6780 |
# looping and one migt want to change the genre. |
| 6781 |
if($loop > 0) { |
| 6782 |
# Ask |
| 6783 |
$genre = get_answ("genre", $genre); |
| 6784 |
} |
| 6785 |
else { |
| 6786 |
unless($pgenre) { |
| 6787 |
$genre = get_answ("genre", $genre); |
| 6788 |
} |
| 6789 |
} |
| 6790 |
unless($genre) { |
| 6791 |
print "\nPlease enter a valid CDDB genre (or none): "; |
| 6792 |
$genre = <STDIN>; |
| 6793 |
chomp $genre; |
| 6794 |
$cd{genre} = $genre; |
| 6795 |
# Allow to submit no genre! Else check it! |
| 6796 |
if($genre) { |
| 6797 |
$genre =~ s/[\015]//g; |
| 6798 |
($genre, $genreno) = check_genre($genre); |
| 6799 |
} |
| 6800 |
} |
| 6801 |
$cddbsubmission = 1 unless($genre eq $cd{'genre'}); |
| 6802 |
my $dtitle = $artist . " / " . $album; |
| 6803 |
substr($dtitle, 230, 0, "\nDTITLE=") if(length($dtitle) > 250); |
| 6804 |
substr($dtitle, 460, 0, "\nDTITLE=") if(length($dtitle) > 500); |
| 6805 |
|
| 6806 |
# Start writing the CDDB submission. |
| 6807 |
open(TOC, ">$homedir/cddb.toc") |
| 6808 |
or print "Can not write to cddb.toc $!\n"; |
| 6809 |
print TOC "# xmcd CD database generated by RipIT\n#\n", |
| 6810 |
"# Track frame offsets:\n"; |
| 6811 |
$i = 0; |
| 6812 |
foreach (@framelist) { |
| 6813 |
print TOC "# $_\n" if($i < $#framelist); |
| 6814 |
$i++; |
| 6815 |
} |
| 6816 |
print TOC "#\n# Disc length: $totals seconds\n#\n"; |
| 6817 |
if(!$cd{discid} && $archive == 1 && $categ ne "musicbrainz") { |
| 6818 |
my $source = "http://www.freedb.org/freedb/" . $categ . "/" . $cddbid; |
| 6819 |
print "Will try to get <$source>.\n"; |
| 6820 |
my $templines = LWP::Simple::get($source); |
| 6821 |
my @templines = split(/\n/, $templines); |
| 6822 |
chomp($revision = join('', grep(s/^\s*#\sRevision:\s(\d+)/$1/, @templines))); |
| 6823 |
$revision++ if($revision =~ /^\d+/); |
| 6824 |
$revision = 0 unless($revision =~ /^\d+/); |
| 6825 |
print "\nRevision number set to $revision.\n" if($verbose >= 4); |
| 6826 |
} |
| 6827 |
print TOC "# Revision: $revision\n"; |
| 6828 |
my $time = sprintf("%02d:%02d", sub {$_[2], $_[1]}->(localtime)); |
| 6829 |
my $date = sprintf("%04d-%02d-%02d", |
| 6830 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 6831 |
$date = $date . " at " . $time; |
| 6832 |
print TOC "# Submitted via: RipIT $version "; |
| 6833 |
print TOC "www.suwald.com/ripit/ripit.html on $date\n"; |
| 6834 |
print TOC "#\n"; |
| 6835 |
print TOC "DISCID=$cddbid\n"; |
| 6836 |
print TOC "DTITLE=$dtitle\n"; |
| 6837 |
print TOC "DYEAR=$year\n"; |
| 6838 |
if(defined $genre) { |
| 6839 |
print TOC "DGENRE=$genre\n"; |
| 6840 |
} |
| 6841 |
elsif($genre eq "" && defined $categ) { |
| 6842 |
print TOC "DGENRE=$categ\n"; |
| 6843 |
} |
| 6844 |
$i = 0; |
| 6845 |
foreach (@tracktags) { |
| 6846 |
# Don't alter the real track tags! |
| 6847 |
my $line = $_; |
| 6848 |
my $limit = 230; |
| 6849 |
my $j = $i; |
| 6850 |
$j += $trackoffset if($trackoffset > 0); |
| 6851 |
while(length($line) > $limit) { |
| 6852 |
substr($line, $limit, 0, "\nTTITLE$j="); |
| 6853 |
$limit += 230; |
| 6854 |
} |
| 6855 |
print TOC "TTITLE$j=$line\n"; |
| 6856 |
++$i; |
| 6857 |
} |
| 6858 |
|
| 6859 |
my @comment = extract_comm; |
| 6860 |
my $commentest = "@comment"; |
| 6861 |
if($commentest) { |
| 6862 |
$ans = "x"; |
| 6863 |
$check = 0; |
| 6864 |
print "Confirm (Enter), delete or edit each comment line "; |
| 6865 |
print "(c/d/e)!\n"; |
| 6866 |
foreach (@comment) { |
| 6867 |
chomp($_); |
| 6868 |
s/\n//g; |
| 6869 |
next if($_ eq ""); |
| 6870 |
while($ans !~ /^c|^d|^e/) { |
| 6871 |
print "$_ (c/d/e): "; |
| 6872 |
$ans = <STDIN>; |
| 6873 |
chomp $ans; |
| 6874 |
if($ans eq "") { |
| 6875 |
$ans = "c"; |
| 6876 |
} |
| 6877 |
} |
| 6878 |
if($ans =~ /^c/ || $ans eq "") { |
| 6879 |
print TOC "EXTD=$_\\n\n"; |
| 6880 |
$check = 1; |
| 6881 |
} |
| 6882 |
elsif($ans =~ /^e/) { |
| 6883 |
print "Enter a different line: \n"; |
| 6884 |
my $ans = <STDIN>; |
| 6885 |
chomp $ans; |
| 6886 |
substr($ans, 230, 0, "\nEXTD=") if(length($ans) > 250); |
| 6887 |
substr($ans, 460, 0, "\nEXTD=") if(length($ans) > 500); |
| 6888 |
print TOC "EXTD=$ans\\n\n"; |
| 6889 |
$cddbsubmission = 1; |
| 6890 |
$check = 1; |
| 6891 |
} |
| 6892 |
else { |
| 6893 |
# Don't print the line. |
| 6894 |
$cddbsubmission = 1; |
| 6895 |
} |
| 6896 |
$ans = "x"; |
| 6897 |
} |
| 6898 |
$line = "a"; |
| 6899 |
while(defined $line) { |
| 6900 |
print "Do you want to add a line? (Enter for none or type!): "; |
| 6901 |
$line = <STDIN>; |
| 6902 |
chomp $line; |
| 6903 |
$cddbsubmission = 1 if($line ne ""); |
| 6904 |
last if(!$line); |
| 6905 |
substr($line, 230, 0, "\nEXTD=") if(length($line) > 250); |
| 6906 |
substr($line, 460, 0, "\nEXTD=") if(length($line) > 500); |
| 6907 |
print TOC "EXTD=$line\\n\n"; |
| 6908 |
$check = 1; |
| 6909 |
} |
| 6910 |
# If all lines have been deleted, add an empty EXTD line! |
| 6911 |
if($check == 0) { |
| 6912 |
print TOC "EXTD=\n"; |
| 6913 |
} |
| 6914 |
} |
| 6915 |
# If there are no comments, ask to add some. |
| 6916 |
elsif(!$comment[0]) { |
| 6917 |
$line = "a"; |
| 6918 |
my $linecn = 0; |
| 6919 |
while(defined $line) { |
| 6920 |
print "Please enter a comment line (or none): "; |
| 6921 |
$line = <STDIN>; |
| 6922 |
chomp $line; |
| 6923 |
$cddbsubmission = 1 if($line ne ""); |
| 6924 |
substr($line, 230, 0, "\nEXTD=") if(length($line) > 250); |
| 6925 |
substr($line, 460, 0, "\nEXTD=") if(length($line) > 500); |
| 6926 |
print TOC "EXTD=$line\n" if($linecn == 0); |
| 6927 |
print TOC "EXTD=\\n$line\n" if($linecn != 0); |
| 6928 |
$linecn++; |
| 6929 |
# This line has to be written, so break the |
| 6930 |
# while loop here and not before, as above. |
| 6931 |
last if(!$line); |
| 6932 |
} |
| 6933 |
} |
| 6934 |
else { |
| 6935 |
print TOC "EXTD=\n"; |
| 6936 |
} |
| 6937 |
|
| 6938 |
# Extract the track comment lines EXTT. |
| 6939 |
my @trackcom = grep(/^EXTT\d+=/, @{$cd{raw}}); |
| 6940 |
@trackcom = grep(s/^EXTT\d+=//, @trackcom); |
| 6941 |
foreach (@trackcom) { |
| 6942 |
chomp($_); |
| 6943 |
s/\n//g; |
| 6944 |
s/[\015]//g; |
| 6945 |
} |
| 6946 |
$ans = get_answ('Track comment','existing ones'); |
| 6947 |
if($ans eq "") { |
| 6948 |
$i = 0; |
| 6949 |
while($i < $tracks) { |
| 6950 |
my $track; |
| 6951 |
if($trackcom[$i]) { |
| 6952 |
printf(" Track comment %02d (%s):", $i+1, $trackcom[$i]); |
| 6953 |
} |
| 6954 |
else { |
| 6955 |
printf(" Track comment %02d: ", $i+1); |
| 6956 |
} |
| 6957 |
$track = <STDIN>; |
| 6958 |
chomp $track; |
| 6959 |
my $j = $i; |
| 6960 |
$j += $trackoffset if($trackoffset > 0); |
| 6961 |
substr($track, 230, 0, "\nEXTT$j=") if(length($track) > 250); |
| 6962 |
substr($track, 460, 0, "\nEXTT$j=") if(length($track) > 500); |
| 6963 |
|
| 6964 |
# If CDDB entry confirmed, take and replace it in tracklist. |
| 6965 |
if(defined $trackcom[$i] && $track eq "") { |
| 6966 |
print TOC "EXTT$j=$trackcom[$i]\n"; |
| 6967 |
} |
| 6968 |
elsif(defined $trackcom[$i] && $track ne "") { |
| 6969 |
print TOC "EXTT$j=$track\n"; |
| 6970 |
$cddbsubmission = 1; |
| 6971 |
} |
| 6972 |
elsif($track ne "") { |
| 6973 |
print TOC "EXTT$j=$track\n"; |
| 6974 |
$cddbsubmission = 1; |
| 6975 |
} |
| 6976 |
else { |
| 6977 |
print TOC "EXTT$j=\n"; |
| 6978 |
} |
| 6979 |
$i++; |
| 6980 |
} |
| 6981 |
} |
| 6982 |
elsif(@trackcom) { |
| 6983 |
$i = 0; |
| 6984 |
my $j = $i; |
| 6985 |
$j += $trackoffset if($trackoffset > 0); |
| 6986 |
foreach (@tracklist) { |
| 6987 |
print TOC "EXTT$j=$trackcom[$i]\n"; |
| 6988 |
++$i; |
| 6989 |
} |
| 6990 |
} |
| 6991 |
else { |
| 6992 |
$i = 0; |
| 6993 |
my $j = $i; |
| 6994 |
$j += $trackoffset if($trackoffset > 0); |
| 6995 |
foreach (@tracklist) { |
| 6996 |
print TOC "EXTT$j=\n"; |
| 6997 |
++$i; |
| 6998 |
} |
| 6999 |
} |
| 7000 |
|
| 7001 |
# Extract the playorder line. |
| 7002 |
my @playorder = grep(/^PLAYORDER=/, @{$cd{raw}}); |
| 7003 |
@playorder = grep(s/^PLAYORDER=//, @playorder); |
| 7004 |
if(@playorder) { |
| 7005 |
my $playorder = $playorder[0]; |
| 7006 |
chomp $playorder; |
| 7007 |
print TOC "PLAYORDER=$playorder\n"; |
| 7008 |
} |
| 7009 |
else { |
| 7010 |
print TOC "PLAYORDER=\n"; |
| 7011 |
} |
| 7012 |
|
| 7013 |
# If no connection to the internet do not submit. |
| 7014 |
if($submission == 0) { |
| 7015 |
$cddbsubmission = 0; |
| 7016 |
} |
| 7017 |
# If we came from MB do not submit. |
| 7018 |
elsif($cd{discid}) { |
| 7019 |
$cddbsubmission = 0; |
| 7020 |
} |
| 7021 |
|
| 7022 |
# Only print non regular info to the toc if no submission will happen. |
| 7023 |
if($cddbsubmission == 0) { |
| 7024 |
print TOC "CDINDEX=", $cd{discid}, "\n" if($cd{discid}); |
| 7025 |
print TOC "MBREID=", $cd{mbreid}, "\n" if($cd{mbreid}); |
| 7026 |
print TOC "ASIN=", $cd{asin}, "\n" if($cd{asin}); |
| 7027 |
print TOC "DGID=", $cd{dgid}, "\n" if($cd{dgid}); |
| 7028 |
print TOC "BARCODE=", $cd{barcode}, "\n" if($cd{barcode}); |
| 7029 |
print TOC "CATALOG=", $cd{catalog}, "\n" if($cd{catalog}); |
| 7030 |
print TOC "RELDAT=", $cd{reldate}, "\n" if($cd{reldate}); |
| 7031 |
print TOC "LANG=", $cd{language}, "\n" if($cd{language}); |
| 7032 |
print TOC "DISCNO=", $cd{discno}, "\n" if($cd{discno}); |
| 7033 |
} |
| 7034 |
close(TOC); |
| 7035 |
|
| 7036 |
# Copy the *edited* CDDB file if variable set to the ~/.cddb/ |
| 7037 |
# directory. |
| 7038 |
if($archive == 1 && $cddbsubmission != 2) { |
| 7039 |
log_system("mkdir -m 0755 -p \"$homedir/.cddb/$categ\"") |
| 7040 |
or print |
| 7041 |
"Can not create directory \"$homedir/.cddb/$categ\": $!\n"; |
| 7042 |
log_system( |
| 7043 |
"cp \"$homedir/cddb.toc\" \"$homedir/.cddb/$categ/$cddbid\"" |
| 7044 |
) |
| 7045 |
or print |
| 7046 |
"Can not copy cddb.toc to directory ", |
| 7047 |
"\"$homedir/.cddb/$categ/$cddbid\": $!\n"; |
| 7048 |
print "Saved file $cddbid in \"$homedir/.cddb/$categ/\""; |
| 7049 |
} |
| 7050 |
print "\n"; |
| 7051 |
|
| 7052 |
if($cddbsubmission == 1) { |
| 7053 |
my $ans = "x"; |
| 7054 |
while($ans !~ /^y$|^n$/) { |
| 7055 |
print "Do you really want to submit your data to freeDB.org?", |
| 7056 |
" [y/n] (y) "; |
| 7057 |
$ans = <STDIN>; |
| 7058 |
chomp $ans; |
| 7059 |
if($ans eq "") { |
| 7060 |
$ans = "y"; |
| 7061 |
} |
| 7062 |
} |
| 7063 |
if($ans =~ /^y/) { |
| 7064 |
$cddbsubmission = 1; |
| 7065 |
} |
| 7066 |
else{ |
| 7067 |
$cddbsubmission = 0; |
| 7068 |
} |
| 7069 |
} |
| 7070 |
if($cddbsubmission == 1) { |
| 7071 |
while($mailad !~ /.@.+[.]./) { |
| 7072 |
print "\nReady for submission, enter a valid return "; |
| 7073 |
print "e-mail address: "; |
| 7074 |
$mailad = <STDIN>; |
| 7075 |
chomp $mailad; |
| 7076 |
} |
| 7077 |
|
| 7078 |
open TOC, "cat \"$homedir/cddb.toc\" |" |
| 7079 |
or die "Can not open file $homedir/cddb.toc $!\n"; |
| 7080 |
my @lines = <TOC>; |
| 7081 |
close(TOC); |
| 7082 |
|
| 7083 |
$subject = "cddb " . $categ . " " . $cddbid; |
| 7084 |
open(MAIL, "|/usr/sbin/sendmail $mailopt -r $mailad") |
| 7085 |
or print "/usr/sbin/sendmail not installed? $!\n"; |
| 7086 |
|
| 7087 |
# Generate the mail-header and add the toc-lines. |
| 7088 |
print MAIL "From: $mailad\n"; |
| 7089 |
print MAIL "To: freedb-submit\@freedb.org\n"; |
| 7090 |
# print MAIL "To: test-submit\@freedb.org\n"; |
| 7091 |
print MAIL "Subject: $subject\n"; |
| 7092 |
print MAIL "MIME-Version: 1.0\n"; |
| 7093 |
print MAIL "Content-Type: text/plain; charset=$charset\n"; |
| 7094 |
foreach (@lines) { |
| 7095 |
print MAIL $_; |
| 7096 |
} |
| 7097 |
close(MAIL); |
| 7098 |
print "Mail exit status not zero: $?" if($?); |
| 7099 |
print "CDDB entry submitted.\n\n" unless($?); |
| 7100 |
unlink("$homedir/cddb.toc"); |
| 7101 |
} |
| 7102 |
elsif($cddbsubmission == 2) { |
| 7103 |
print "\n CDDB entry created and saved in \$HOME, but not send, "; |
| 7104 |
print "because no changes"; |
| 7105 |
print "\n were made! Please edit and send it manually to "; |
| 7106 |
print "freedb-submit\@freedb.org"; |
| 7107 |
print "\n with subject: cddb "; |
| 7108 |
my $pcateg = $categ; |
| 7109 |
$pcateg = "category" if($categ =~ /musicbrainz/); |
| 7110 |
print "$pcateg $cddbid\n"; |
| 7111 |
print " where category is one of the 11 valid freedb categories.\n" |
| 7112 |
if($categ =~ /musicbrainz/); |
| 7113 |
print "\n"; |
| 7114 |
sleep (4); |
| 7115 |
} |
| 7116 |
else { |
| 7117 |
print "\n CDDB entry saved in your home directory, but not send,"; |
| 7118 |
print "\n please edit it and send it manually to:"; |
| 7119 |
print "\n freedb-submit\@freedb.org with subject:"; |
| 7120 |
print "\n cddb "; |
| 7121 |
my $pcateg = $categ; |
| 7122 |
$pcateg = "category" if($categ =~ /musicbrainz/); |
| 7123 |
print "$pcateg $cddbid\n"; |
| 7124 |
print " where category is one of the 11 valid freedb categories.\n" |
| 7125 |
if($categ =~ /musicbrainz/); |
| 7126 |
print "\n"; |
| 7127 |
} |
| 7128 |
} |
| 7129 |
######################################################################## |
| 7130 |
# |
| 7131 |
# Check if genre is correct. |
| 7132 |
# |
| 7133 |
sub check_genre { |
| 7134 |
my $genre = $_[0]; |
| 7135 |
my $genreno = ""; |
| 7136 |
my $genrenoflag = 1; |
| 7137 |
|
| 7138 |
$genre = " " if($genre eq ""); |
| 7139 |
|
| 7140 |
# If Lame is not used, don't die if ID3v2-tag is not compliant. |
| 7141 |
if($lameflag == 0) { |
| 7142 |
unless(log_system( |
| 7143 |
"lame --genre-list 2>&1 | grep -i \" $genre\$\" > /dev/null ")) { |
| 7144 |
print "Genre $genre is not ID3v2 compliant!\n" |
| 7145 |
if($verbose >= 1); |
| 7146 |
print "Continuing anyway!\n\n" if($verbose >= 1); |
| 7147 |
chomp($genreno = "not ID3v2 compliant!\n"); |
| 7148 |
} |
| 7149 |
return ($genre,$genreno); |
| 7150 |
} |
| 7151 |
|
| 7152 |
# If Lame is not installed, don't loop for ever. |
| 7153 |
if($lameflag == -1) { |
| 7154 |
chomp($genreno = "Unknown.\n"); |
| 7155 |
return ($genre,$genreno); |
| 7156 |
} |
| 7157 |
|
| 7158 |
# Check if (similar) genre exists. Enter a new one with interaction, |
| 7159 |
# or take the default one. |
| 7160 |
while(!log_system( |
| 7161 |
"lame --genre-list 2>&1 | grep -i \"$genre\" > /dev/null ")) { |
| 7162 |
print "Genre $genre is not ID3v2 compliant!\n" if($verbose >= 1); |
| 7163 |
if($interaction == 1) { |
| 7164 |
print "Use \"lame --genre-list\" to get a list!\n"; |
| 7165 |
print "\nPlease enter a valid CDDB genre (or none): "; |
| 7166 |
$genre = <STDIN>; |
| 7167 |
chomp $genre; |
| 7168 |
$cd{genre} = $genre; |
| 7169 |
} |
| 7170 |
else { |
| 7171 |
print "Genre \"Other\" will be used instead!\n" |
| 7172 |
if($verbose >= 1); |
| 7173 |
$genre = "12 Other"; |
| 7174 |
} |
| 7175 |
} |
| 7176 |
|
| 7177 |
if($genre eq "") { |
| 7178 |
return; |
| 7179 |
} |
| 7180 |
elsif($genre =~ /^\d+$/) { |
| 7181 |
chomp($genre = `lame --genre-list 2>&1 | grep -i \' $genre \'`); |
| 7182 |
} |
| 7183 |
else { |
| 7184 |
# First we want to be sure that the genre from the DB, which might |
| 7185 |
# be "wrong", e.g. wave (instead of Darkwave or New Wave) or synth |
| 7186 |
# instead of Synthpop, will be correct. Put the DB genre to ogenre |
| 7187 |
# and get a new right-spelled genre... Note, we might get several |
| 7188 |
# possibilities, e.g. genre is Pop, then we get a bunch of |
| 7189 |
# "pop-like" genres! |
| 7190 |
# There will be a line break, if multiple possibilities found. |
| 7191 |
my $ogenre = $genre; |
| 7192 |
chomp($genre = `lame --genre-list 2>&1 | grep -i \'$genre\'`); |
| 7193 |
# Second we want THE original genre, if it precisely exists. |
| 7194 |
chomp(my $testgenre = `lame --genre-list 2>&1 | grep -i \'\^... $ogenre\$\'`); |
| 7195 |
$genre = $testgenre if($testgenre); |
| 7196 |
# If we still have several genres: |
| 7197 |
# Either let the operator choose, or if no interaction, take |
| 7198 |
# default genre: "12 Other". |
| 7199 |
if($genre =~ /\n/ && $interaction == 1) { |
| 7200 |
print "More than one genre possibility found:\n"; |
| 7201 |
my @list = split(/\n/, $genre); |
| 7202 |
my ($i, $j) = (0,1); |
| 7203 |
while($i > $#list+1 || $i == 0) { |
| 7204 |
# TODO: Here we should add the possibility to choose none! |
| 7205 |
# Or perhaps to go back and choose something completely |
| 7206 |
# different. |
| 7207 |
foreach (@list) { |
| 7208 |
printf(" %2d: $_ \n", $j); |
| 7209 |
$j++; |
| 7210 |
} |
| 7211 |
$j--; |
| 7212 |
print "\nChoose [1-$j]: "; |
| 7213 |
$i = <STDIN>; |
| 7214 |
chomp $i; |
| 7215 |
$j = 1; |
| 7216 |
} |
| 7217 |
chomp($genre = $list[$i-1]); |
| 7218 |
} |
| 7219 |
# No interaction! Take the first or default genre! |
| 7220 |
elsif($genre =~ /\n/ && $interaction != 1 && $lameflag == 1) { |
| 7221 |
$genre = "12 Other" if($genre eq ""); |
| 7222 |
$genre =~ s/\n.*//; |
| 7223 |
} |
| 7224 |
# The genre is not Lame compliant, and we do not care about, |
| 7225 |
# because Lame is not used. Set the genre-number-flag to 0 to |
| 7226 |
# prevent genre-number-extracting at the end of the subroutine. |
| 7227 |
elsif($lameflag != 1) { |
| 7228 |
$genre = $ogenre; |
| 7229 |
$genrenoflag = 0; |
| 7230 |
} |
| 7231 |
chomp $genre; |
| 7232 |
} |
| 7233 |
|
| 7234 |
# Extract genre number. |
| 7235 |
if($genre ne "" && $genrenoflag == 1) { |
| 7236 |
$genre =~ s/^\s*//; |
| 7237 |
my @genre = split(/ /, $genre); |
| 7238 |
$genreno = shift(@genre); |
| 7239 |
$genre = "@genre"; |
| 7240 |
} |
| 7241 |
return ($genre,$genreno); |
| 7242 |
} |
| 7243 |
######################################################################## |
| 7244 |
# |
| 7245 |
# Check mirrors. Need to be tested from time to time, which ones are up. |
| 7246 |
# |
| 7247 |
# http://at.freedb.org:80/~cddb/cddb.cgi working |
| 7248 |
# http://au.freedb.org:80/~cddb/cddb.cgi not working |
| 7249 |
# http://ca.freedb.org:80/~cddb/cddb.cgi working |
| 7250 |
# http://ca2.freedb.org:80/~cddb/cddb.cgi working |
| 7251 |
# http://de.freedb.org:80/~cddb/cddb.cgi working |
| 7252 |
# http://es.freedb.org:80/~cddb/cddb.cgi working |
| 7253 |
# http://fi.freedb.org:80/~cddb/cddb.cgi working |
| 7254 |
# http://freedb.freedb.org:80/~cddb/cddb.cgi not working |
| 7255 |
# http://ru.freedb.org:80/~cddb/cddb.cgi working |
| 7256 |
# http://uk.freedb.org:80/~cddb/cddb.cgi working |
| 7257 |
# http://us.freedb.org:80/~cddb/cddb.cgi not working |
| 7258 |
# |
| 7259 |
# |
| 7260 |
sub check_host { |
| 7261 |
# while($mirror !~ m/^freedb$|^at$|^au$|^ca$|^es$|^fi$| |
| 7262 |
# |^fr$|^jp$|^jp2$|^ru$|^uk$|^uk2$|^us$/) { |
| 7263 |
while($mirror !~ m/^freedb$|^at$|^au$|^bg$|^ca$|^es$|^fi$| |
| 7264 |
|^lu$|^no$|^uk$|^us$/) { |
| 7265 |
print "host mirror ($mirror) not valid!\nenter freedb, ", |
| 7266 |
"at, au, ca, es, fi, fr, jp, jp2, ru, uk, uk2 or us: "; |
| 7267 |
$mirror = <STDIN>; |
| 7268 |
chomp $mirror; |
| 7269 |
} |
| 7270 |
} |
| 7271 |
######################################################################## |
| 7272 |
# |
| 7273 |
# Answer to question. |
| 7274 |
# |
| 7275 |
sub get_answ { |
| 7276 |
my $ans = "x"; |
| 7277 |
while($ans !~ /^y|^n/) { |
| 7278 |
print "Do you want to enter a different ".$_[0]." than ".$_[1]; |
| 7279 |
print "? [y/n], (n): "; |
| 7280 |
$ans = <STDIN>; |
| 7281 |
chomp $ans; |
| 7282 |
if($ans eq "") { |
| 7283 |
$ans = "n"; |
| 7284 |
} |
| 7285 |
} |
| 7286 |
if($ans =~ /^y/) { |
| 7287 |
return ""; |
| 7288 |
} |
| 7289 |
return $_[1]; |
| 7290 |
} |
| 7291 |
######################################################################## |
| 7292 |
# |
| 7293 |
# Check quality passed from command line for lame, oggenc, flac, faac. |
| 7294 |
# |
| 7295 |
sub check_quality { |
| 7296 |
# |
| 7297 |
# Prevent warnings. |
| 7298 |
@pquality = defined unless(@pquality); |
| 7299 |
# |
| 7300 |
# Remember, if the quality is defined via -q/--quality switch |
| 7301 |
# on the command line, the array consists of a comma separated |
| 7302 |
# string in the first entry only! |
| 7303 |
# |
| 7304 |
if($pquality[0] =~ /\d/ or "@pquality" =~ "off") { # new in 4.0 |
| 7305 |
# Why this joining and splitting? Because the whole string is in |
| 7306 |
# $quality[0]! But why joining? Because we can come from CLI! In |
| 7307 |
# this case we need to make it identical to the way it comes from |
| 7308 |
# config file, i.e. as comma separated string in the first entry. |
| 7309 |
@quality = split(/,/, join(',', @pquality)); |
| 7310 |
} |
| 7311 |
else { |
| 7312 |
my @clean_q = (); |
| 7313 |
foreach (@quality) { |
| 7314 |
next unless(defined $_); |
| 7315 |
push(@clean_q, $_); |
| 7316 |
} |
| 7317 |
if("@clean_q" eq "5 3 5 100 0 5") { |
| 7318 |
return; |
| 7319 |
} |
| 7320 |
} |
| 7321 |
# If no coder-array has been passed, we do not know to which encoder |
| 7322 |
# each quality-entry belongs to. NOTE, we've not yet read the config. |
| 7323 |
# So we need to read the config file to check if there is an unusual |
| 7324 |
# order of encoders. In this way, this subroutine will ask the |
| 7325 |
# correct questions and not mess up the encoders if qualities are |
| 7326 |
# wrong, supposing the operator is aware about an unusual order! |
| 7327 |
if(!@pcoder && -r "$ripdir") { |
| 7328 |
open(CONF, "$ripdir"); |
| 7329 |
my @conflines = <CONF>; |
| 7330 |
close(CONF); |
| 7331 |
@pcoder = grep(s/^coder=//, @conflines) unless(@pcoder); |
| 7332 |
chomp @pcoder; |
| 7333 |
if($pcoder[0] =~ /^\d/) { |
| 7334 |
@coder = split(/,/, join(',',@pcoder)); |
| 7335 |
} |
| 7336 |
} |
| 7337 |
# Actually check only those qualities needed, i.e. for chosen |
| 7338 |
# encoders. |
| 7339 |
# NOTE again: the $qualame etc. variables hold the string needed for |
| 7340 |
# the config, it might be a comma separated string. When passing |
| 7341 |
# commands, we should not use them, but things like "$quality[$c]" |
| 7342 |
# instead! |
| 7343 |
my $corrflag = 0; |
| 7344 |
$qualame = ""; |
| 7345 |
$qualoggenc = ""; |
| 7346 |
$quaflac = ""; |
| 7347 |
$quafaac = ""; |
| 7348 |
$quamp4als = ""; |
| 7349 |
$quamuse = ""; |
| 7350 |
for(my $c=0; $c<=$#coder; $c++) { |
| 7351 |
if($coder[$c] == 0 && !defined($quality[$c])) { |
| 7352 |
$quality[$c] = 5; # prevent warnings. |
| 7353 |
} |
| 7354 |
elsif($coder[$c] == 0 && $quality[$c] ne "off") { |
| 7355 |
$quality[$c] = 5 unless($quality[$c] =~ /\d/); |
| 7356 |
while($quality[$c] > 9) { |
| 7357 |
print "\nThe quality $quality[$c] is not valid for Lame!", |
| 7358 |
"\nPlease enter a different quality (0 = best),", |
| 7359 |
" [0-9]: "; |
| 7360 |
$quality[$c] = <STDIN>; |
| 7361 |
chomp $quality[$c]; |
| 7362 |
} |
| 7363 |
$qualame .= ";" . $quality[$c]; |
| 7364 |
} |
| 7365 |
elsif($coder[$c] == 0 && $quality[$c] eq "off") { |
| 7366 |
$qualame .= ";" . $quality[$c]; |
| 7367 |
} |
| 7368 |
# Done with lame, do the other encoders. |
| 7369 |
if($coder[$c] == 1 && !defined($quality[$c])) { |
| 7370 |
$quality[$c] = 3; # prevent warnings. |
| 7371 |
} |
| 7372 |
elsif($coder[$c] == 1 && $quality[$c] ne "off") { |
| 7373 |
$quality[$c] = 3 unless($quality[$c] =~ /\d/); |
| 7374 |
while($quality[$c] > 10 || $quality[$c] == 0) { |
| 7375 |
print "\nThe quality $quality[$c] is not valid for Oggenc!", |
| 7376 |
"\nPlease enter a different quality (10 = best),", |
| 7377 |
" [1-10]: "; |
| 7378 |
$quality[$c] = <STDIN>; |
| 7379 |
chomp $quality[$c]; |
| 7380 |
} |
| 7381 |
$qualoggenc .= "," . $quality[$c]; |
| 7382 |
} |
| 7383 |
elsif($coder[$c] == 1 && $quality[$c] eq "off") { |
| 7384 |
$qualoggenc .= "," . $quality[$c]; |
| 7385 |
} |
| 7386 |
if($coder[$c] == 2 && !defined($quality[$c])) { |
| 7387 |
$quality[$c] = 5; # prevent warnings. |
| 7388 |
} |
| 7389 |
elsif($coder[$c] == 2 && $quality[$c] ne "off") { |
| 7390 |
$quality[$c] = 5 unless($quality[$c] =~ /\d/); |
| 7391 |
while($quality[$c] > 8) { |
| 7392 |
print "\nThe compression level $quality[$c] is not valid ", |
| 7393 |
"for Flac!", |
| 7394 |
"\nPlease enter a different compression level ", |
| 7395 |
"(0 = lowest), [0-8]: "; |
| 7396 |
$quality[$c] = <STDIN>; |
| 7397 |
chomp $quality[$c]; |
| 7398 |
} |
| 7399 |
$quaflac = $quaflac . "," . $quality[$c]; |
| 7400 |
} |
| 7401 |
elsif($coder[$c] == 2 && $quality[$c] eq "off") { |
| 7402 |
$quaflac .= "," . $quality[$c]; |
| 7403 |
} |
| 7404 |
if($coder[$c] == 3 && !defined($quality[$c])) { |
| 7405 |
$quality[$c] = 100; # prevent warnings. |
| 7406 |
} |
| 7407 |
elsif($coder[$c] == 3 && $quality[$c] ne "off") { |
| 7408 |
$quality[$c] = 100 unless($quality[$c] =~ /\d/); |
| 7409 |
while($quality[$c] > 500 || $quality[$c] < 10) { |
| 7410 |
print "\nThe quality $quality[$c] is not valid for Faac!", |
| 7411 |
"\nPlease enter a different quality (500 = max), ", |
| 7412 |
"[10-500]: "; |
| 7413 |
$quality[$c] = <STDIN>; |
| 7414 |
chomp $quality[$c]; |
| 7415 |
} |
| 7416 |
$quafaac .= "," . $quality[$c]; |
| 7417 |
} |
| 7418 |
elsif($coder[$c] == 3 && $quality[$c] eq "off") { |
| 7419 |
$quafaac .= "," . $quality[$c]; |
| 7420 |
} |
| 7421 |
if($coder[$c] == 4 && !defined($quality[$c])) { |
| 7422 |
$quality[$c] = 0; # prevent warnings. |
| 7423 |
} |
| 7424 |
elsif($coder[$c] == 4 && $quality[$c] ne "off") { |
| 7425 |
$quality[$c] = 0 unless($quality[$c] =~ /\d/); |
| 7426 |
# Any info about mp4als "qualities", i. e. compression levels? |
| 7427 |
$quamp4als .= "," . $quality[$c]; |
| 7428 |
} |
| 7429 |
elsif($coder[$c] == 4 && $quality[$c] eq "off") { |
| 7430 |
$quamp4als .= "," . $quality[$c]; |
| 7431 |
} |
| 7432 |
if($coder[$c] == 5 && !defined($quality[$c])) { |
| 7433 |
$quality[$c] = 5; # prevent warnings. |
| 7434 |
} |
| 7435 |
elsif($coder[$c] == 5 && $quality[$c] ne "off") { |
| 7436 |
$quality[$c] = 5 unless($quality[$c] =~ /\d/); |
| 7437 |
while($quality[$c] > 10 || $quality[$c] < 0) { |
| 7438 |
print "\nThe quality $quality[$c] is not valid for $musenc!", |
| 7439 |
"\nPlease enter a different quality (10 = max), ", |
| 7440 |
"[0-10]: "; |
| 7441 |
$quality[$c] = <STDIN>; |
| 7442 |
chomp $quality[$c]; |
| 7443 |
} |
| 7444 |
$quamuse .= "," . $quality[$c]; |
| 7445 |
} |
| 7446 |
elsif($coder[$c] == 5 && $quality[$c] eq "off") { |
| 7447 |
$quamuse .= "," . $quality[$c]; |
| 7448 |
} |
| 7449 |
if($coder[$c] == 6 && !defined($quality[$c])) { |
| 7450 |
$quality[$c] = " "; # prevent warnings. |
| 7451 |
} |
| 7452 |
if($coder[$c] == 7 && !defined($quality[$c])) { |
| 7453 |
$quality[$c] = " "; # prevent warnings. |
| 7454 |
} |
| 7455 |
} |
| 7456 |
$qualame =~ s/^,//; |
| 7457 |
$qualoggenc =~ s/^,//; |
| 7458 |
$quaflac =~ s/^,//; |
| 7459 |
$quafaac =~ s/^,//; |
| 7460 |
$quamuse =~ s/^,//; |
| 7461 |
# Small problem if only option --savenew is used, with no other |
| 7462 |
# option at all. Then, qualame has default value (because Lame is |
| 7463 |
# default encoder), but all other qualities are empty! |
| 7464 |
$qualoggenc = 3 unless($qualoggenc); |
| 7465 |
$quaflac = 5 unless($quaflac); |
| 7466 |
$quafaac = 100 unless($quafaac); |
| 7467 |
$quamp4als = 0 unless($quamp4als); |
| 7468 |
$quamuse = 5 unless($quamuse); |
| 7469 |
# NOTE: corrections have been done on quality array, not pquality. |
| 7470 |
# If pquality was passed, we need to apply corrections and save it |
| 7471 |
# the same way as if it had been passed on command line. |
| 7472 |
if($pquality[0]) { |
| 7473 |
my $pquality = join(',', @quality); |
| 7474 |
$pquality =~ s/(,\s)*$//; |
| 7475 |
@pquality = (); |
| 7476 |
$pquality[0] = $pquality; |
| 7477 |
} |
| 7478 |
} |
| 7479 |
######################################################################## |
| 7480 |
# |
| 7481 |
# Check bitrate for Lame only if vbr is wanted. |
| 7482 |
# |
| 7483 |
sub check_vbrmode { |
| 7484 |
while($vbrmode ne "new" && $vbrmode ne "old") { |
| 7485 |
print "\nFor vbr using Lame choose *new* or *old*! (new): "; |
| 7486 |
$vbrmode = <STDIN>; |
| 7487 |
chomp $vbrmode; |
| 7488 |
$vbrmode = "new" if($vbrmode eq ""); |
| 7489 |
} |
| 7490 |
} |
| 7491 |
######################################################################## |
| 7492 |
# |
| 7493 |
# Check preset for Lame only. |
| 7494 |
# |
| 7495 |
sub lame_preset { |
| 7496 |
if($vbrmode eq "new") { |
| 7497 |
$preset = "fast " . $preset; |
| 7498 |
} |
| 7499 |
} |
| 7500 |
######################################################################## |
| 7501 |
# |
| 7502 |
# Check if there is an other than $cddev which has a CD if no --device |
| 7503 |
# option was given. |
| 7504 |
# |
| 7505 |
sub check_cddev { |
| 7506 |
# Try to get a list of possible CD devices. |
| 7507 |
open(DEV, "/etc/fstab"); |
| 7508 |
my @dev = <DEV>; |
| 7509 |
close(DEV); |
| 7510 |
@dev = grep(/^\s*\/dev/, @dev); |
| 7511 |
@dev = grep(!/^\s*\/dev\/[f|h]d/, @dev); |
| 7512 |
@dev = grep(!/sd/, @dev); |
| 7513 |
my @devlist = (); |
| 7514 |
foreach (@dev) { |
| 7515 |
my @line = split(/\s/, $_); |
| 7516 |
chomp $line[0]; |
| 7517 |
push(@devlist, $line[0]) unless($line[0] =~ /by-id/); |
| 7518 |
} |
| 7519 |
# First check some default addresses. |
| 7520 |
if(open(CD, "$cddev")) { |
| 7521 |
$cddev = $cddev; |
| 7522 |
close(CD); |
| 7523 |
} |
| 7524 |
elsif(open(CD, "/dev/cdrecorder")) { |
| 7525 |
$cddev = "/dev/cdrecorder"; |
| 7526 |
close(CD); |
| 7527 |
} |
| 7528 |
elsif(open(CD, "/dev/dvd")) { |
| 7529 |
$cddev = "/dev/dvd"; |
| 7530 |
close(CD); |
| 7531 |
} |
| 7532 |
elsif(open(CD, "/dev/sr0")) { |
| 7533 |
$cddev = "/dev/sr0"; |
| 7534 |
close(CD); |
| 7535 |
} |
| 7536 |
elsif(open(CD, "/dev/sr1")) { |
| 7537 |
$cddev = "/dev/sr1"; |
| 7538 |
close(CD); |
| 7539 |
} |
| 7540 |
else { |
| 7541 |
foreach (@devlist) { |
| 7542 |
if(open(CD, "$_")) { |
| 7543 |
$cddev = $_; |
| 7544 |
chomp $cddev; |
| 7545 |
close(CD); |
| 7546 |
} |
| 7547 |
else { |
| 7548 |
# Condition added in 4.0, why should the $cddev be cleared |
| 7549 |
# unconditionally? |
| 7550 |
$cddev = "" unless($cddev =~ /\/dev\/.*/); |
| 7551 |
} |
| 7552 |
} |
| 7553 |
} |
| 7554 |
# On a notebook, the tray can't be closed automatically! |
| 7555 |
# Print error message and retry detection. |
| 7556 |
if($cddev eq "" && $rip > 0) { |
| 7557 |
print "Is there a CD and the tray of the device closed?\n"; |
| 7558 |
print "Pausing 12 seconds.\n"; |
| 7559 |
sleep(12); |
| 7560 |
foreach (@devlist) { |
| 7561 |
if(open(CD, "$_")) { |
| 7562 |
$cddev = $_; |
| 7563 |
chomp $cddev; |
| 7564 |
close(CD); |
| 7565 |
} |
| 7566 |
} |
| 7567 |
} |
| 7568 |
if($cddev eq "" && $rip > 0) { |
| 7569 |
print "Could not detect CD device! The default /dev/cdrom "; |
| 7570 |
print "device will be used.\n"; |
| 7571 |
$cddev = "/dev/cdrom"; |
| 7572 |
} |
| 7573 |
return; |
| 7574 |
} |
| 7575 |
######################################################################## |
| 7576 |
# |
| 7577 |
# Check bitrate if bitrate is not zero. |
| 7578 |
# |
| 7579 |
sub check_bitrate { |
| 7580 |
while($bitrate !~ m/^32$|^40$|^48$|^56$|^64$|^80$|^96$|^112$|^128$| |
| 7581 |
|^160$|^192$|^224$|^256$|^320$|^off$/) { |
| 7582 |
print "\nBitrate should be one of the following numbers or "; |
| 7583 |
print "\"off\"! Please Enter"; |
| 7584 |
print "\n32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, "; |
| 7585 |
print "256 or 320: (128) \n"; |
| 7586 |
$bitrate = <STDIN>; |
| 7587 |
chomp $bitrate; |
| 7588 |
if($bitrate eq "") { |
| 7589 |
$bitrate = 128; |
| 7590 |
} |
| 7591 |
} |
| 7592 |
} |
| 7593 |
######################################################################## |
| 7594 |
# |
| 7595 |
# Check protocol level for CDDB query. |
| 7596 |
# |
| 7597 |
sub check_proto { |
| 7598 |
while($proto > 6) { |
| 7599 |
print "Protocol level for CDDB query should be less-equal 6!\n"; |
| 7600 |
print "Enter an other value for protocol level (6): "; |
| 7601 |
$proto = <STDIN>; |
| 7602 |
chomp $proto; |
| 7603 |
$proto = 6 if($proto eq ""); |
| 7604 |
} |
| 7605 |
} |
| 7606 |
######################################################################## |
| 7607 |
# |
| 7608 |
# Check and clean the coder array. |
| 7609 |
# |
| 7610 |
sub check_coder { |
| 7611 |
|
| 7612 |
# Reset $lameflag set by past invocation of check_coder() except if |
| 7613 |
# lame is not installed ($lameflag == -1). |
| 7614 |
$lameflag = 0 if($lameflag > 0); |
| 7615 |
|
| 7616 |
# Create encoder array if passed or read from config file. |
| 7617 |
# Remember, if we come from reading the config file, the array |
| 7618 |
# consists of a comma separated string in the first entry only! |
| 7619 |
if(@pcoder) { |
| 7620 |
@coder = split(/,/, join(',', @pcoder)); |
| 7621 |
} |
| 7622 |
else { |
| 7623 |
# This can happen because this subroutine is called before config |
| 7624 |
# file is read! So @pcoder can be empty and @coder will be filled |
| 7625 |
# with default value for Lame. Do we need this? |
| 7626 |
@coder = split(/,/, join(',', @coder)); |
| 7627 |
} |
| 7628 |
|
| 7629 |
my @ffmpegsuf = (); |
| 7630 |
if($ffmpegsuffix) { |
| 7631 |
@ffmpegsuf = split(/,/, $ffmpegsuffix); |
| 7632 |
} |
| 7633 |
|
| 7634 |
# Check if there is an entry > 7. |
| 7635 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 7636 |
if($coder[$c] > 7) { |
| 7637 |
die "Encoder number $coder[$c] does not yet exist, ", |
| 7638 |
"please enter\n0 for Lame, 1 for Oggenc, 2 for Flac ", |
| 7639 |
"3 for Faac,\n 4 for mp4als, 5 for Musepack, ", |
| 7640 |
"6 for Wavpack or 7 for ffmpeg!\n\n"; |
| 7641 |
# TODO: splice that entry out, don't die! |
| 7642 |
} |
| 7643 |
$lameflag = 1 if($coder[$c] == 0); |
| 7644 |
$oggflag = 1 if($coder[$c] == 1); |
| 7645 |
$wvpflag = 1 if($coder[$c] == 6); |
| 7646 |
$suffix[$c] = "mp3" if($coder[$c] == 0); |
| 7647 |
$suffix[$c] = "ogg" if($coder[$c] == 1); |
| 7648 |
$suffix[$c] = "flac" if($coder[$c] == 2); |
| 7649 |
$suffix[$c] = "m4a" if($coder[$c] == 3); |
| 7650 |
$suffix[$c] = "m4b" if($coder[$c] == 3 && $book == 1); |
| 7651 |
$suffix[$c] = "als" if($coder[$c] == 4); |
| 7652 |
$suffix[$c] = "mpc" if($coder[$c] == 5); |
| 7653 |
$suffix[$c] = "wv" if($coder[$c] == 6); |
| 7654 |
if($coder[$c] == 7) { |
| 7655 |
$suffix[$c] = shift @ffmpegsuf; |
| 7656 |
} |
| 7657 |
} |
| 7658 |
# Use comma separated string to write the encoder array to the |
| 7659 |
# config file! |
| 7660 |
$wcoder = join(',', @coder); |
| 7661 |
} |
| 7662 |
######################################################################## |
| 7663 |
# |
| 7664 |
# Over or re-write the config file (depends on option savenew or save). |
| 7665 |
# |
| 7666 |
# New options step 10: Add description of new option to config file. |
| 7667 |
# |
| 7668 |
sub save_config { |
| 7669 |
$confdir = "$homedir/.ripit" if($confdir eq ""); |
| 7670 |
log_system("mkdir -m 0755 -p $confdir") |
| 7671 |
or die "Can not create directory $confdir: $!\n"; |
| 7672 |
# Remember: $ripdir is the full path including config file name. |
| 7673 |
rename("$confdir/$confname","$confdir/$confname.old") |
| 7674 |
if(-r "$confdir/$confname"); |
| 7675 |
open(CONF, "> $confdir/$confname") |
| 7676 |
or die "Can not write to $confdir/$confname: $!\n"; |
| 7677 |
print CONF " |
| 7678 |
##### |
| 7679 |
# |
| 7680 |
# RipIT $version configuration file. |
| 7681 |
# |
| 7682 |
# For further information on ripit configuration / parameters |
| 7683 |
# and examples see the manpage or the README provided with ripit |
| 7684 |
# or type ripit --help . |
| 7685 |
|
| 7686 |
|
| 7687 |
##### |
| 7688 |
# |
| 7689 |
# Ripping device, permissions & path. |
| 7690 |
# |
| 7691 |
|
| 7692 |
# cddevice: Define ripping device if other than /dev/cdrom. |
| 7693 |
# Default: /dev/cdrom |
| 7694 |
|
| 7695 |
cddevice=$cddev |
| 7696 |
|
| 7697 |
# scsidevice: Device name for special devices if the non ripping |
| 7698 |
# commands should be executed on a different device node. This might |
| 7699 |
# be useful for some old SCSI devices. If not set the cddevice will |
| 7700 |
# be used. |
| 7701 |
# Example: /dev/sr18 |
| 7702 |
# Default: not set |
| 7703 |
|
| 7704 |
scsidevice=$scsi_cddev |
| 7705 |
|
| 7706 |
# output: Path for audio files. If not set, \$HOME will be used. |
| 7707 |
# Default: not set |
| 7708 |
|
| 7709 |
output=$outputdir |
| 7710 |
|
| 7711 |
# directory permissions: Permissions for directories. |
| 7712 |
# Default: 0755 |
| 7713 |
|
| 7714 |
dpermission=$dpermission |
| 7715 |
|
| 7716 |
# file permissions: Permissions for sound and log files. |
| 7717 |
# If not set, uses the default system settings. |
| 7718 |
# Default: not set |
| 7719 |
|
| 7720 |
fpermission=$fpermission |
| 7721 |
|
| 7722 |
|
| 7723 |
##### |
| 7724 |
# |
| 7725 |
# Ripping options. |
| 7726 |
# |
| 7727 |
|
| 7728 |
# ripper: select CD ripper |
| 7729 |
# 0 - dagrab |
| 7730 |
# 1 - cdparanoia |
| 7731 |
# 2 - cdda2wav |
| 7732 |
# 3 - rip (Morituri) |
| 7733 |
# 4 - cdd (support not ensured) |
| 7734 |
# Default: cdparanoia |
| 7735 |
|
| 7736 |
ripper=$ripper |
| 7737 |
|
| 7738 |
# ripopt: User definable options for the CD ripper. |
| 7739 |
# Example: when using cdda2wav: -v summary |
| 7740 |
# Default: not set |
| 7741 |
|
| 7742 |
ripopt=$ripopt |
| 7743 |
|
| 7744 |
# offset: User definable sample offset for the CD ripper. This will |
| 7745 |
# trigger option -O when using cdparanoia and option -o when using rip. |
| 7746 |
# Icedax (cdda2wav) seems not to provide a sample offset. |
| 7747 |
# Possible values: integers |
| 7748 |
# Example: 48 |
| 7749 |
# Default: 0 |
| 7750 |
|
| 7751 |
offset=$offset |
| 7752 |
|
| 7753 |
# span: Rip only part of a single track or the merged track-interval. |
| 7754 |
# Possible values: any in the format hh:mm:ss.ff-hh:mm:ss.ff |
| 7755 |
# Example: rip first 30s of each track: 0-30 |
| 7756 |
# Default: not set |
| 7757 |
|
| 7758 |
span=$span |
| 7759 |
|
| 7760 |
# paranoia: Turn \"paranoia\" on or off for dagrab and cdparanoia. |
| 7761 |
# Possible values: 0 - no paranoia, 1 - use paranoia |
| 7762 |
# 2 - switch paranoia off if ripping fails on one |
| 7763 |
# track and retry this track without paranoia |
| 7764 |
# Default: 1 - use paranoia |
| 7765 |
|
| 7766 |
paranoia=$parano |
| 7767 |
|
| 7768 |
# ghost: Analyze the wavs for possible gaps, split the wav into |
| 7769 |
# chunks of sound and delete blank tracks. |
| 7770 |
# Possible values: 0 - off, 1 - on |
| 7771 |
# Default: off |
| 7772 |
|
| 7773 |
ghost=$ghost |
| 7774 |
|
| 7775 |
# prepend: Enlarge the chunk of sound by a number of |
| 7776 |
# seconds at the beginning (if possible). |
| 7777 |
# Possible values: any positive number and zero; precision in |
| 7778 |
# tenths of seconds. Be aware of low numbers, especially when |
| 7779 |
# using option cdcue. |
| 7780 |
# Default: 2.0 |
| 7781 |
|
| 7782 |
prepend=$prepend |
| 7783 |
|
| 7784 |
# extend: Enlarge the chunk of sound by a number of |
| 7785 |
# seconds at the end (if possible). |
| 7786 |
# Possible values: any positive number and zero; precision in |
| 7787 |
# tenths of seconds. Be aware of low numbers. |
| 7788 |
# Default: 2.0 |
| 7789 |
|
| 7790 |
extend=$extend |
| 7791 |
|
| 7792 |
# resume: Resume a previously started session. |
| 7793 |
# Possible values: 0 - off, 1 - on |
| 7794 |
# Default: off |
| 7795 |
|
| 7796 |
resume=$resume |
| 7797 |
|
| 7798 |
# overwrite: Default behaviour of Ripit is not to overwrite existing |
| 7799 |
# directories, a suffix will be added if directory name exists. |
| 7800 |
# Use option overwrite to prevent this and either overwrite a previous |
| 7801 |
# rip or force Ripit to quit or even eject the disc. If ejection is |
| 7802 |
# chosen, the disc will be ejected even if option eject has not been |
| 7803 |
# switched on. |
| 7804 |
# Possible values: n - off, y - on, |
| 7805 |
# q - quit, e - quit and force ejection |
| 7806 |
# Default: off |
| 7807 |
|
| 7808 |
overwrite=$overwrite |
| 7809 |
|
| 7810 |
# accuracy: Check ripped tracks using rip (Morituri) for accuracy with |
| 7811 |
# AccurateRip DB in case tracks have been ripped without rip (Morituri). |
| 7812 |
# Note: Option is defunct, rip (Morituri) will re-rip the whole disc. |
| 7813 |
# Possible values: 0 - off, 1 - on |
| 7814 |
# Default: off |
| 7815 |
|
| 7816 |
accuracy=$accuracy |
| 7817 |
|
| 7818 |
# verify: Rip each track \$verify times (or less) until at least 2 rips |
| 7819 |
# give the same md5sum. |
| 7820 |
# Possible: any integer |
| 7821 |
# Example: 3 |
| 7822 |
# Default: 1 |
| 7823 |
|
| 7824 |
verify=$verify |
| 7825 |
|
| 7826 |
|
| 7827 |
##### |
| 7828 |
# |
| 7829 |
# Encoding options |
| 7830 |
# |
| 7831 |
|
| 7832 |
# encode: Encode the wavs. |
| 7833 |
# Possible values: 0 - off, 1 - on |
| 7834 |
# Default: on |
| 7835 |
|
| 7836 |
encode=$encode |
| 7837 |
|
| 7838 |
# coder: Select encoders for audio files: |
| 7839 |
# 0 - Lame (mp3) |
| 7840 |
# 1 - Oggenc (ogg) |
| 7841 |
# 2 - Flac (flac) |
| 7842 |
# 3 - Faac (m4a) |
| 7843 |
# 4 - mp4als (als or mp4) |
| 7844 |
# 5 - Musepack (mpc) |
| 7845 |
# 6 - Wavpack (wv) |
| 7846 |
# 7 - ffmpeg |
| 7847 |
# Multiple encoders can be selected by giving a comma separated list |
| 7848 |
# Example: coder=0,0,1,2 encodes CD twice to mp3, ogg and flac files |
| 7849 |
# Default: Lame |
| 7850 |
|
| 7851 |
coder=$wcoder |
| 7852 |
|
| 7853 |
### |
| 7854 |
# |
| 7855 |
# lame (mp3) encoder options |
| 7856 |
# |
| 7857 |
|
| 7858 |
# qualame: Sets audio quality for lame encoder in cbr (lame-option -q) |
| 7859 |
# and vbr (lame-option -V) mode, comma separated list if encoder is |
| 7860 |
# used several times. |
| 7861 |
# Possible values: 0...9, off |
| 7862 |
# 0: highest quality |
| 7863 |
# 9: lowest quality |
| 7864 |
# Can be set to \"off\" if all options are passed to --lameopt. |
| 7865 |
# Example: qualame=off,off |
| 7866 |
# Note: default value is the same for cbr and vbr, |
| 7867 |
# although vbr-default should be 4. |
| 7868 |
# Default: 5 |
| 7869 |
|
| 7870 |
qualame=$qualame |
| 7871 |
|
| 7872 |
# lameopt: Additional options for lame encoder, |
| 7873 |
# use a comma separated list if encoder is used several times. |
| 7874 |
# Example: lameopt=-b 128,--preset extreme |
| 7875 |
# Default: not set |
| 7876 |
|
| 7877 |
lameopt=$lameopt |
| 7878 |
|
| 7879 |
# vbrmode: Enable variable bitrate for lame encoder. |
| 7880 |
# Possible values: \"old\" or \"new\" |
| 7881 |
# Default: not set |
| 7882 |
|
| 7883 |
vbrmode=$vbrmode |
| 7884 |
|
| 7885 |
# bitrate: Sets bitrate for lame encoder. |
| 7886 |
# Possible values: 32...320, off |
| 7887 |
# Should be set to \"off\" if vbr is used |
| 7888 |
# Default: 128 |
| 7889 |
|
| 7890 |
bitrate=$bitrate |
| 7891 |
|
| 7892 |
# maxrate: Sets maximum bitrate for lame (when using vbr) and oggenc. |
| 7893 |
# Possible values: 0 - off, 32...320 |
| 7894 |
# Default: 0 |
| 7895 |
|
| 7896 |
maxrate=$maxrate |
| 7897 |
|
| 7898 |
# preset: Use lame presets. To set the \"fast\" switch, use --vbrmode new. |
| 7899 |
# Possible values: medium, standard, extreme, insane |
| 7900 |
# |
| 7901 |
# medium: 160kbps |
| 7902 |
# standard: 192kbps |
| 7903 |
# extreme: 256kbps |
| 7904 |
# insane: 320kbps |
| 7905 |
# |
| 7906 |
# Default: not set |
| 7907 |
|
| 7908 |
preset=$wpreset |
| 7909 |
|
| 7910 |
### |
| 7911 |
# |
| 7912 |
# oggenc (ogg) encoder options |
| 7913 |
# |
| 7914 |
|
| 7915 |
# qualoggenc: Sets audio quality for oggenc. |
| 7916 |
# Possible values: 1..10, off |
| 7917 |
# 1: lowest quality |
| 7918 |
# 10: highest quality |
| 7919 |
# Can be set to \"off\" |
| 7920 |
# Default: 3 |
| 7921 |
|
| 7922 |
qualoggenc=$qualoggenc |
| 7923 |
|
| 7924 |
# oggencopt: Additional options for oggenc, |
| 7925 |
# use a comma separated list if encoder is used several times. |
| 7926 |
# Default: not set |
| 7927 |
|
| 7928 |
oggencopt=$oggencopt |
| 7929 |
|
| 7930 |
### |
| 7931 |
# |
| 7932 |
# flac (lossless) encoder options |
| 7933 |
# |
| 7934 |
|
| 7935 |
# quaflac: Sets audio compression for flac encoder |
| 7936 |
# Possible values: 0...8, off |
| 7937 |
# 0: lowest compression |
| 7938 |
# 8: highest compression |
| 7939 |
# Can be set to \"off\" |
| 7940 |
# Default: 5 |
| 7941 |
|
| 7942 |
quaflac=$quaflac |
| 7943 |
|
| 7944 |
# flacopt: Additional options for flac encoder, |
| 7945 |
# use a comma separated list if encoder is used several times. |
| 7946 |
# Example of single encoder: |
| 7947 |
# flacopt=--padding=8212 --replay-gain |
| 7948 |
# Example of multiple encoder: |
| 7949 |
# flacopt=--padding=8212 --replay-gain,--padding=8212 |
| 7950 |
# Note: If using the --replay-gain option the padding option |
| 7951 |
# is recommended, otherwise all padding might be lost. |
| 7952 |
# Default: not set |
| 7953 |
|
| 7954 |
flacopt=$flacopt |
| 7955 |
|
| 7956 |
# flacdecopt: Additional options for flac when used to decode flacs. |
| 7957 |
# Might be needed to force (over) writing existing wav files |
| 7958 |
# Example: flacdecopt=\"--totally-silent -f\" |
| 7959 |
# Default: -s (silent) |
| 7960 |
|
| 7961 |
flacdecopt=$flacdecopt |
| 7962 |
|
| 7963 |
### |
| 7964 |
# |
| 7965 |
# faac (m4a) encoder options |
| 7966 |
# |
| 7967 |
|
| 7968 |
# quafaac: Sets audio quality for faac encoder |
| 7969 |
# Possible values: 10...500, off |
| 7970 |
# 10: lowest quality |
| 7971 |
# 500: highest quality |
| 7972 |
# Can be set to \"off\" |
| 7973 |
# Default: 100 |
| 7974 |
|
| 7975 |
quafaac=$quafaac |
| 7976 |
|
| 7977 |
# faacopt: Additional options for faac encoder, |
| 7978 |
# comma separated list if encoder is used several times. |
| 7979 |
# Default: not set |
| 7980 |
|
| 7981 |
faacopt=$faacopt |
| 7982 |
|
| 7983 |
### |
| 7984 |
# |
| 7985 |
# mp4als (als or mp4) encoder options |
| 7986 |
# |
| 7987 |
|
| 7988 |
# quamp4als: Set audio compression level for mp4als. |
| 7989 |
# Note: Options that influence compression and speed |
| 7990 |
# should be used in the mp4als options below. |
| 7991 |
# Default: 0 |
| 7992 |
|
| 7993 |
quamp4als=$quamp4als |
| 7994 |
|
| 7995 |
# mp4alsopt: Additional options for mp4als encoder, |
| 7996 |
# comma separated list if encoder is used several times. |
| 7997 |
# Example: -MP4 to allow tagging, mandatory. |
| 7998 |
# Example: -a -o30 for faster speed. |
| 7999 |
# Default: not set |
| 8000 |
|
| 8001 |
mp4alsopt=$mp4alsopt |
| 8002 |
|
| 8003 |
### |
| 8004 |
# |
| 8005 |
# Musepack (mpc) encoder options |
| 8006 |
# |
| 8007 |
|
| 8008 |
# musenc: The encoder name on the command line |
| 8009 |
# Possible values: any |
| 8010 |
# Example: musenc=mppenc for older versions |
| 8011 |
# Default: mpcenc |
| 8012 |
|
| 8013 |
musenc=$musenc |
| 8014 |
|
| 8015 |
# quamuse: Sets audio quality for Musepack encoder |
| 8016 |
# Possible values: 0...10, off |
| 8017 |
# 0: lowest quality |
| 8018 |
# 10: highest quality |
| 8019 |
# Can be set to \"off\" |
| 8020 |
# Default: 5 |
| 8021 |
|
| 8022 |
quamuse=$quamuse |
| 8023 |
|
| 8024 |
# museopt: Additional options for Musepack encoder, |
| 8025 |
# use a comma separated list if encoder is used several times. |
| 8026 |
# Default: not set |
| 8027 |
|
| 8028 |
museopt=$museopt |
| 8029 |
|
| 8030 |
### |
| 8031 |
# |
| 8032 |
# Wavpack (wv) encoder options |
| 8033 |
# |
| 8034 |
|
| 8035 |
# wavpacopt: Additional options for Wavpack encoder, |
| 8036 |
# use a comma separated list if encoder is used several times. |
| 8037 |
# Example: -b320chy |
| 8038 |
# Default: -y |
| 8039 |
|
| 8040 |
wavpacopt=$wavpacopt |
| 8041 |
|
| 8042 |
### |
| 8043 |
# |
| 8044 |
#ffmpeg encoder options |
| 8045 |
# |
| 8046 |
|
| 8047 |
# ffmpegopt: Additional options for ffmpeg, |
| 8048 |
# use a comma separated list if encoder is used several times. |
| 8049 |
# Example if ffmpeg is used twice: -acodec alac,-acodec wmav2 |
| 8050 |
# Default: off |
| 8051 |
|
| 8052 |
ffmpegopt=$ffmpegopt |
| 8053 |
|
| 8054 |
# ffmpegsuffix: Suffix to be used for ffmpeg, |
| 8055 |
# use a comma separated list if encoder is used several times. |
| 8056 |
# Example if ffmpeg is used twice: m4a,wma |
| 8057 |
# Default: off |
| 8058 |
|
| 8059 |
ffmpegsuffix=$ffmpegsuffix |
| 8060 |
|
| 8061 |
|
| 8062 |
##### |
| 8063 |
# |
| 8064 |
# Track name and directory template |
| 8065 |
# |
| 8066 |
|
| 8067 |
# dirtemplate: Template for directory structure |
| 8068 |
# The template can be created using any legal |
| 8069 |
# character, including slashes (/) for multi-level |
| 8070 |
# directory-trees, and the following variables: |
| 8071 |
# \$album |
| 8072 |
# \$artist |
| 8073 |
# \$iletter |
| 8074 |
# \$genre |
| 8075 |
# \$quality |
| 8076 |
# \$suffix |
| 8077 |
# \$trackname |
| 8078 |
# \$tracknum |
| 8079 |
# \$year |
| 8080 |
# \$trackno |
| 8081 |
# |
| 8082 |
# The variable \$iletter is the initial letter of |
| 8083 |
# the artist variable, the \$quality is the quality |
| 8084 |
# according to the encoding format defined by \$suffix. |
| 8085 |
# The variable \$quality reflects the encoder options, |
| 8086 |
# not the arguments of option --quality which may be set |
| 8087 |
# to off. The variable \$trackno is the total number of tracks |
| 8088 |
# of the release. |
| 8089 |
# |
| 8090 |
# dirtemplate is an array, for each encoder a different |
| 8091 |
# dirtemplate may be defined (i. e. for each encoder state |
| 8092 |
# a line starting with dirtemplate=...). |
| 8093 |
# |
| 8094 |
# Example: |
| 8095 |
# dirtemplate=\"\$suffix/hard_path/\$iletter/\$artist/\$year - \$album\" |
| 8096 |
# |
| 8097 |
# The double quotes (\") are mandatory! |
| 8098 |
# Default: \"\$artist - \$album\" |
| 8099 |
\n"; |
| 8100 |
print CONF "dirtemplate=$_\n" foreach(@dirtemplate); |
| 8101 |
print CONF " |
| 8102 |
# tracktemplate: Template for track names |
| 8103 |
# \"tracktemplate\" is used similarly to \"dirtemplate\" but allows two |
| 8104 |
# more variables helpful in case VA-style is detected: |
| 8105 |
# \$trackartist |
| 8106 |
# \$tracktitle |
| 8107 |
# Note: \$trackartist will be filled with the value of \$artist in case |
| 8108 |
# no track artist has been found to respect the templates settings. |
| 8109 |
# Example: |
| 8110 |
# tracktemplate=\"\$tracknum: \$tracktitle performed by \$trackartist\" |
| 8111 |
# Default: \"\$tracknum \$trackname\" |
| 8112 |
|
| 8113 |
tracktemplate=$tracktemplate |
| 8114 |
|
| 8115 |
# trackoffset: Add an offset to the track counter (\$tracknum) |
| 8116 |
# Possible values: any integer |
| 8117 |
# Default: 0 |
| 8118 |
|
| 8119 |
trackoffset=$trackoffset |
| 8120 |
|
| 8121 |
# addtrackoffset: When using MusicBrainz automatically add an offset |
| 8122 |
# to the track counter (\$tracknum) in case a multi disc release has |
| 8123 |
# been detected. |
| 8124 |
# Possible values: 0 - off, 1 - on |
| 8125 |
# Default: off |
| 8126 |
|
| 8127 |
addtrackoffset=$addtrackoffset |
| 8128 |
|
| 8129 |
# discno: Set a counter for the disc when using a multi disc release. |
| 8130 |
# Possible values: 0 - off, any integer, when using MB set to 1 and |
| 8131 |
# MB might detect and set the discnumber. |
| 8132 |
# Default: 0 |
| 8133 |
|
| 8134 |
discno=$discno |
| 8135 |
|
| 8136 |
# infolog: Log certain operations to file |
| 8137 |
# (e.g. system calls, creation of dirs/files) |
| 8138 |
# Possible values: filename (full path, no ~ here!) |
| 8139 |
# Default: not set |
| 8140 |
|
| 8141 |
infolog=$infolog |
| 8142 |
|
| 8143 |
# lowercase: Convert filenames and or directory names to lowercase |
| 8144 |
# Possible values: 0 - off, 1 - on (for both file and direcotry names) |
| 8145 |
# 2 - on (only file names), 3 - on (only directory |
| 8146 |
# names) |
| 8147 |
# Default: off |
| 8148 |
|
| 8149 |
lowercase=$lowercase |
| 8150 |
|
| 8151 |
# uppercasefirst: Convert filenames and tags to uppercase first, |
| 8152 |
# not recommended. To be used on the command line only if CDDB entry |
| 8153 |
# is in uppercase. |
| 8154 |
# Possible values: 0 - off, 1 - on |
| 8155 |
# Default: off |
| 8156 |
|
| 8157 |
uppercasefirst=$uppercasefirst |
| 8158 |
|
| 8159 |
# underscore: Replace blanks in filenames with underscores |
| 8160 |
# Possible values: 0 - off, 1 - on |
| 8161 |
# Default: off |
| 8162 |
|
| 8163 |
underscore=$underscore |
| 8164 |
|
| 8165 |
# chars: Exclude special characters in file names and path. |
| 8166 |
# Note: following characters will always be purged: |
| 8167 |
# ; > < \" and \\015 . |
| 8168 |
# Side note: if calling this option on the command line without |
| 8169 |
# argument, following characters will be purged: |\\:*?\$ plus |
| 8170 |
# blanks and periods at beginning and end of file names and directories. |
| 8171 |
# This is identical to the word NTFS passed as argument to the command |
| 8172 |
# line or stated here in the config file. The word HFS will purge colons |
| 8173 |
# only plus blanks and periods at beginning of file names and |
| 8174 |
# directories. |
| 8175 |
# |
| 8176 |
# No need to escape the special characters here in the config file. |
| 8177 |
# Possible values: HFS, NTFS, none, any (?) |
| 8178 |
# Default: not set |
| 8179 |
|
| 8180 |
chars=$chars |
| 8181 |
|
| 8182 |
|
| 8183 |
##### |
| 8184 |
# |
| 8185 |
# Audio file tagging |
| 8186 |
# |
| 8187 |
|
| 8188 |
# year-tag: State a year (mp3, m4a) or a date (ogg, flac) tag. |
| 8189 |
# Possible values: integer |
| 8190 |
# Default: not set |
| 8191 |
|
| 8192 |
year=$year |
| 8193 |
|
| 8194 |
# comment-tag: State a comment (mp3, m4a, mpc) or a |
| 8195 |
# description (ogg, flac) tag. To write the cddbid used for freedb |
| 8196 |
# or the MusicBrainz discid into the comment, use the word \"cddbid\" |
| 8197 |
# or \"discid\". |
| 8198 |
# Possible values: discid, cddbid or any string |
| 8199 |
# Default: not set |
| 8200 |
|
| 8201 |
comment=$commentag |
| 8202 |
|
| 8203 |
# flactags: Additional tags for flac not passed by the encoder to ensure |
| 8204 |
# evaluation of special strings similar to mp3tags. Use option |
| 8205 |
# --flacopt \"--tag=FRAME=foo\" for additional hard coded tags instead. |
| 8206 |
# When using MB providing additional meta data can be added using the |
| 8207 |
# string FRAME=frame. |
| 8208 |
# Examples: |
| 8209 |
# Add asin: |
| 8210 |
# flactags=ASIN=asin |
| 8211 |
# Add musicbrainz release id and disid to be recodnized by Picard: |
| 8212 |
# flactags=MUSICBRAINZ_ALBUMID=mbreid |
| 8213 |
# flactags=MUSICBRAINZ_DISCID=discid |
| 8214 |
# flactags=CATALOGNUMBER=catalog |
| 8215 |
# Note: option is an array, for each additional frame/tag to be added |
| 8216 |
# state the option once. |
| 8217 |
# Possible values: none, any (?) |
| 8218 |
# Default: not set |
| 8219 |
\n"; |
| 8220 |
if(@flactags) { |
| 8221 |
foreach(@flactags) { |
| 8222 |
print CONF "flactags=$_\n"; |
| 8223 |
} |
| 8224 |
} |
| 8225 |
else { |
| 8226 |
print CONF "flactags=\n"; |
| 8227 |
} |
| 8228 |
print CONF " |
| 8229 |
# oggtags: Same as flactags. |
| 8230 |
\n"; |
| 8231 |
if(@oggtags) { |
| 8232 |
foreach(@oggtags) { |
| 8233 |
print CONF "oggtags=$_\n"; |
| 8234 |
} |
| 8235 |
} |
| 8236 |
else { |
| 8237 |
print CONF "oggtags=\n"; |
| 8238 |
} |
| 8239 |
print CONF " |
| 8240 |
# mp3tags: Additional tags for mp3 not passed by the encoder. |
| 8241 |
# Example: Add url tag: |
| 8242 |
# mp3tags=WUOF=www.id3v2.org |
| 8243 |
# Add a special track annotation: |
| 8244 |
# mp3tags=TXXX=[ASIN]B00654321 |
| 8245 |
# Force an unofficial compilation frame when using a certain player: |
| 8246 |
# mp3tags=TCMP=1 |
| 8247 |
# Special tags will be evaluated in case the meta data is provided |
| 8248 |
# mp3tags=TXXX=[ASIN]asin |
| 8249 |
# mp3tags=TXXX=[CATALOGNUMBER]catalog |
| 8250 |
# mp3tags=TXXX=[DISCID]discid |
| 8251 |
# mp3tags=TXXX=[MusicBrainz Disc Id]discid |
| 8252 |
# mp3tags=TXXX=[MusicBrainz Album Id]mbreid |
| 8253 |
# Note: option is an array, for each additional frame/tag to be added |
| 8254 |
# state the option once. |
| 8255 |
# Possible values: none, any (?) |
| 8256 |
# Default: not set |
| 8257 |
\n"; |
| 8258 |
if(@mp3tags) { |
| 8259 |
foreach(@mp3tags) { |
| 8260 |
print CONF "mp3tags=$_\n"; |
| 8261 |
} |
| 8262 |
} |
| 8263 |
else { |
| 8264 |
print CONF "mp3tags=\n"; |
| 8265 |
} |
| 8266 |
print CONF " |
| 8267 |
# utftag: Use Lame-tags in UTF-8 or convert them |
| 8268 |
# (but not the filenames) from Unicode to ISO8859-1. |
| 8269 |
# Use when your mp3-audio player doesn't support Unicode tags. |
| 8270 |
# May be useful with Lame. Experimental use in combination with option |
| 8271 |
# --threads or --sshlist. |
| 8272 |
# Possible values: 0 - off, 1 - on |
| 8273 |
# Default: on |
| 8274 |
|
| 8275 |
utftag=$utftag |
| 8276 |
|
| 8277 |
# coverart: Add cover image to meta data of encoded file if possible. |
| 8278 |
# Note: The cover must be available when encoding starts and specified |
| 8279 |
# with option --coverpath (below). One might want to use option |
| 8280 |
# --precmd to execute a script for downloading and preparing a cover. |
| 8281 |
# Argument is a list in same order as encoders with |
| 8282 |
# values 0 (no coverart) or 1 (add coverart) for each encoder. |
| 8283 |
# Example: 1,0,0,1 |
| 8284 |
# Possible values: 0 - off, 1 - on |
| 8285 |
# Default: off |
| 8286 |
|
| 8287 |
coverart=$coverart |
| 8288 |
|
| 8289 |
# coverorg: If set coverart will be retrieved from coverartarchive.org. |
| 8290 |
# Possible values: 0 - off, 1 - on |
| 8291 |
# Default: off |
| 8292 |
|
| 8293 |
coverorg=$coverorg |
| 8294 |
|
| 8295 |
# coverpath: Path where the cover can be found, mandatory with option |
| 8296 |
# --coverart. Note that the full path is required unless you know what |
| 8297 |
# you do. The same variables as in option --dirtemplate may be |
| 8298 |
# used and need to be quoted. |
| 8299 |
# Example: \"\$wavdir/../thumb.png\" |
| 8300 |
# Possible values: string, none |
| 8301 |
# Default: none |
| 8302 |
|
| 8303 |
coverpath=$coverpath |
| 8304 |
|
| 8305 |
# coversize: Alter size of provided cover to be added to tags and rename |
| 8306 |
# the original cover making use of the ImageMagick package. |
| 8307 |
# Example: 640x640 or simply in the format 640 |
| 8308 |
# Possible values: any valid format treated by ImageMagick |
| 8309 |
# Default: none |
| 8310 |
|
| 8311 |
coversize=$coversize |
| 8312 |
|
| 8313 |
# copycover: Copy a cover (or any other file) with full path to all |
| 8314 |
# directories containing encoded files. The same variables as in option |
| 8315 |
# --dirtemplate may be used and need to be quoted. |
| 8316 |
# Example: /media/snd/covers/cover.png |
| 8317 |
# Possible values: none - off, absolute path to image |
| 8318 |
# Default: off |
| 8319 |
|
| 8320 |
copycover=$copycover |
| 8321 |
|
| 8322 |
# mbrels: MusicBrainz relationships will be retrieved for each track to |
| 8323 |
# add vocal performer names in the form \"(featuring PERFORMER)\" or |
| 8324 |
# (covering WORK) if found. |
| 8325 |
# Possible values: 0 - off, 1 - on |
| 8326 |
# Default: off |
| 8327 |
|
| 8328 |
mbrels=$mbrels |
| 8329 |
|
| 8330 |
# vatag: Analyze track names for \"various artists\" style and split |
| 8331 |
# the meta data in case one of the delimiters (colon, hyphen, slash or |
| 8332 |
# parenthesis) are found. Use unpair numbers for the scheme |
| 8333 |
# \"artist ? tracktitle\" and pair numbers in the opposite case. |
| 8334 |
# The artist will be compared to the argument of option --vastring |
| 8335 |
# (see below). If the artist must be like vastring and each track have a |
| 8336 |
# delimiter, use 1 (2), if the artist must be like vastring while only |
| 8337 |
# some tracks contain the delimiter, use 3 (4), if no restrictions |
| 8338 |
# apply for the artist but all track names must have a delimiter, use |
| 8339 |
# 5 (6) and finally, if only a few tracks contain a delimiter to be |
| 8340 |
# used as splitting point, set vatag to 7 (8). |
| 8341 |
# Example: 5 |
| 8342 |
# Possible values: 0 - off, 1, 2, 3, 4, 5, 6, 7, 8 |
| 8343 |
# Default: off |
| 8344 |
|
| 8345 |
vatag=$vatag |
| 8346 |
|
| 8347 |
# vastring: the string (regular expression) that defines the |
| 8348 |
# \"various artists\" style |
| 8349 |
# Example: Varios|VA |
| 8350 |
# Possible values: string, none |
| 8351 |
# Default: \\bVA\\b|Variou*s|Various\\sArtists|Soundtrack|OST |
| 8352 |
|
| 8353 |
vastring=$vastring |
| 8354 |
|
| 8355 |
# mp3gain: Add album gain tags to mp3 files using the appropriate |
| 8356 |
# command with options and arguments but without in-files. |
| 8357 |
# Example: mp3gain -a -c -q -s i |
| 8358 |
# Default: not set |
| 8359 |
|
| 8360 |
mp3gain=$mp3gain |
| 8361 |
|
| 8362 |
# vorbgain: Add album gain tags to ogg files using the appropriate |
| 8363 |
# command with options and arguments but without in-files. |
| 8364 |
# Example: vorbisgain -a -q |
| 8365 |
# Default: not set |
| 8366 |
|
| 8367 |
vorbgain=$vorbgain |
| 8368 |
|
| 8369 |
# flacgain: Add album gain tags to flac files using the appropriate |
| 8370 |
# command with options and arguments but without in-files. |
| 8371 |
# Example: metaflac --add-replay-gain |
| 8372 |
# Default: not set |
| 8373 |
|
| 8374 |
flacgain=$flacgain |
| 8375 |
|
| 8376 |
# aacgain: Add album gain tags to mp4 or m4a files using the appropriate |
| 8377 |
# command with options and arguments but without in-files. |
| 8378 |
# Example: aacgain -a -c -q |
| 8379 |
# Default: not set |
| 8380 |
|
| 8381 |
aacgain=$aacgain |
| 8382 |
|
| 8383 |
# mpcgain: Add album gain tags to mpc files using the appropriate |
| 8384 |
# command with options and arguments but without in-files. |
| 8385 |
# Example: mpcgain |
| 8386 |
# Default: not set |
| 8387 |
|
| 8388 |
mpcgain=$mpcgain |
| 8389 |
|
| 8390 |
# wvgain: Add album gain tags to wv files using the appropriate |
| 8391 |
# command with options and arguments but without in-files. |
| 8392 |
# Example: wvgain -a -q |
| 8393 |
# Default: not set |
| 8394 |
|
| 8395 |
wvgain=$wvgain |
| 8396 |
|
| 8397 |
|
| 8398 |
##### |
| 8399 |
# |
| 8400 |
# CDDB options |
| 8401 |
# |
| 8402 |
|
| 8403 |
# mb: Access MusicBrainz DB via WebService::MusicBrainz module instead |
| 8404 |
# of the http protocol (see below). |
| 8405 |
# Possible values: 0 - off, 1 - on |
| 8406 |
# Default: off |
| 8407 |
|
| 8408 |
mb=$mb |
| 8409 |
|
| 8410 |
# CDDBHOST: Specifies the CDDB server |
| 8411 |
# Possible values: freedb.org, freedb2.org or musicbrainz.org |
| 8412 |
# Note: Full name of the server used is \$mirror.\$CDDBHOST, except for |
| 8413 |
# freedb2.org (no mirror) and musicbrainz.org has freedb as default |
| 8414 |
# mirror. |
| 8415 |
# E.g. default server is freedb.freedb.org |
| 8416 |
# Default: freedb.org |
| 8417 |
|
| 8418 |
CDDBHOST=$CDDB_HOST |
| 8419 |
|
| 8420 |
# mirror: Selects freedb mirror |
| 8421 |
# Possible values: \"freedb\" or any freedb mirrors |
| 8422 |
# See www.freedb.org for mirror list |
| 8423 |
# Note: Full name of the server used is \$mirror.\$CDDBHOST |
| 8424 |
# E.g., default server is freedb.freedb.org |
| 8425 |
# Default: freedb |
| 8426 |
|
| 8427 |
mirror=$mirror |
| 8428 |
|
| 8429 |
# transfer: Set transfer mode for cddb queries |
| 8430 |
# Possible values: cddb, http |
| 8431 |
# Note: CDDB servers freedb2.org and musicbrainz.org may need transfer |
| 8432 |
# mode http. |
| 8433 |
# Default: cddb |
| 8434 |
|
| 8435 |
transfer=$transfer |
| 8436 |
|
| 8437 |
# proto: Set CDDP protocol level |
| 8438 |
# Possible values: 5, 6 |
| 8439 |
# Protocol level 6 supports Unicode (UTF-8) |
| 8440 |
# Default: 6 |
| 8441 |
|
| 8442 |
proto=$proto |
| 8443 |
|
| 8444 |
# proxy: Address of http-proxy, if needed. |
| 8445 |
# Default: not set |
| 8446 |
|
| 8447 |
proxy=$proxy |
| 8448 |
|
| 8449 |
# mailad: Mail address for cddb submissions. |
| 8450 |
# Possible values: Valid user email address for submitting cddb entries |
| 8451 |
# Default: not set |
| 8452 |
|
| 8453 |
mailad=$mailad |
| 8454 |
|
| 8455 |
# mailopt: Additional options for sendmail. |
| 8456 |
# Possible values: Any sendmail options. |
| 8457 |
# Default: -t |
| 8458 |
|
| 8459 |
mailopt=$mailopt |
| 8460 |
|
| 8461 |
# archive: Read and save cddb data on local machine. |
| 8462 |
# Possible values: 0 - off, 1 - on |
| 8463 |
# Default: off |
| 8464 |
|
| 8465 |
archive=$archive |
| 8466 |
|
| 8467 |
# submission: Submit new or edited cddb entries to freeCDDB. |
| 8468 |
# Possible values: 0 - off, 1 - on |
| 8469 |
# Default: on |
| 8470 |
|
| 8471 |
submission=$submission |
| 8472 |
|
| 8473 |
# interaction: Turns on or off user interaction in cddb dialog and |
| 8474 |
# everywhere else. |
| 8475 |
# Possible values: 0 - off, 1 - on |
| 8476 |
# Default: on |
| 8477 |
|
| 8478 |
interaction=$interaction |
| 8479 |
|
| 8480 |
# isrc: detect track ISRCs using icedax and submit them to Musicbrainz |
| 8481 |
# if login info is provided. Please check if the device in use is |
| 8482 |
# able to read correct ISRCs and submit them if found. |
| 8483 |
# Possible values: 0 - off, 1 - on |
| 8484 |
# Default: off |
| 8485 |
|
| 8486 |
isrc=$isrc |
| 8487 |
|
| 8488 |
# mbname: login name to Musicbrainz.org |
| 8489 |
# Possible values: string |
| 8490 |
# Default: not set |
| 8491 |
|
| 8492 |
mbname=$mbname |
| 8493 |
|
| 8494 |
# mbpass: password to Musicbrainz.org |
| 8495 |
# Possible values: string |
| 8496 |
# Default: not set |
| 8497 |
|
| 8498 |
mbpass=$mbpass |
| 8499 |
|
| 8500 |
# cdtext: check if CD text is present and use it if no DB entry found. |
| 8501 |
# Possible values: 0 - off, 1 - on |
| 8502 |
# Default: off |
| 8503 |
|
| 8504 |
cdtext=$cdtext |
| 8505 |
|
| 8506 |
|
| 8507 |
##### |
| 8508 |
# |
| 8509 |
# LCD options |
| 8510 |
# |
| 8511 |
|
| 8512 |
# lcd: Use lcdproc to display status on LCD |
| 8513 |
# Possible values: 0 - off, 1 - on |
| 8514 |
# Default: off |
| 8515 |
|
| 8516 |
lcd=$lcd |
| 8517 |
|
| 8518 |
# lcdhost: Specify the lcdproc host |
| 8519 |
# Default: localhost |
| 8520 |
|
| 8521 |
lcdhost=$lcdhost |
| 8522 |
|
| 8523 |
# lcdport: Specify port number for $lcdhost |
| 8524 |
# Default: 13666 |
| 8525 |
|
| 8526 |
lcdport=$lcdport |
| 8527 |
|
| 8528 |
|
| 8529 |
##### |
| 8530 |
# |
| 8531 |
# Distributed ripping options |
| 8532 |
# |
| 8533 |
|
| 8534 |
# sshlist: Comma separated list of remote machines ripit shall use |
| 8535 |
# for encoding. The output path must be the same for all machines. |
| 8536 |
# Specify the login (login\@machine) only if not the |
| 8537 |
# same for the remote machine. Else just state the |
| 8538 |
# machine names. |
| 8539 |
# Default: not set |
| 8540 |
|
| 8541 |
sshlist=$wsshlist |
| 8542 |
|
| 8543 |
# scp: Copy files to encode to the remote machine. |
| 8544 |
# Use if the fs can not be accessed on the remote machines |
| 8545 |
# Possible values: 0 - off, 1 - on |
| 8546 |
# Default: off |
| 8547 |
|
| 8548 |
scp=$scp |
| 8549 |
|
| 8550 |
# local: Turn off encoding on local machine, e.g. use only remote |
| 8551 |
# machines. |
| 8552 |
# Possible values: 0 - off, 1 - on |
| 8553 |
# Example: local=0 (off) turns off encoding on the |
| 8554 |
# local machine |
| 8555 |
# Default: on |
| 8556 |
|
| 8557 |
local=$local |
| 8558 |
|
| 8559 |
|
| 8560 |
##### |
| 8561 |
# |
| 8562 |
# Misc. options |
| 8563 |
# |
| 8564 |
|
| 8565 |
# verbosity: Run silent (do not output comments, status etc.) (0), with |
| 8566 |
# minimal (1), normal without encoder msgs (2), normal (3), verbose (4) |
| 8567 |
# or extremely verbose (5). |
| 8568 |
# Possible values: 0...5 |
| 8569 |
# Default: 3 - normal |
| 8570 |
|
| 8571 |
verbose=$verbose |
| 8572 |
|
| 8573 |
# eject: Eject cd after finishing encoding. |
| 8574 |
# Possible values: 0 - off, 1 - on |
| 8575 |
# Default: off |
| 8576 |
|
| 8577 |
eject=$eject |
| 8578 |
|
| 8579 |
# ejectcmd: Command used to eject and close CD tray. |
| 8580 |
# Possible values: string |
| 8581 |
# Example: /usr/sbin/cdcontrol for FreeBSD |
| 8582 |
# Default: eject |
| 8583 |
|
| 8584 |
ejectcmd=$ejectcmd |
| 8585 |
|
| 8586 |
# ejectopt: Options to command used to eject or close CD. |
| 8587 |
# Possible values: string or \"{cddev}\" to design the CD |
| 8588 |
# device. |
| 8589 |
# Note: Don't use options -t / close or eject, |
| 8590 |
# RipIT knows when to eject or load the tray |
| 8591 |
# Default: {cddev} |
| 8592 |
|
| 8593 |
ejectopt=$ejectopt |
| 8594 |
|
| 8595 |
# quitnodb: Give up CD if no CDDB entry found. |
| 8596 |
# Useful if option --loop or --nointeraction are on. |
| 8597 |
# Default behaviour is to let operator enter data or to use default |
| 8598 |
# artist, album and track names. |
| 8599 |
# Possible values: 0 - off, 1 - on |
| 8600 |
# Default: off |
| 8601 |
|
| 8602 |
quitnodb=$quitnodb |
| 8603 |
|
| 8604 |
# execmd: Execute a command when done with ripping. Quote the command |
| 8605 |
# if needed. |
| 8606 |
# Note: The same variables as in the dirtemplate can be used. When |
| 8607 |
# using MusicBrainz one might want to use \$cd{asin} to get the ASIN |
| 8608 |
# if available. |
| 8609 |
# Possible values: none - off, string - on |
| 8610 |
# Example: execmd=\"add_db -a \\\"\$artist\\\" -r \\\"\$album\\\"\" |
| 8611 |
# Default: off |
| 8612 |
|
| 8613 |
execmd=$execmd |
| 8614 |
|
| 8615 |
# precmd: Execute a command before starting to rip. Quote the command |
| 8616 |
# if needed. |
| 8617 |
# Note: The same variables as in the dirtemplate can be used. When |
| 8618 |
# using MusicBrainz one might want to use \$cd{asin} to get the ASIN |
| 8619 |
# if available. |
| 8620 |
# Possible values: none - off, string - on |
| 8621 |
# Example: precmd=\"get_cover -a \\\"\$artist\\\" -r \\\"\$album\\\" -o \\\"\$wavdir\\\" -t \\\"\$trackno\\\"\" |
| 8622 |
# Default: off |
| 8623 |
|
| 8624 |
precmd=$precmd |
| 8625 |
|
| 8626 |
# book: Create an audiobook, i. e. merge all tracks into one single |
| 8627 |
# file, option --ghost will be switched off and file suffix will be |
| 8628 |
# m4b. Make sure to use encoder faac, ripit will not check that. |
| 8629 |
# A chapter file will be written for chapter marks. |
| 8630 |
# Possible values: 0 - off, 1 - on |
| 8631 |
# Default: off |
| 8632 |
|
| 8633 |
book=$book |
| 8634 |
|
| 8635 |
# loop: Continue with a new CD when the previous one is done. |
| 8636 |
# Option --eject will be forced. To start ripping process immediately |
| 8637 |
# after ejection of previous disc, use experimental argument 2. Ripit |
| 8638 |
# will restart as child process, one might see the prompt and it will |
| 8639 |
# be necessary to manually terminate the process! Use with caution! |
| 8640 |
# Possible values: 0 - off, 1 - on, 2 - immediate restart, experimental |
| 8641 |
# Default: off |
| 8642 |
|
| 8643 |
loop=$loop |
| 8644 |
|
| 8645 |
# halt: Powers off machine after finishing encoding. |
| 8646 |
# Possible values: 0 - off, 1 - on |
| 8647 |
# Default: off |
| 8648 |
|
| 8649 |
halt=$halt |
| 8650 |
|
| 8651 |
# nice: Sets \"nice\" value for the encoding process. |
| 8652 |
# Possible values: 0..19 for normal users, |
| 8653 |
# -20..19 for user \"root\" |
| 8654 |
# Default: 0 |
| 8655 |
|
| 8656 |
nice=$nice |
| 8657 |
|
| 8658 |
# nicerip: Sets \"nice\" value for the ripping process. |
| 8659 |
# Possible values: 0..19 for normal users, |
| 8660 |
# -20..19 for user \"root\" |
| 8661 |
# Default: 0 |
| 8662 |
|
| 8663 |
nicerip=$nicerip |
| 8664 |
|
| 8665 |
# threads: Comma separated list of numbers giving maximum |
| 8666 |
# of allowed encoder processes to run at the same time |
| 8667 |
# (on each machine when using sshlist). |
| 8668 |
# Possible values: comma separated integers |
| 8669 |
# Default: 1 |
| 8670 |
|
| 8671 |
threads=$wthreads |
| 8672 |
|
| 8673 |
# md5sum: Create file with md5sums for each type of sound files. |
| 8674 |
# Possible values: 0 - off, 1 - on |
| 8675 |
# Default: off |
| 8676 |
|
| 8677 |
md5sum=$md5sum |
| 8678 |
|
| 8679 |
# wav: Don't delete wave-files after encoding. |
| 8680 |
# Possible values: 0 - off, 1 - on |
| 8681 |
# Default: off |
| 8682 |
|
| 8683 |
wav=$wav |
| 8684 |
|
| 8685 |
# normalize: Normalizes the wave-files to a given dB-value |
| 8686 |
# (default: -12dB) |
| 8687 |
# See http://normalize.nongnu.org for details. |
| 8688 |
# Possible values: 0 - off, 1 - on |
| 8689 |
# Default: off |
| 8690 |
|
| 8691 |
normalize=$normalize |
| 8692 |
|
| 8693 |
# normcmd: Command to be used to normalize. |
| 8694 |
# Possible values: string |
| 8695 |
# Example: normalize-audio (when using Debian) |
| 8696 |
# Default: normalize |
| 8697 |
|
| 8698 |
normcmd=$normcmd |
| 8699 |
|
| 8700 |
# normopt: Options to pass to normalize |
| 8701 |
# Possible values: -a -nndB : Normalize to -nn dB, default is -12dB, |
| 8702 |
# Value range: All values <= 0dB |
| 8703 |
# Example : normalize -a -20dB *.wav |
| 8704 |
# -b : Batch mode - loudness differences |
| 8705 |
# between individual tracks of a CD are |
| 8706 |
# maintained |
| 8707 |
# -m : Mix mode - all track are normalized to |
| 8708 |
# the same loudness |
| 8709 |
# -v : Verbose operation |
| 8710 |
# -q : Quiet operation |
| 8711 |
# For further options see normalize documentation. |
| 8712 |
# Default: -b |
| 8713 |
# The -v option will be added by default according to RipITs verbosity |
| 8714 |
|
| 8715 |
normopt=$normopt |
| 8716 |
|
| 8717 |
# playlist: Create m3u playlist with or without the full path |
| 8718 |
# in the filename. |
| 8719 |
# Possible values: 0 - off, |
| 8720 |
# 1 - on with full path |
| 8721 |
# 2 - on with no path (filename only) |
| 8722 |
# Default: on (with full path) |
| 8723 |
|
| 8724 |
playlist=$playlist |
| 8725 |
|
| 8726 |
# cue: Create a cue file with all tracks to play or burn them with |
| 8727 |
# cd-text. |
| 8728 |
# Possible values: 0 - off, 1 - on |
| 8729 |
# Default: off |
| 8730 |
|
| 8731 |
cue=$cue |
| 8732 |
|
| 8733 |
# cdtoc: Create a toc file to burn the wavs with |
| 8734 |
# cd-text using cdrdao or cdrecord (in dao mode). |
| 8735 |
# Possible values: 0 - off, 1 - on |
| 8736 |
# Default: off |
| 8737 |
|
| 8738 |
cdtoc=$cdtoc |
| 8739 |
|
| 8740 |
# inf: Create inf files to burn the wavs with |
| 8741 |
# cd-text using wodim or cdrecord (in dao mode). |
| 8742 |
# Possible values: 0 - off, 1 - on |
| 8743 |
# Default: off |
| 8744 |
|
| 8745 |
inf=$inf |
| 8746 |
|
| 8747 |
# cdcue: Create a cue file to burn the merged wav with cd-text. |
| 8748 |
# Note that all tracks will be merged and normalized. |
| 8749 |
# Possible values: 0 - off, 1 - on, 2 - on (experimental fallback) |
| 8750 |
# Note: Use value 2 only if for whatever reason value 1 should fail. |
| 8751 |
# Default: off |
| 8752 |
|
| 8753 |
cdcue=$cdcue |
| 8754 |
\n"; |
| 8755 |
close(CONF); |
| 8756 |
} |
| 8757 |
######################################################################## |
| 8758 |
# |
| 8759 |
# Read the config file, take the parameters only if NOT yet defined! |
| 8760 |
# |
| 8761 |
# New options step 11: Read the new options from config file. Replicate |
| 8762 |
# one of the 2-liners starting with chomp. |
| 8763 |
# |
| 8764 |
sub read_config { |
| 8765 |
if($confdir ne "") { |
| 8766 |
$ripdir = $confdir . "/" . $confname; |
| 8767 |
} |
| 8768 |
elsif($confname ne "config") { |
| 8769 |
$ripdir = $homedir . "/.ripit/" . $confname; |
| 8770 |
} |
| 8771 |
# Fallback: |
| 8772 |
$ripdir = $homedir . "/.ripit/config" unless(-r "$ripdir"); |
| 8773 |
$ripdir = "/etc/ripit/config" unless(-r "$ripdir"); |
| 8774 |
print "Reading config file in $ripdir.\n" if($verbose > 4); |
| 8775 |
if(-r "$ripdir") { |
| 8776 |
open(CONF, "$ripdir") or |
| 8777 |
print "Can not read config file in $ripdir: $!\n"; |
| 8778 |
my @conflines = <CONF>; |
| 8779 |
close(CONF); |
| 8780 |
my @confver = grep(s/^# RipIT //, @conflines); |
| 8781 |
@confver = split(/ /, $confver[0]) if($confver[0] =~ /^\d/); |
| 8782 |
my $confver = $confver[0] if($confver[0] =~ /^\d/); |
| 8783 |
$confver = 0 unless($confver); |
| 8784 |
chomp $confver; |
| 8785 |
if($version ne $confver && $savepara == 0) { |
| 8786 |
$verbose = 3 if($verbose <= 1); |
| 8787 |
print "\nPlease update your config-file with option --save"; |
| 8788 |
print "\nto ensure correct settings! Pausing 3 seconds!\n\n"; |
| 8789 |
sleep(3); |
| 8790 |
} |
| 8791 |
elsif($version ne $confver) { |
| 8792 |
grep(s/^chars=[01]\s*$/chars=/, @conflines); |
| 8793 |
} |
| 8794 |
chomp($accuracy = join(' ', grep(s/^accuracy=//, @conflines))) |
| 8795 |
unless defined $paccuracy; |
| 8796 |
chomp($archive = join(' ', grep(s/^archive=//, @conflines))) |
| 8797 |
unless defined $parchive; |
| 8798 |
chomp($bitrate = join(' ', grep(s/^bitrate=//, @conflines))) |
| 8799 |
unless($pbitrate); |
| 8800 |
chomp($book = join(' ', grep(s/^book=//, @conflines))) |
| 8801 |
unless($pbook); |
| 8802 |
chomp($maxrate = join(' ', grep(s/^maxrate=//, @conflines))) |
| 8803 |
unless($pmaxrate); |
| 8804 |
chomp($cddev = join(' ', grep(s/^cddevice=//, @conflines))) |
| 8805 |
unless($pcddev); |
| 8806 |
chomp($scsi_cddev = join(' ', grep(s/^scsidevice=//, @conflines))) |
| 8807 |
unless($pscsi_cddev); |
| 8808 |
chomp($cdtext = join('', grep(s/^cdtext=//, @conflines))) |
| 8809 |
unless defined $pcdtext; # Remember, $cdtext might be zero. |
| 8810 |
chomp($cdtoc = join('', grep(s/^cdtoc=//, @conflines))) |
| 8811 |
unless defined $pcdtoc; # Remember, $cdtoc might be zero. |
| 8812 |
chomp($cdcue = join('', grep(s/^cdcue=//, @conflines))) |
| 8813 |
unless($pcdcue); |
| 8814 |
chomp($cue = join('', grep(s/^cue=//, @conflines))) |
| 8815 |
unless($pcue); |
| 8816 |
chomp($chars = join('', grep(s/^chars=//, @conflines))) |
| 8817 |
if($chars eq "XX"); |
| 8818 |
chomp($commentag = join('', grep(s/^comment=//, @conflines))) |
| 8819 |
unless($pcommentag); |
| 8820 |
chomp($CDDB_HOST = join('', grep(s/^CDDBHOST=//, @conflines))) |
| 8821 |
unless($PCDDB_HOST); |
| 8822 |
@pcoder = grep(s/^coder=//, @conflines) unless(@pcoder); |
| 8823 |
# NOTE: all coders are in array entry $pcoder[0]! |
| 8824 |
# NOTE: we have to fill the wcoder (w=write) variable! |
| 8825 |
$wcoder = $pcoder[0] if(@pcoder); |
| 8826 |
chomp $wcoder; |
| 8827 |
@dirtemplate = grep(s/^dirtemplate=//, @conflines) |
| 8828 |
unless($pdirtemplate[0]); |
| 8829 |
chomp $_ foreach(@dirtemplate); |
| 8830 |
chomp($dpermission = join('', grep(s/^dpermission=//, @conflines))) |
| 8831 |
unless($pdpermission); |
| 8832 |
chomp($eject = join('', grep(s/^eject=//, @conflines))) |
| 8833 |
unless defined $peject; |
| 8834 |
chomp($ejectcmd = join('', grep(s/^ejectcmd=//, @conflines))) |
| 8835 |
unless defined $pejectcmd; |
| 8836 |
chomp($ejectopt = join('', grep(s/^ejectopt=//, @conflines))) |
| 8837 |
unless defined $pejectopt; |
| 8838 |
chomp($encode = join('', grep(s/^encode=//, @conflines))) |
| 8839 |
unless defined $pencode; |
| 8840 |
chomp($extend = join('', grep(s/^extend=//, @conflines))) |
| 8841 |
unless defined $pextend; |
| 8842 |
chomp($execmd = join('', grep(s/^execmd=//, @conflines))) |
| 8843 |
unless defined $pexecmd; |
| 8844 |
chomp($precmd = join('', grep(s/^precmd=//, @conflines))) |
| 8845 |
unless defined $pprecmd; |
| 8846 |
chomp($fpermission = join('', grep(s/^fpermission=//, @conflines))) |
| 8847 |
unless($pfpermission); |
| 8848 |
chomp($ghost = join('', grep(s/^ghost=//, @conflines))) |
| 8849 |
unless defined $pghost; |
| 8850 |
chomp($halt = join('', grep(s/^halt=//, @conflines))) |
| 8851 |
unless($phalt); |
| 8852 |
chomp($inf = join('', grep(s/^inf=//, @conflines))) |
| 8853 |
unless($pinf); |
| 8854 |
chomp($infolog = join('', grep(s/^infolog=//, @conflines))) |
| 8855 |
unless(defined $pinfolog); |
| 8856 |
chomp($interaction = join('', grep(s/^interaction=//, @conflines))) |
| 8857 |
unless defined $pinteraction; |
| 8858 |
chomp($isrc = join('', grep(s/^isrc=//, @conflines))) |
| 8859 |
unless defined $pisrc; |
| 8860 |
chomp($lcd = join('', grep(s/^lcd=//, @conflines))) |
| 8861 |
unless defined $plcd; |
| 8862 |
chomp($lcdhost = join('', grep(s/^lcdhost=//, @conflines))) |
| 8863 |
unless($plcdhost); |
| 8864 |
chomp($lcdport = join('', grep(s/^lcdport=//, @conflines))) |
| 8865 |
unless($plcdport); |
| 8866 |
chomp($local = join('', grep(s/^local=//, @conflines))) |
| 8867 |
unless defined $plocal; |
| 8868 |
chomp($loop = join('', grep(s/^loop=//, @conflines))) |
| 8869 |
unless defined $ploop; |
| 8870 |
chomp($lowercase = join('', grep(s/^lowercase=//, @conflines))) |
| 8871 |
unless defined $plowercase; |
| 8872 |
chomp($uppercasefirst = join('', grep(s/^uppercasefirst=//, @conflines))) |
| 8873 |
unless defined $puppercasefirst; |
| 8874 |
chomp($mailad = join('', grep(s/^mailad=//, @conflines))) |
| 8875 |
unless($pmailad); |
| 8876 |
chomp($mailopt = join('', grep(s/^mailopt=//, @conflines))) |
| 8877 |
unless($pmailopt); |
| 8878 |
chomp($mb = join('', grep(s/^mb=//, @conflines))) |
| 8879 |
unless defined $pmb; |
| 8880 |
chomp($mbrels = join('', grep(s/^mbrels=//, @conflines))) |
| 8881 |
unless defined $pmbrels; |
| 8882 |
chomp($mbname = join('', grep(s/^mbname=//, @conflines))) |
| 8883 |
unless defined $pmbname; |
| 8884 |
chomp($mbpass = join('', grep(s/^mbpass=//, @conflines))) |
| 8885 |
unless defined $pmbpass; |
| 8886 |
chomp($md5sum = join('', grep(s/^md5sum=//, @conflines))) |
| 8887 |
unless($pmd5sum); |
| 8888 |
chomp($mirror = join('', grep(s/^mirror=//, @conflines))) |
| 8889 |
unless($pmirror); |
| 8890 |
@flactags = grep(s/^flactags=//, @conflines) |
| 8891 |
unless($pflactags[0]); |
| 8892 |
chomp $_ foreach(@flactags); |
| 8893 |
@oggtags = grep(s/^oggtags=//, @conflines) |
| 8894 |
unless($poggtags[0]); |
| 8895 |
chomp $_ foreach(@oggtags); |
| 8896 |
@mp3tags = grep(s/^mp3tags=//, @conflines) |
| 8897 |
unless($pmp3tags[0]); |
| 8898 |
chomp $_ foreach(@mp3tags); |
| 8899 |
chomp($musenc = join('', grep(s/^musenc=//, @conflines))) |
| 8900 |
unless($pmusenc); |
| 8901 |
chomp($normalize = join('', grep(s/^normalize=//, @conflines))) |
| 8902 |
unless defined $pnormalize; |
| 8903 |
chomp($normcmd = join('', grep(s/^normcmd=//, @conflines))) |
| 8904 |
unless($pnormcmd); |
| 8905 |
chomp($normopt = join('', grep(s/^normopt=//, @conflines))) |
| 8906 |
unless($pnormopt); |
| 8907 |
chomp($nice = join('', grep(s/^nice=//, @conflines))) |
| 8908 |
unless defined $pnice; |
| 8909 |
chomp($nicerip = join('', grep(s/^nicerip=//, @conflines))) |
| 8910 |
unless defined $pnicerip; |
| 8911 |
chomp($offset = join('', grep(s/^offset=//, @conflines))) |
| 8912 |
unless($poffset); |
| 8913 |
chomp($outputdir = join('', grep(s/^output=//, @conflines))) |
| 8914 |
unless($poutputdir); |
| 8915 |
chomp($overwrite = join('', grep(s/^overwrite=//, @conflines))) |
| 8916 |
unless($poverwrite); |
| 8917 |
chomp($parano = join('', grep(s/^paranoia=//, @conflines))) |
| 8918 |
unless defined $pparano; |
| 8919 |
chomp($playlist = join('', grep(s/^playlist=//, @conflines))) |
| 8920 |
unless defined $pplaylist; |
| 8921 |
chomp($prepend = join('', grep(s/^prepend=//, @conflines))) |
| 8922 |
unless defined $pprepend; |
| 8923 |
chomp($preset = join('', grep(s/^preset=//, @conflines))) |
| 8924 |
unless($ppreset); |
| 8925 |
# NOTE: we have to fill the w_RITE_preset variable! |
| 8926 |
$wpreset = $preset unless($ppreset); |
| 8927 |
chomp $preset; |
| 8928 |
chomp $wpreset; |
| 8929 |
chomp($proto = join('', grep(s/^proto=//, @conflines))) |
| 8930 |
unless($pproto); |
| 8931 |
chomp($proxy = join('', grep(s/^proxy=//, @conflines))) |
| 8932 |
unless($pproxy); |
| 8933 |
my @quafaac = grep(s/^quafaac=//, @conflines) unless($pquality[0]); |
| 8934 |
chomp($quafaac = $quafaac[0]) unless($pquality[0]); |
| 8935 |
my @quaflac = grep(s/^quaflac=//, @conflines) unless($pquality[0]); |
| 8936 |
chomp($quaflac = $quaflac[0]) unless($pquality[0]); |
| 8937 |
my @qualame = grep(s/^qualame=//, @conflines) unless($pquality[0]); |
| 8938 |
chomp($qualame = $qualame[0]) unless($pquality[0]); |
| 8939 |
my @qualoggenc = grep(s/^qualoggenc=//, @conflines) |
| 8940 |
unless($pquality[0]); |
| 8941 |
chomp($qualoggenc = $qualoggenc[0]) unless($pquality[0]); |
| 8942 |
my @quamp4als = grep(s/^quamp4als=//, @conflines) |
| 8943 |
unless($pquality[0]); |
| 8944 |
chomp($quamp4als = $quamp4als[0]) unless($pquality[0]); |
| 8945 |
my @quamuse = grep(s/^quamuse=//, @conflines) |
| 8946 |
unless($pquality[0]); |
| 8947 |
chomp($quamuse = $quamuse[0]) unless($pquality[0]); |
| 8948 |
# I don't really like this. I don't like the variables qualame etc |
| 8949 |
# too and wanted to get rid of them. Not possible anymore. We need |
| 8950 |
# them because they hold a comma separated string necessary to |
| 8951 |
# write to the config file... |
| 8952 |
unless($pquality[0]) { |
| 8953 |
@qualame = split(/,/, $qualame); |
| 8954 |
@qualoggenc = split(/,/, $qualoggenc); |
| 8955 |
@quaflac = split(/,/, $quaflac); |
| 8956 |
@quafaac = split(/,/, $quafaac); |
| 8957 |
@quamp4als = split(/,/, $quamp4als); |
| 8958 |
@quamuse = split(/,/, $quamuse); |
| 8959 |
@coder = split(/,/, join(',',@pcoder)); |
| 8960 |
for(my $c=0; $c<=$#coder; $c++) { |
| 8961 |
if($coder[$c] == 0) { |
| 8962 |
print "\nWarning: Config file has less Lame qualties than stated coders!\nPlease fix your config file.\n" if(!defined $qualame[0]); |
| 8963 |
$quality[$c] = $qualame[0]; |
| 8964 |
shift(@qualame); |
| 8965 |
} |
| 8966 |
if($coder[$c] == 1) { |
| 8967 |
print "\nWarning: Config file has less Oggenc qualties than stated coders!\nPlease fix your config file.\n" if(!defined $qualoggenc[0]); |
| 8968 |
$quality[$c] = $qualoggenc[0]; |
| 8969 |
shift(@qualoggenc); |
| 8970 |
} |
| 8971 |
if($coder[$c] == 2) { |
| 8972 |
print "\nWarning: Config file has less Flac qualties than stated coders!\nPlease fix your config file.\n" if(!defined $quaflac[0]); |
| 8973 |
$quality[$c] = $quaflac[0]; |
| 8974 |
shift(@quaflac); |
| 8975 |
} |
| 8976 |
if($coder[$c] == 3) { |
| 8977 |
print "\nWarning: Config file has less Faac qualties than stated coders!\nPlease fix your config file.\n" if(!defined $quafaac[0]); |
| 8978 |
$quality[$c] = $quafaac[0]; |
| 8979 |
shift(@quafaac); |
| 8980 |
} |
| 8981 |
if($coder[$c] == 4) { |
| 8982 |
print "\nWarning: Config file has less mp4als qualties than stated coders!\nPlease fix your config file.\n" if(!defined $quamp4als[0]); |
| 8983 |
$quality[$c] = $quamp4als[0]; |
| 8984 |
shift(@quamp4als); |
| 8985 |
} |
| 8986 |
if($coder[$c] == 5) { |
| 8987 |
print "\nWarning: Config file has less Musepack qualties than stated coders!\nPlease fix your config file.\n" if(!defined $quamuse[0]); |
| 8988 |
$quality[$c] = $quamuse[0]; |
| 8989 |
shift(@quamuse); |
| 8990 |
} |
| 8991 |
} |
| 8992 |
} |
| 8993 |
chomp($faacopt = join('', grep(s/^faacopt=//, @conflines))) |
| 8994 |
unless($pfaacopt); |
| 8995 |
chomp($flacopt = join('', grep(s/^flacopt=//, @conflines))) |
| 8996 |
unless($pflacopt); |
| 8997 |
chomp($flacdecopt = join('', grep(s/^flacdecopt=//, @conflines))) |
| 8998 |
unless($pflacdecopt); |
| 8999 |
chomp($lameopt = join('', grep(s/^lameopt=//, @conflines))) |
| 9000 |
unless($plameopt); |
| 9001 |
chomp($mp4alsopt = join('', grep(s/^mp4alsopt=//, @conflines))) |
| 9002 |
unless($pmp4alsopt); |
| 9003 |
chomp($museopt = join('', grep(s/^museopt=//, @conflines))) |
| 9004 |
unless($pmuseopt); |
| 9005 |
chomp($oggencopt = join('', grep(s/^oggencopt=//, @conflines))) |
| 9006 |
unless($poggencopt); |
| 9007 |
chomp($wavpacopt = join('', grep(s/^wavpacopt=//, @conflines))) |
| 9008 |
unless($pwavpacopt); |
| 9009 |
chomp($aacgain = join('', grep(s/^aacgain=//, @conflines))) |
| 9010 |
unless($paacgain); |
| 9011 |
chomp($flacgain = join('', grep(s/^flacgain=//, @conflines))) |
| 9012 |
unless($pflacgain); |
| 9013 |
chomp($mp3gain = join('', grep(s/^mp3gain=//, @conflines))) |
| 9014 |
unless($pmp3gain); |
| 9015 |
chomp($mpcgain = join('', grep(s/^mpcgain=//, @conflines))) |
| 9016 |
unless($pmpcgain); |
| 9017 |
chomp($vorbgain = join('', grep(s/^vorbgain=//, @conflines))) |
| 9018 |
unless($pvorbgain); |
| 9019 |
chomp($wvgain = join('', grep(s/^wvgain=//, @conflines))) |
| 9020 |
unless($pwvgain); |
| 9021 |
chomp($ffmpegopt = join('', grep(s/^ffmpegopt=//, @conflines))) |
| 9022 |
unless($pffmpegopt); |
| 9023 |
chomp($ffmpegsuffix = join('', grep(s/^ffmpegsuffix=//, @conflines))) |
| 9024 |
unless($pffmpegsuffix); |
| 9025 |
chomp($coverart = join('', grep(s/^coverart=//, @conflines))) |
| 9026 |
unless($pcoverart); |
| 9027 |
chomp($coverorg = join('', grep(s/^coverorg=//, @conflines))) |
| 9028 |
unless defined $pcoverorg; |
| 9029 |
chomp($coverpath = join('', grep(s/^coverpath=//, @conflines))) |
| 9030 |
unless($pcoverpath); |
| 9031 |
chomp($coversize = join('', grep(s/^coversize=//, @conflines))) |
| 9032 |
unless($pcoversize); |
| 9033 |
chomp($copycover = join('', grep(s/^copycover=//, @conflines))) |
| 9034 |
unless($pcopycover); |
| 9035 |
chomp($quitnodb = join('', grep(s/^quitnodb=//, @conflines))) |
| 9036 |
unless defined $pquitnodb; |
| 9037 |
chomp($ripper = join('', grep(s/^ripper=//, @conflines))) |
| 9038 |
unless defined $pripper; |
| 9039 |
chomp($resume = join('', grep(s/^resume=//, @conflines))) |
| 9040 |
unless defined $presume; |
| 9041 |
chomp($ripopt = join('', grep(s/^ripopt=//, @conflines))) |
| 9042 |
unless defined $pripopt; |
| 9043 |
my @clist = grep(s/^threads=//, @conflines) unless($pthreads[0]); |
| 9044 |
chomp @clist; |
| 9045 |
# NOTE: all threads numbers are in array entry $clist[0]! |
| 9046 |
@threads = split(/,/, join(',',@clist)); |
| 9047 |
my @rlist = grep(s/^sshlist=//, @conflines) unless($psshlist[0]); |
| 9048 |
chomp @rlist; |
| 9049 |
# NOTE: all machine names are in array entry $rlist[0]! |
| 9050 |
@sshlist = split(/,/, join(',',@rlist)); |
| 9051 |
chomp($scp = join('', grep(s/^scp=//, @conflines))) |
| 9052 |
unless defined $pscp; |
| 9053 |
chomp($span = join('', grep(s/^span=//, @conflines))) |
| 9054 |
unless defined $pspan; |
| 9055 |
chomp($submission = join('', grep(s/^submission=//, @conflines))) |
| 9056 |
unless defined $psubmission; |
| 9057 |
chomp($transfer = join('', grep(s/^transfer=//, @conflines))) |
| 9058 |
unless($ptransfer); |
| 9059 |
chomp($tracktemplate = join('', grep(s/^tracktemplate=//, @conflines))) |
| 9060 |
unless($ptracktemplate); |
| 9061 |
chomp($trackoffset = join('', grep(s/^trackoffset=//, @conflines))) |
| 9062 |
unless($ptrackoffset); |
| 9063 |
chomp($addtrackoffset = join('', grep(s/^addtrackoffset=//, @conflines))) |
| 9064 |
unless($paddtrackoffset); |
| 9065 |
chomp($discno = join('', grep(s/^discno=//, @conflines))) |
| 9066 |
unless($pdiscno); |
| 9067 |
chomp($underscore = join('', grep(s/^underscore=//, @conflines))) |
| 9068 |
unless defined $punderscore; |
| 9069 |
chomp($utftag = join('', grep(s/^utftag=//, @conflines))) |
| 9070 |
unless defined $putftag; |
| 9071 |
chomp($vatag = join('', grep(s/^vatag=//, @conflines))) |
| 9072 |
unless defined $pvatag; |
| 9073 |
chomp($vastring = join('', grep(s/^vastring=//, @conflines))) |
| 9074 |
unless defined $pvastring; |
| 9075 |
chomp($vbrmode = join('', grep(s/^vbrmode=//, @conflines))) |
| 9076 |
unless($pvbrmode); |
| 9077 |
chomp($verify = join('', grep(s/^verify=//, @conflines))) |
| 9078 |
unless defined $pverify; |
| 9079 |
chomp($year = join('', grep(s/^year=//, @conflines))) |
| 9080 |
unless($pyear); |
| 9081 |
chomp($wav = join('', grep(s/^wav=//, @conflines))) |
| 9082 |
unless defined $pwav; |
| 9083 |
} |
| 9084 |
else { |
| 9085 |
print "\nNo config file found! Use option --save to create one.\n" |
| 9086 |
if($verbose >= 2); |
| 9087 |
} |
| 9088 |
} |
| 9089 |
# |
| 9090 |
# |
| 9091 |
######################################################################## |
| 9092 |
# |
| 9093 |
# Change encoding of tags back to iso-8859-1. Again: this is only needed |
| 9094 |
# when using lame to create mp3s. Tagging works for all other |
| 9095 |
# encoders and encodings. |
| 9096 |
# |
| 9097 |
# Test CDs where option --noutf should work: |
| 9098 |
# Bang Bang: Je t'aime... 10: Sacré cœur |
| 9099 |
# Distain!: [Li:quíd]: 3: Summer 84 |
| 9100 |
# Enya: The Celts: 10: Triad: St. Patrick Cú Chulainn Oisin |
| 9101 |
# Enya: The Celts: 14: Dan y Dŵr |
| 9102 |
# Röyksopp: Junior: 5: Röyksopp Forever |
| 9103 |
# Žofka: Bad Girls: 1: Woho |
| 9104 |
# |
| 9105 |
sub back_encoding { |
| 9106 |
my $string = shift; |
| 9107 |
my $latin1 = encode("latin1", $string); |
| 9108 |
my $utf_string = $string; |
| 9109 |
if(utf8::is_utf8($string)) { |
| 9110 |
print "The \$string is already in utf8, do nothing!\n" |
| 9111 |
if($verbose > 5); |
| 9112 |
} |
| 9113 |
else { |
| 9114 |
print "The \$string is *not* in utf8, encode->decode!\n" |
| 9115 |
if($verbose > 5); |
| 9116 |
$utf_string = Encode::decode('UTF-8', $utf_string, Encode::FB_QUIET); |
| 9117 |
} |
| 9118 |
my @utf_points = unpack("U0U*", "$utf_string"); # Perl 5.10 |
| 9119 |
my $latinflag = 0; |
| 9120 |
my $wideflag = 0; |
| 9121 |
foreach (@utf_points) { |
| 9122 |
$wideflag = 1 if($_ > 255); |
| 9123 |
$latinflag++ if($_ > 128 && $_ < 256); |
| 9124 |
} |
| 9125 |
|
| 9126 |
# It works with Röyksopp archive and freeCDDB entry. |
| 9127 |
my @char_points = unpack("U0U*", "$string"); |
| 9128 |
@char_points = @utf_points if($wideflag == 1); |
| 9129 |
|
| 9130 |
return $string if($string eq ""); |
| 9131 |
my $decoded = ""; |
| 9132 |
foreach (@char_points) { |
| 9133 |
if($_ > 255) { |
| 9134 |
print "\"Wide\" char detected: $_.\n" if($verbose > 5); |
| 9135 |
use Unicode::UCD 'charinfo'; |
| 9136 |
my $charinfo = charinfo(sprintf("0x%X", $_)); |
| 9137 |
my $letter = $charinfo->{name}; |
| 9138 |
print "The charinfo is <$letter>.\n" if($verbose > 5); |
| 9139 |
my $smallflag = 0; |
| 9140 |
$smallflag = 1 if($letter =~ /SMALL\sLETTER/); |
| 9141 |
$smallflag = 1 if($letter =~ /SMALL\sLIGATURE/); |
| 9142 |
$letter =~ s/^.*LETTER\s(\w+)\s.*/$1/; |
| 9143 |
$letter =~ s/^.*LIGATURE\s(\w+)(\.|\s)*.*/$1/; |
| 9144 |
$letter = "\L$letter" if($smallflag == 1); |
| 9145 |
# Rather do nothing than print rubbish (string with words): |
| 9146 |
$letter = $_ if($letter =~ /\s/); |
| 9147 |
print "New letter will be: $letter.\n" if($verbose > 5); |
| 9148 |
$decoded .= $letter; |
| 9149 |
} |
| 9150 |
else { |
| 9151 |
$decoded .= chr($_); |
| 9152 |
} |
| 9153 |
} |
| 9154 |
|
| 9155 |
if($cd{discid}) { |
| 9156 |
# Special condition for MB data. Please do not ask why. |
| 9157 |
if($wideflag == 0 && $latinflag == 0) { |
| 9158 |
# Original. |
| 9159 |
Encode::from_to($decoded, 'UTF8', 'iso-8859-1'); |
| 9160 |
# But we come here in every case because we want the discid to be |
| 9161 |
# present (in comment tags), but come from archive, not from MB. |
| 9162 |
} |
| 9163 |
elsif($wideflag == 0) { |
| 9164 |
Encode::from_to($decoded, 'UTF8', 'ISO-8859-1'); |
| 9165 |
} |
| 9166 |
} |
| 9167 |
elsif($wideflag == 0) { |
| 9168 |
Encode::from_to($decoded, 'UTF8', 'ISO-8859-1'); |
| 9169 |
} |
| 9170 |
return($decoded); |
| 9171 |
} |
| 9172 |
######################################################################## |
| 9173 |
# |
| 9174 |
# Check the preset options. |
| 9175 |
# |
| 9176 |
sub check_preset { |
| 9177 |
if($preset !~ /^\d/) { |
| 9178 |
while($preset !~ /^insane$|^extreme$|^standard$|^medium$/) { |
| 9179 |
print "\nPreset should be one of the following words! Please"; |
| 9180 |
print " Enter \ninsane (320\@CBR), extreme (256), standard"; |
| 9181 |
print " (192) or medium (160), (standard): "; |
| 9182 |
$preset = <STDIN>; |
| 9183 |
chomp $preset; |
| 9184 |
if($preset eq "") { |
| 9185 |
$preset = "standard"; |
| 9186 |
} |
| 9187 |
} |
| 9188 |
} |
| 9189 |
else { |
| 9190 |
while($preset !~ m/^32$|^40$|^48$|^56$|^64$|^80$|^96$|^112$|^128$| |
| 9191 |
|^160$|^192$|^224$|^256$|^320$/) { |
| 9192 |
print "\nPreset should be one of the following numbers!", |
| 9193 |
" Please Enter \n32, 40, 48, 56, 64, 80, 96, 112, 128,", |
| 9194 |
" 160, 192, 224, 256 or 320, (128):\n"; |
| 9195 |
$preset = <STDIN>; |
| 9196 |
chomp $preset; |
| 9197 |
if($preset eq "") { |
| 9198 |
$preset = 128; |
| 9199 |
} |
| 9200 |
} |
| 9201 |
} |
| 9202 |
$preset = "medium" if($preset =~ /\d+/ && $preset == 160); |
| 9203 |
$preset = "standard" if($preset =~ /\d+/ && $preset == 192); |
| 9204 |
$preset = "extreme" if($preset =~ /\d+/ && $preset == 256); |
| 9205 |
$preset = "insane" if($preset =~ /\d+/ && $preset == 320); |
| 9206 |
$wpreset = $preset; |
| 9207 |
} |
| 9208 |
######################################################################## |
| 9209 |
# |
| 9210 |
# Check sshlist of remote machines and create a hash. |
| 9211 |
# |
| 9212 |
sub check_sshlist { |
| 9213 |
if(@psshlist) { |
| 9214 |
@sshlist = split(/,/, join(',', @psshlist)); |
| 9215 |
} |
| 9216 |
if(@pthreads) { |
| 9217 |
@threads = split(/,/, join(',', @pthreads)); |
| 9218 |
} |
| 9219 |
$wthreads = join(',', @threads); |
| 9220 |
if(@sshlist || $threads[0] > 1) { |
| 9221 |
$sshflag = 1; |
| 9222 |
$wsshlist = join(',', @sshlist); |
| 9223 |
# Create a hash with all machines and the number of encoding |
| 9224 |
# processes each machine is able to handle. |
| 9225 |
$sshlist{'local'} = $threads[0] if($local == 1); |
| 9226 |
my $threadscn = 1; |
| 9227 |
foreach (@sshlist) { |
| 9228 |
$threads[$threadscn] = 1 unless($threads[$threadscn]); |
| 9229 |
$sshlist{$_} = $threads[$threadscn]; |
| 9230 |
$threadscn++; |
| 9231 |
} |
| 9232 |
} |
| 9233 |
else { |
| 9234 |
$sshflag = 0; |
| 9235 |
} |
| 9236 |
} |
| 9237 |
######################################################################## |
| 9238 |
# |
| 9239 |
# Dispatcher for encoding on remote machines. If there are no .lock |
| 9240 |
# files, a ssh command will be passed, else the dispatcher waits until |
| 9241 |
# an already passed ssh command terminates and removes the lock file. |
| 9242 |
# The dispatcher checks all machines all 6 seconds until a machine is |
| 9243 |
# available. If option --scp is used, the dispatcher will not start an |
| 9244 |
# other job while copying. In this situation, it looks like nothing |
| 9245 |
# would happen, but it's only during scp. |
| 9246 |
# |
| 9247 |
sub enc_ssh { |
| 9248 |
my $machine; |
| 9249 |
my @codwav = (); |
| 9250 |
my $delwav = $_[0]; |
| 9251 |
my $enccom = $_[1]; |
| 9252 |
my $ripnam = $_[2]; |
| 9253 |
my $sepdir = $_[3]; |
| 9254 |
my $suffix = $_[4]; |
| 9255 |
my $shortnam = $_[5]; |
| 9256 |
my $enc_no = $_[6]; |
| 9257 |
my $old_wavdir = $wavdir; |
| 9258 |
my $old_sepdir = $sepdir; |
| 9259 |
my $old_ripnam = $ripnam; |
| 9260 |
my $esc_name; |
| 9261 |
my $esc_dir; |
| 9262 |
my $threadscn; |
| 9263 |
|
| 9264 |
$sshflag = 2; |
| 9265 |
while($sshflag == 2) { |
| 9266 |
# Start on the local machine first. |
| 9267 |
$threadscn = 1; |
| 9268 |
for($threadscn = 1; $threadscn <= $threads[0]; $threadscn++) { |
| 9269 |
if(! -r "$wavdir/local.lock_$threadscn") { |
| 9270 |
if($local == 1) { |
| 9271 |
$sshflag = 1; |
| 9272 |
$machine = "local"; |
| 9273 |
push @codwav, "$ripnam"; |
| 9274 |
} |
| 9275 |
} |
| 9276 |
else { |
| 9277 |
$sshflag = del_lock("$wavdir", "local.lock_$threadscn") |
| 9278 |
if($utftag == 0); |
| 9279 |
$sshflag = 1 if($sshflag == 0); |
| 9280 |
} |
| 9281 |
last if($sshflag == 1); |
| 9282 |
} |
| 9283 |
last if($sshflag == 1); |
| 9284 |
$threadscn = 1; |
| 9285 |
|
| 9286 |
foreach $_ (keys %sshlist) { |
| 9287 |
# Variable $machine will be needed below... and must be set. |
| 9288 |
$machine = $_; |
| 9289 |
next if(!defined $machine or $machine eq ""); |
| 9290 |
for($threadscn = 1; $threadscn <= $sshlist{$_}; $threadscn++) { |
| 9291 |
if(! -r "$wavdir/$_.lock_$threadscn") { |
| 9292 |
$sshflag = 1; |
| 9293 |
} |
| 9294 |
# Prepare array @codwav with all track names in, which are |
| 9295 |
# still in progress, i. e. either being ripped or encoded. |
| 9296 |
else { |
| 9297 |
open(LOCK, "$wavdir/$_.lock_$threadscn"); |
| 9298 |
my @locklines = <LOCK>; |
| 9299 |
close(LOCK); |
| 9300 |
if($utftag == 0) { |
| 9301 |
$sshflag = del_lock("$wavdir", "$_.lock_$threadscn"); |
| 9302 |
} |
| 9303 |
if($locklines[0]) { |
| 9304 |
chomp(my $locklines = $locklines[0]); |
| 9305 |
# Push track name into array only if not yet present. |
| 9306 |
my @presence = grep(/$locklines/, @codwav); |
| 9307 |
my $presence = $presence[0]; |
| 9308 |
push @codwav, "$locklines" if(!$presence); |
| 9309 |
} |
| 9310 |
} |
| 9311 |
last if($sshflag == 1); |
| 9312 |
} |
| 9313 |
$sshflag = 1 if($sshflag == 0); |
| 9314 |
last if($sshflag == 1); |
| 9315 |
} |
| 9316 |
last if($sshflag == 1); |
| 9317 |
sleep 3 if($sshflag != 1); |
| 9318 |
} |
| 9319 |
|
| 9320 |
$machine = "local" if(!defined $machine or $machine eq ""); |
| 9321 |
if(-r "$wavdir/enc.log" && $verbose >= 3) { |
| 9322 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 9323 |
print ENCLOG "...on machine $machine.\n" |
| 9324 |
if($#threads > 1 || $machine !~ /^local$/); |
| 9325 |
print ENCLOG "Executing scp command to $machine.\n" |
| 9326 |
if($scp && $machine !~ /^local$/); |
| 9327 |
close(ENCLOG); |
| 9328 |
} |
| 9329 |
elsif($verbose >= 3) { |
| 9330 |
print "...on machine $machine.\n" |
| 9331 |
if($#threads > 1 || $machine !~ /^local$/); |
| 9332 |
print ENCLOG "Executing scp command to $machine.\n" |
| 9333 |
if($scp && $machine !~ /^local$/); |
| 9334 |
} |
| 9335 |
|
| 9336 |
open(LOCKF, ">$wavdir/$machine.lock_$threadscn"); |
| 9337 |
print LOCKF "$sepdir/$ripnam.$suffix\n"; |
| 9338 |
close(LOCKF); |
| 9339 |
|
| 9340 |
# We need more quotes for the commands (faac,flac,lame,ogg) |
| 9341 |
# passed to the remote machine. NOTE: But now pay attention |
| 9342 |
# to single quotes in tags. Quote them outside of single quotes. |
| 9343 |
# TODO: Please tell me how to quote leading periods within ssh, thx. |
| 9344 |
if($machine !~ /^local$/) { |
| 9345 |
$enccom =~ s/'/'\\''/g; |
| 9346 |
$enccom = "ssh " . $machine . " '" . $enccom . "'"; |
| 9347 |
if($scp) { |
| 9348 |
# *Create* the directory: |
| 9349 |
# Quote the double quotes with a backslash when using ssh! |
| 9350 |
$sepdir = esc_char($sepdir, 0); |
| 9351 |
$wavdir = esc_char($wavdir, 0); |
| 9352 |
log_info("new-outputdir: $sepdir on $machine created."); |
| 9353 |
log_system("ssh $machine mkdir -p \\\"$sepdir\\\""); |
| 9354 |
log_info("new-outputdir: $wavdir on $machine created."); |
| 9355 |
log_system("ssh $machine mkdir -p \\\"$wavdir\\\""); |
| 9356 |
# *Copy* the File: |
| 9357 |
# Don't overwrite destination file, it will confuse running |
| 9358 |
# encoders! Do it the hard way! First get all lock-file-names |
| 9359 |
# of that machine. There will be at least one, created above! |
| 9360 |
opendir(LOCK, "$old_wavdir") or |
| 9361 |
print "Can not read in $old_wavdir: $!\n"; |
| 9362 |
my @boxes = grep {/^$machine/i} readdir(LOCK); |
| 9363 |
close(LOCK); |
| 9364 |
my $wavflag = 0; |
| 9365 |
# Open each lock-file, read the content, increase counter if |
| 9366 |
# the same wavname is found. Again: it will be found at least |
| 9367 |
# once. |
| 9368 |
foreach(@boxes) { |
| 9369 |
open(LOCKF, "$old_wavdir/$_") or |
| 9370 |
print "Can't open $old_wavdir/$_: $!\n"; |
| 9371 |
my @content = <LOCKF>; |
| 9372 |
close(LOCKF); |
| 9373 |
$wavflag++ if("@content" =~ /$ripnam/); |
| 9374 |
} |
| 9375 |
$ripnam = esc_char($ripnam, 0); |
| 9376 |
log_system("scp $wavdir/$ripnam.wav \\ |
| 9377 |
$machine:\"$wavdir/$ripnam.wav\" > /dev/null 2>&1") |
| 9378 |
if($wavflag <= 1); |
| 9379 |
} |
| 9380 |
} |
| 9381 |
else { |
| 9382 |
# On the local machine escape at least the dollar sign. |
| 9383 |
$ripnam =~ s/\$/\\\$/g; |
| 9384 |
$sepdir =~ s/\$/\\\$/g; |
| 9385 |
} |
| 9386 |
$enccom = $enccom . " > /dev/null" |
| 9387 |
unless($enc_no == 3 || $enc_no == 4); |
| 9388 |
# Because Lame comes with the "Can't get "TERM" environment string" |
| 9389 |
# error message, I decided to switch off all error output. This is |
| 9390 |
# not good, if ssh errors appear, then RipIT may hang with a message |
| 9391 |
# "Checking for lock files". If this happens, switch to verbosity 4 |
| 9392 |
# or higher and look what's going on. |
| 9393 |
$enccom = $enccom . " 2> /dev/null" |
| 9394 |
if($verbose <= 3 && ($enc_no != 3 || $enc_no != 4)); |
| 9395 |
if($machine !~ /^local$/ && $scp) { |
| 9396 |
if($suffix eq "mpc") { |
| 9397 |
$enccom = $enccom . " && \\ |
| 9398 |
scp $machine:\"$sepdir/$ripnam\_enc.$suffix\" \\ |
| 9399 |
$sepdir/$ripnam.$suffix > /dev/null 2>&1 && \\ |
| 9400 |
ssh $machine rm \"$sepdir/$ripnam\_enc.$suffix\" "; |
| 9401 |
} |
| 9402 |
elsif($suffix eq "wv") { |
| 9403 |
$enccom = $enccom . " && \\ |
| 9404 |
scp $machine:\"$sepdir/$ripnam\_enc.$suffix\" \\ |
| 9405 |
$sepdir/$ripnam.$suffix > /dev/null 2>&1 && \\ |
| 9406 |
ssh $machine rm \"$sepdir/$ripnam\_enc.$suffix\" "; |
| 9407 |
# TODO: |
| 9408 |
# Copy correction file! Not yet supported. |
| 9409 |
} |
| 9410 |
else { |
| 9411 |
$enccom = $enccom . " && \\ |
| 9412 |
scp $machine:\"$sepdir/$ripnam.$suffix\_enc\" \\ |
| 9413 |
$sepdir/$ripnam.$suffix > /dev/null 2>&1 && \\ |
| 9414 |
ssh $machine rm \"$sepdir/$ripnam.$suffix\_enc\" "; |
| 9415 |
} |
| 9416 |
} |
| 9417 |
# |
| 9418 |
if($suffix eq "mpc") { |
| 9419 |
$enccom = $enccom . " && \\ |
| 9420 |
mv \"$sepdir/$ripnam\_enc.$suffix\" \\ |
| 9421 |
\"$sepdir/$ripnam.$suffix\"" |
| 9422 |
if($machine eq "local" || ($machine !~ /^local$/ && !$scp)); |
| 9423 |
} |
| 9424 |
elsif($suffix eq "wv") { |
| 9425 |
$enccom = $enccom . " && \\ |
| 9426 |
mv \"$sepdir/$ripnam\_enc.$suffix\" \\ |
| 9427 |
\"$sepdir/$ripnam.$suffix\"" |
| 9428 |
if($machine eq "local" || ($machine !~ /^local$/ && !$scp)); |
| 9429 |
# TODO: |
| 9430 |
# Copy correction file! Not yet supported. |
| 9431 |
} |
| 9432 |
# This should not be used: |
| 9433 |
elsif($suffix eq "mp3" and $utftag == 0) { |
| 9434 |
# The command starts in Latin-1 and can not be enlarged with |
| 9435 |
# a string in local encoding probably different from Latin-1. |
| 9436 |
# The file name will never be found. |
| 9437 |
open(LOCKF, ">>$wavdir/$machine.lock_$threadscn"); |
| 9438 |
print LOCKF "short-in: /tmp/$shortnam-$enc_no.mp3\n"; |
| 9439 |
print LOCKF "full-out: $sepdir/$ripnam.$suffix\n"; |
| 9440 |
close(LOCKF); |
| 9441 |
$enccom = $enccom . " && \\ |
| 9442 |
mv \"/tmp/$shortnam-$enc_no.mp3_done\" \\ |
| 9443 |
\"/tmp/$shortnam-$enc_no.mp3\" &" |
| 9444 |
if($machine eq "local" || ($machine !~ /^local$/ && !$scp)); |
| 9445 |
} |
| 9446 |
else { |
| 9447 |
$enccom = $enccom . " && \\ |
| 9448 |
mv \"$sepdir/$ripnam.$suffix\_enc\" \\ |
| 9449 |
\"$sepdir/$ripnam.$suffix\"" |
| 9450 |
if($machine eq "local" || ($machine !~ /^local$/ && !$scp)); |
| 9451 |
} |
| 9452 |
$enccom = $enccom . " && \\ |
| 9453 |
rm \"$old_wavdir/$machine.lock_$threadscn\" &" |
| 9454 |
unless($suffix eq "mp3" and $utftag == 0); |
| 9455 |
|
| 9456 |
# A huge hack only not to interfere with the ripper output. |
| 9457 |
if($verbose >= 4) { |
| 9458 |
my $ripmsg = "The audio CD ripper reports: all done!"; |
| 9459 |
my $ripcomplete = 0; |
| 9460 |
if(-r "$wavdir/error.log") { |
| 9461 |
open(ERR, "$wavdir/error.log") |
| 9462 |
or print "Can not open file error.log!\n"; |
| 9463 |
my @errlines = <ERR>; |
| 9464 |
close(ERR); |
| 9465 |
my @ripcomplete = grep(/^$ripmsg/, @errlines); |
| 9466 |
$ripcomplete = 1 if(@ripcomplete); |
| 9467 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 9468 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 9469 |
print ENCLOG "\n\nExecuting command on machine $machine", |
| 9470 |
" and trying to encode \n$ripnam.$suffix\_enc.\n"; |
| 9471 |
close(ENCLOG); |
| 9472 |
} |
| 9473 |
else { |
| 9474 |
print "\nExecuting command on machine $machine and tring", |
| 9475 |
" to encode \n$ripnam.$suffix\_enc.\n"; |
| 9476 |
} |
| 9477 |
} |
| 9478 |
else { |
| 9479 |
print "\nExecuting command on machine $machine and tring", |
| 9480 |
" to encode \n$ripnam.$suffix\_enc.\n"; |
| 9481 |
} |
| 9482 |
} |
| 9483 |
log_system("$enccom"); |
| 9484 |
sleep 2; # Don't mess up with possible error-msgs from remote hosts. |
| 9485 |
|
| 9486 |
$wavdir = $old_wavdir; |
| 9487 |
$sepdir = $old_sepdir; |
| 9488 |
$ripnam = $old_ripnam; |
| 9489 |
# Delete the wav only if all encodings of this track are done! |
| 9490 |
# When the (last) encoding of a track started, its name is pushed |
| 9491 |
# into the array @delname. Then the first (oldest) entry of the same |
| 9492 |
# array (@delname) will be compared to the @codwav array. If this |
| 9493 |
# entry is still present in the codewav-array, nothing happens, else |
| 9494 |
# the wav file will be deleted and the track name shifted out of the |
| 9495 |
# @delname. |
| 9496 |
if($delwav == 1) { |
| 9497 |
push @delname, "$ripnam"; |
| 9498 |
my $delflag = 0; |
| 9499 |
while($delflag == 0) { |
| 9500 |
my $delname = $delname[0]; |
| 9501 |
my $deln = quotemeta($delname); |
| 9502 |
my @delwav = grep(/$deln/, @codwav); |
| 9503 |
if(!$delwav[0] && $#delname > 1) { |
| 9504 |
unlink("$wavdir/$delname.wav"); |
| 9505 |
log_info("File $wavdir/$delname.wav deleted."); |
| 9506 |
shift(@delname); |
| 9507 |
# Prevent endless loop if array is empty. |
| 9508 |
$delflag = 1 if(!$delwav[0]); |
| 9509 |
} |
| 9510 |
else { |
| 9511 |
$delflag = 1; |
| 9512 |
} |
| 9513 |
} |
| 9514 |
} |
| 9515 |
} |
| 9516 |
######################################################################## |
| 9517 |
# |
| 9518 |
# Delete wavs if sshlist was used. DONE: Improve code for following |
| 9519 |
# situation: if no .lock files are found, but the encoder did not yet |
| 9520 |
# finish, don't delete the wavs (i.e. wait for more lock files to |
| 9521 |
# appear). Do it only after a certain timeout with no .lock file. |
| 9522 |
# Furthermore if encoder subroutine checks again for |
| 9523 |
# ghost songs (in an extra loop), add an artificial ghost.lock file to |
| 9524 |
# ensure an additional timeout. Actually, this should not be necessary, |
| 9525 |
# as ghost songs are already present when last track has been ripped, |
| 9526 |
# but it may happen that check_wav quits before encoding of ghost |
| 9527 |
# songs started. |
| 9528 |
# |
| 9529 |
# We come here from sub finish_process. |
| 9530 |
# |
| 9531 |
sub check_wav { |
| 9532 |
my $waitflag = 0; |
| 9533 |
my $waitsecs = 3; |
| 9534 |
sleep $waitsecs; |
| 9535 |
my $time = sprintf "%02d:%02d:%02d:", |
| 9536 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 9537 |
print "\n$time Checking for remaining lock files in $wavdir.\n" |
| 9538 |
if($verbose > 1); |
| 9539 |
my @timeout = split(/:/, $time); |
| 9540 |
my $timeout = $timeout[1]; |
| 9541 |
while($waitflag < 4) { |
| 9542 |
sleep $waitsecs; |
| 9543 |
opendir(DIR, "$wavdir"); |
| 9544 |
my @locks = readdir(DIR); |
| 9545 |
closedir(DIR); |
| 9546 |
@locks = grep { /\.lock_\d+$/ } @locks; |
| 9547 |
foreach (@locks) { |
| 9548 |
$waitflag = del_lock("$wavdir", "$_") |
| 9549 |
if($utftag == 0); |
| 9550 |
} |
| 9551 |
$waitflag++ if(! @locks); |
| 9552 |
$waitsecs = $waitflag = 1 if(@locks); |
| 9553 |
$waitsecs += 1 if(defined $pmerge and $pmerge ne ""); |
| 9554 |
$waitsecs += 1 if(defined $ghost and $ghost > 0); |
| 9555 |
$waitsecs += $#coder if($waitflag > 1); |
| 9556 |
if(-r "$wavdir/ghost.lock") { |
| 9557 |
sleep $waitsecs; |
| 9558 |
unlink("$wavdir/ghost.lock"); |
| 9559 |
$waitsecs = $waitflag = 1; |
| 9560 |
} |
| 9561 |
my $time = sprintf "%02d:%02d:%02d:", |
| 9562 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 9563 |
my @timeout = split(/:/, $time); |
| 9564 |
my $timecnt = $timeout[1]; |
| 9565 |
$timecnt += 60 if($timecnt < $timeout); |
| 9566 |
if($timecnt - $timeout > $#tracklist + 6) { |
| 9567 |
print "\n$time Something went wrong with encoder, lock files ", |
| 9568 |
"are locked for more than an hour.\nGiving up and ", |
| 9569 |
"deleting all lock files.\n" if($verbose > 0); |
| 9570 |
open(ERO,">>$wavdir/error.log") |
| 9571 |
or print "Can not append to file ", |
| 9572 |
"\"$wavdir/error.log\"!\n"; |
| 9573 |
foreach (@locks) { |
| 9574 |
open(LOCK, "$wavdir/$_"); |
| 9575 |
my @locklines = <LOCK>; |
| 9576 |
close(LOCK); |
| 9577 |
print ERO "Track on CD $cd{artist} - $cd{title} ", |
| 9578 |
"failed!\n"; |
| 9579 |
print ERO "@locklines\n"; |
| 9580 |
unlink("$wavdir/$_"); |
| 9581 |
} |
| 9582 |
close(ERO); |
| 9583 |
} |
| 9584 |
} |
| 9585 |
del_wav if($wav == 0); |
| 9586 |
if($scp) { |
| 9587 |
foreach my $machine (keys %sshlist) { |
| 9588 |
next if($machine =~ /local/); |
| 9589 |
foreach my $deldir (@sepdir, $wavdir) { |
| 9590 |
my $dd = $deldir; |
| 9591 |
$dd = esc_char($dd, 0); |
| 9592 |
log_system("ssh $machine rm \"$dd/*.wav\" 2> /dev/null"); |
| 9593 |
log_system("ssh $machine rmdir -p \"$dd\" 2> /dev/null"); |
| 9594 |
} |
| 9595 |
} |
| 9596 |
} |
| 9597 |
} |
| 9598 |
######################################################################## |
| 9599 |
# |
| 9600 |
# Delete wavs if sshlist was used. |
| 9601 |
# |
| 9602 |
sub del_wav { |
| 9603 |
printf "\n%02d:%02d:%02d: ", |
| 9604 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 9605 |
if(-d "$wavdir" && $verbose > 1); |
| 9606 |
print "Searching existing wav files to be deleted.\n" |
| 9607 |
if(-d "$wavdir" && $verbose > 1); |
| 9608 |
if(-d "$wavdir") { |
| 9609 |
opendir(DIR, "$wavdir"); |
| 9610 |
my @wavs = readdir(DIR); |
| 9611 |
closedir(DIR); |
| 9612 |
@wavs = grep { /\.wav$/ } @wavs; |
| 9613 |
foreach (@wavs) { |
| 9614 |
unlink("$wavdir/$_"); |
| 9615 |
log_info("File $wavdir/$_ deleted."); |
| 9616 |
} |
| 9617 |
} |
| 9618 |
} |
| 9619 |
######################################################################## |
| 9620 |
# |
| 9621 |
# LCDproc subroutines, all credits to Max Kaesbauer. For comments and |
| 9622 |
# questions contact max [dot] kaesbauer [at] gmail [dot] com. |
| 9623 |
# |
| 9624 |
|
| 9625 |
# print |
| 9626 |
|
| 9627 |
sub plcd { |
| 9628 |
my ($data) = @_; |
| 9629 |
print $lcdproc $data."\n"; |
| 9630 |
my $res = <$lcdproc>; |
| 9631 |
} |
| 9632 |
|
| 9633 |
# update |
| 9634 |
|
| 9635 |
sub ulcd { |
| 9636 |
if($lcdoline1 ne $lcdline1) { |
| 9637 |
$lcdoline1 = $lcdline1; |
| 9638 |
plcd("widget_set ripitlcd line1 1 2 {$lcdline1}"); |
| 9639 |
} |
| 9640 |
if($lcdoline2 ne $lcdline2) { |
| 9641 |
$lcdoline2 = $lcdline2; |
| 9642 |
plcd("widget_set ripitlcd line2 1 3 {$lcdline2}"); |
| 9643 |
} |
| 9644 |
if($lcdoline3 ne $lcdline3) { |
| 9645 |
$lcdoline3 = $lcdline3; |
| 9646 |
plcd("widget_set ripitlcd line3 1 4 {$lcdline3}"); |
| 9647 |
} |
| 9648 |
} |
| 9649 |
|
| 9650 |
# init |
| 9651 |
|
| 9652 |
sub init_lcd { |
| 9653 |
$lcdproc = IO::Socket::INET->new( |
| 9654 |
Proto => "tcp", |
| 9655 |
PeerAddr => $lcdhost, |
| 9656 |
PeerPort => $lcdport, |
| 9657 |
) || die "Can not connect to LCDproc port\n"; |
| 9658 |
$lcdproc->autoflush(1); |
| 9659 |
sleep 1; |
| 9660 |
|
| 9661 |
print $lcdproc "Hello\n"; |
| 9662 |
my @lcd_specs = split(/ /,<$lcdproc>); |
| 9663 |
my %screen; |
| 9664 |
|
| 9665 |
$screen{wid} = $lcd_specs[7]; |
| 9666 |
$screen{hgt} = $lcd_specs[9]; |
| 9667 |
$screen{cellwid} = $lcd_specs[11]; |
| 9668 |
$screen{cellhgt} = $lcd_specs[13]; |
| 9669 |
|
| 9670 |
$screen{pixwid} = $screen{wid}*$screen{cellwid}; |
| 9671 |
$screen{pixhgt} = $screen{hgt}*$screen{cellhgt}; |
| 9672 |
|
| 9673 |
fcntl($lcdproc, F_SETFL, O_NONBLOCK); |
| 9674 |
|
| 9675 |
plcd("client_set name {ripit.pl}"); |
| 9676 |
plcd("screen_add ripitlcd"); |
| 9677 |
plcd("screen_set ripitlcd name {ripitlcd}"); |
| 9678 |
|
| 9679 |
plcd("widget_add ripitlcd title title"); |
| 9680 |
plcd("widget_set ripitlcd title {RipIT $version}"); |
| 9681 |
|
| 9682 |
plcd("widget_add ripitlcd line1 string"); |
| 9683 |
plcd("widget_add ripitlcd line2 string"); |
| 9684 |
plcd("widget_add ripitlcd line3 string"); |
| 9685 |
} |
| 9686 |
######################################################################## |
| 9687 |
# |
| 9688 |
# Read the CDDB on the local machine. |
| 9689 |
# |
| 9690 |
sub read_entry { |
| 9691 |
my ($album, $artist, $totals, $trackno, $asin, $asinurl, $barcode, |
| 9692 |
$catalog, $dgid, $language, $reldate, $mbreid); |
| 9693 |
my @rawlines = (); |
| 9694 |
my $logfile = $_[0]; |
| 9695 |
open(LOG, "<$logfile") || print "Can't open $logfile\n"; |
| 9696 |
my @cddblines = <LOG>; |
| 9697 |
close(LOG); |
| 9698 |
%cd = (); |
| 9699 |
# Note that long lines may be split into several lines |
| 9700 |
# all starting with the same keyword, e.g. DTITLE. |
| 9701 |
# Note, discno is not yet reseted anymore. There will be some |
| 9702 |
# interference. |
| 9703 |
if($_[1] eq "musicbrainz" or $multi == 1) { |
| 9704 |
chomp($artist = join('', grep(s/^artist:\s//i, @cddblines))); |
| 9705 |
chomp($album = join('', grep(s/^album:\s//i, @cddblines))); |
| 9706 |
chomp($categ = join('', grep(s/^category:\s//i, @cddblines))); |
| 9707 |
chomp($genre = join('', grep(s/^genre:\s//i, @cddblines))); |
| 9708 |
chomp($year = join('', grep(s/^year:\s//i, @cddblines))); |
| 9709 |
chomp($cddbid = join('', grep(s/^cddbid:\s//i, @cddblines))); |
| 9710 |
chomp($discid = join('', grep(s/^discid:\s//i, @cddblines))); |
| 9711 |
chomp($mbreid = join('', grep(s/^mbreid:\s//i, @cddblines))); |
| 9712 |
chomp($asin = join('', grep(s/^asin:\s//i, @cddblines))); |
| 9713 |
chomp($asinurl = join('', grep(s/^asinurl:\s//i, @cddblines))); |
| 9714 |
chomp($dgid = join('', grep(s/^discogs:\s//i, @cddblines))); |
| 9715 |
chomp($barcode = join('', grep(s/^barcode:\s//i, @cddblines))); |
| 9716 |
chomp($catalog = join('', grep(s/^catalog:\s//i, @cddblines))); |
| 9717 |
chomp($language = join('', grep(s/^language:\s//i, @cddblines))); |
| 9718 |
chomp($reldate = join('', grep(s/^reldate:\s//i, @cddblines))); |
| 9719 |
chomp($trackno = join('', grep(s/^trackno:\s//i, @cddblines))); |
| 9720 |
chomp($totals = join('', grep(s/^totaltime:\s//i, @cddblines))); |
| 9721 |
chomp($discno = join('', grep(s/^disc-number:\s//i, @cddblines))); |
| 9722 |
chomp($trackoffset = join('', grep(s/^trackoff:\s//i, @cddblines))); |
| 9723 |
$trackoffset = 0 unless($trackoffset =~ /^\d+$/); |
| 9724 |
$trackno = $_[2] unless($trackno); |
| 9725 |
|
| 9726 |
push(@rawlines, "# xmcd CD database generated by RipIT\n#\n", |
| 9727 |
"# Track frame offsets:\n"); |
| 9728 |
my $i = 0; |
| 9729 |
foreach(@framelist) { |
| 9730 |
push(@rawlines, "#\t$_\n") if($i < $#framelist); |
| 9731 |
$i++; |
| 9732 |
} |
| 9733 |
# In case $rip == 0 disc length is given in seconds only, could |
| 9734 |
# be changed there, but for now do it this way when regular |
| 9735 |
# disc length is in minutes:seconds format. |
| 9736 |
if(defined $totals && $totals =~ /:/) { |
| 9737 |
my @totals = split(/:/, $totals); |
| 9738 |
$totals = $totals[0] * 60 + $totals[1]; |
| 9739 |
} |
| 9740 |
push(@rawlines, "#\n# Disc length: $totals seconds\n"); |
| 9741 |
push(@rawlines, "# Revision: 0\n"); |
| 9742 |
push(@rawlines, "# Submitted via: RipIT $version\n#\n"); |
| 9743 |
push(@rawlines, "DISCID=$cddbid\n"); |
| 9744 |
push(@rawlines, "DTITLE=$artist / $album\n"); |
| 9745 |
push(@rawlines, "DYEAR=$year\n"); |
| 9746 |
push(@rawlines, "DGENRE=$genre\n"); |
| 9747 |
} |
| 9748 |
else { |
| 9749 |
$cd{raw} = \@cddblines; |
| 9750 |
# In case we want to know the toc read it out here: |
| 9751 |
foreach (@cddblines) { |
| 9752 |
chomp; |
| 9753 |
my $tocnumber = $_; |
| 9754 |
$tocnumber =~ s/#\s*Disc\slength:\s*/# /; |
| 9755 |
next unless($tocnumber =~ /^#\s*\d+/); |
| 9756 |
$tocnumber =~ s/#\s*//g; |
| 9757 |
$tocnumber =~ s/\s*seconds.*$//; |
| 9758 |
push(@framelist, $tocnumber); |
| 9759 |
} |
| 9760 |
# Sometimes the archive entry might be corrupted (ripits fault?); |
| 9761 |
# do not fail in this case. |
| 9762 |
$framelist[$#framelist] *= 75 if($framelist[0]); |
| 9763 |
chomp($artist = join(' x/x ', grep(s/^DTITLE=//g, @cddblines))); |
| 9764 |
$artist =~ s/[\015]//g; |
| 9765 |
$artist =~ s/\n\sx\/x\s//g; |
| 9766 |
$artist =~ s/\sx\/x\s//g; |
| 9767 |
# Artist is just the first part before first occurrence of |
| 9768 |
# the slash (/), album gets all the rest! |
| 9769 |
my @disctitle = split(/\s\/\s/, $artist); |
| 9770 |
$artist = shift(@disctitle); |
| 9771 |
$album = join(' / ', @disctitle); |
| 9772 |
chomp $artist; |
| 9773 |
chomp $album; |
| 9774 |
$categ = $_[1]; |
| 9775 |
unless($genre) { |
| 9776 |
chomp($genre = join('', grep(s/^DGENRE=//, @cddblines))); |
| 9777 |
$genre =~ s/[\015]//g; |
| 9778 |
} |
| 9779 |
unless($year) { |
| 9780 |
chomp($year = join('', grep(s/^DYEAR=//, @cddblines))); |
| 9781 |
$year =~ s/[\015]//g; |
| 9782 |
} |
| 9783 |
unless($discid) { |
| 9784 |
chomp($discid = join('', grep(s/^DISCID=//, @cddblines))); |
| 9785 |
$discid =~ s/[\015]//g; |
| 9786 |
$discid = "" unless($discid =~ /\-$/ && length($discid) == 28); |
| 9787 |
} |
| 9788 |
if(defined $discno and $discno < 2) { |
| 9789 |
chomp($discno = join('', grep(s/^DISCNO=//, @cddblines))); |
| 9790 |
$discno =~ s/[\015]//g; |
| 9791 |
} |
| 9792 |
unless($dgid) { |
| 9793 |
chomp($dgid = join('', grep(s/^DGID=//, @cddblines))); |
| 9794 |
$dgid =~ s/[\015]//g; |
| 9795 |
$dgid = "" if($dgid =~ /\D/); |
| 9796 |
} |
| 9797 |
unless($mbreid) { |
| 9798 |
chomp($mbreid = join('', grep(s/^MBREID=//, @cddblines))); |
| 9799 |
$mbreid =~ s/[\015]//g; |
| 9800 |
$mbreid = "" if($mbreid =~ /\-$/ or length($mbreid) <= 28); |
| 9801 |
} |
| 9802 |
$trackno = $_[2]; |
| 9803 |
} |
| 9804 |
$cd{artist} = $artist; |
| 9805 |
$cd{title} = $album; |
| 9806 |
$cd{cat} = $categ; |
| 9807 |
$cd{genre} = $genre; |
| 9808 |
$cd{id} = $cddbid; |
| 9809 |
$cd{discid} = $discid; |
| 9810 |
$cd{mbreid} = $mbreid; |
| 9811 |
$cd{asin} = $asin; |
| 9812 |
$cd{asinurl} = $asinurl; |
| 9813 |
$cd{dgid} = $dgid; |
| 9814 |
$cd{year} = $year; |
| 9815 |
$cd{barcode} = $barcode; |
| 9816 |
$cd{catalog} = $catalog; |
| 9817 |
$cd{language} = $language; |
| 9818 |
$cd{reldate} = $reldate; |
| 9819 |
$cd{discno} = $discno if(defined $discno and $discno > 0); |
| 9820 |
|
| 9821 |
my $h = 0; # Array counter |
| 9822 |
my $i = $trackoffset + 1; # Track counter for display |
| 9823 |
my $j = $trackoffset; # Track name counter |
| 9824 |
# Problem: if the local file has been saved with a trackoffset, |
| 9825 |
# counter $i will work. But in case it has been saved without and |
| 9826 |
# operator wants to rip with a trackoffset, $j must be reset to 0. |
| 9827 |
# Hm... shall we test tracknumbers in case trackoffset is larger than |
| 9828 |
# 0 if tracknumbers start at TTITLE0= or not? If not suppose local |
| 9829 |
# CDDB file is actual. Let's test and alter the track name counter. |
| 9830 |
if($trackoffset > 0 or $discno > 0) { |
| 9831 |
my @trackcn = grep(/^TTITLE\d+=/, @cddblines); |
| 9832 |
@trackcn = grep(s/^TTITLE//, @trackcn); |
| 9833 |
@trackcn = grep(s/=.*//, @trackcn); |
| 9834 |
if(defined $trackcn[0] and $trackcn[0] == 0) { |
| 9835 |
$j = 0; |
| 9836 |
} |
| 9837 |
elsif(defined $trackcn[0] and $trackcn[0] > 0) { |
| 9838 |
$j = $trackcn[0]; |
| 9839 |
$i += $j; |
| 9840 |
$trackoffset = $j if($trackoffset == 0); |
| 9841 |
} |
| 9842 |
} |
| 9843 |
|
| 9844 |
while($i <= $trackno + $trackoffset) { |
| 9845 |
my @track = (); |
| 9846 |
@track = grep(s/^TTITLE$j=//, @cddblines) if($multi == 0); |
| 9847 |
@track = grep(s/^track\s$i:\s//i, @cddblines) |
| 9848 |
if($_[1] eq "musicbrainz" or $multi == 1); |
| 9849 |
my $track = join(' ', @track); |
| 9850 |
$track =~ s/[\015]//g; |
| 9851 |
$track =~ s/\n\s\/\s//g; |
| 9852 |
chomp $track; |
| 9853 |
$cd{track}[$h] = $track; |
| 9854 |
push(@rawlines, "TTITLE$j=$track\n") |
| 9855 |
if($_[1] eq "musicbrainz" or $multi == 1); |
| 9856 |
$h++; |
| 9857 |
$i++; |
| 9858 |
$j++; |
| 9859 |
} |
| 9860 |
|
| 9861 |
if($_[1] eq "musicbrainz" or $multi == 1) { |
| 9862 |
push(@rawlines, "EXTD=\n"); |
| 9863 |
$i = 1; |
| 9864 |
$j = 0; |
| 9865 |
$j += $trackoffset if($trackoffset > 0); |
| 9866 |
while($i <= $trackno) { |
| 9867 |
push(@rawlines, "EXTT$j=\n"); |
| 9868 |
$i++; |
| 9869 |
$j++; |
| 9870 |
} |
| 9871 |
push(@rawlines, "PLAYORDER=\n"); |
| 9872 |
push(@rawlines, "CDINDEX=" . $cd{discid} . "\n") if($cd{discid}); |
| 9873 |
push(@rawlines, "MBREID=" . $cd{mbreid} . "\n") if($cd{mbreid}); |
| 9874 |
push(@rawlines, "ASIN=" . $cd{asin} . "\n") if($cd{asin}); |
| 9875 |
push(@rawlines, "ASINURL=" . $cd{asinurl} . "\n") if($cd{asinurl}); |
| 9876 |
push(@rawlines, "DGID=" . $cd{dgid} . "\n") if($cd{dgid}); |
| 9877 |
push(@rawlines, "BARCODE=" . $cd{barcode} . "\n") if($cd{barcode}); |
| 9878 |
push(@rawlines, "CATALOG=" . $cd{catalog} . "\n") if($cd{catalog}); |
| 9879 |
push(@rawlines, "RELDAT=" . $cd{reldate} . "\n") if($cd{reldate}); |
| 9880 |
push(@rawlines, "LANG=" . $cd{language} . "\n") if($cd{language}); |
| 9881 |
push(@rawlines, "DISCNO=" . $cd{discno} . "\n") if($cd{discno}); |
| 9882 |
|
| 9883 |
$cd{raw} = \@rawlines; |
| 9884 |
} |
| 9885 |
return; |
| 9886 |
} |
| 9887 |
######################################################################## |
| 9888 |
# |
| 9889 |
# Delete error.log if there is no track-comment in! |
| 9890 |
# |
| 9891 |
sub del_erlog { |
| 9892 |
open(ERR, "$wavdir/error.log") |
| 9893 |
or print "Fatal: $wavdir/error.log disappeared!\n"; |
| 9894 |
my @errlines = <ERR>; |
| 9895 |
close(ERR); |
| 9896 |
|
| 9897 |
my @covs = grep(s/^flac-cover: //, @errlines) if(defined $coverpath); |
| 9898 |
chomp($_) foreach(@covs); |
| 9899 |
# Add missing coverart and tags to files previously not done because |
| 9900 |
# of option thread or sshlist. |
| 9901 |
my @md5tracks = grep(s/^md5: //, @errlines) if($md5sum == 1); |
| 9902 |
@mp3tags = grep(s/^mp3tags: //, @errlines); |
| 9903 |
if(@md5tracks) { |
| 9904 |
foreach (@md5tracks) { |
| 9905 |
my ($sepdir, $donetrack) = split(/;#;/, $_); |
| 9906 |
chomp $donetrack; |
| 9907 |
# Add special mp3 tags. |
| 9908 |
if(@mp3tags && $donetrack =~ /mp3$/) { |
| 9909 |
mp3_tags("$sepdir/$donetrack") |
| 9910 |
if(defined $mp3tags[0] && $mp3tags[0] !~ /^\s*$/); |
| 9911 |
} |
| 9912 |
# Add coverart if it is a mp3 or ogg. |
| 9913 |
if($donetrack =~ /mp3$/ && -f "$coverpath" && -s "$coverpath") { |
| 9914 |
mp3_cover("$sepdir/$donetrack", "$coverpath"); |
| 9915 |
} |
| 9916 |
elsif($donetrack =~ /ogg$/ && -f "$coverpath" && -s "$coverpath") { |
| 9917 |
ogg_cover("$sepdir/$donetrack", "$coverpath"); |
| 9918 |
} |
| 9919 |
} |
| 9920 |
} |
| 9921 |
# Add album-gain once all files are present. |
| 9922 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 9923 |
if($verbose > 2 && ($mp3gain || $vorbgain || $flacgain || $aacgain || $mpcgain || $wvgain)) { |
| 9924 |
printf "\n%02d:%02d:%02d: ", |
| 9925 |
sub {$_[2], $_[1], $_[0]}->(localtime) if($verbose > 2); |
| 9926 |
print "Starting with album gain detection for $suffix[$c]-files.\n"; |
| 9927 |
} |
| 9928 |
if($mp3gain && $suffix[$c] =~ /mp3/) { |
| 9929 |
log_system("$mp3gain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9930 |
} |
| 9931 |
elsif($vorbgain && $suffix[$c] =~ /ogg/) { |
| 9932 |
log_system("$vorbgain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9933 |
} |
| 9934 |
elsif($flacgain && $suffix[$c] =~ /flac/) { |
| 9935 |
log_system("$flacgain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9936 |
} |
| 9937 |
elsif($aacgain && $suffix[$c] =~ /m4a|mp4/) { |
| 9938 |
log_system("$aacgain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9939 |
} |
| 9940 |
elsif($mpcgain && $suffix[$c] =~ /mpc/) { |
| 9941 |
log_system("$mpcgain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9942 |
} |
| 9943 |
elsif($wvgain && $suffix[$c] =~ /wv/) { |
| 9944 |
log_system("$wvgain \"$sepdir[$c]/\"*.$suffix[$c]"); |
| 9945 |
} |
| 9946 |
else { |
| 9947 |
print "\nNo album gain command found for $suffix[$c].\n" |
| 9948 |
if($verbose > 5 && ($mp3gain || $vorbgain || $flacgain || $aacgain || $mpcgain || $wvgain)); |
| 9949 |
} |
| 9950 |
} |
| 9951 |
# Once all tagging is done, continue with md5sum calculation. |
| 9952 |
printf "\n\n%02d:%02d:%02d: ", |
| 9953 |
sub {$_[2], $_[1], $_[0]}->(localtime) |
| 9954 |
if($verbose > 2 && $md5sum == 1); |
| 9955 |
print "Starting with md5sum calculation.\n" |
| 9956 |
if($verbose > 2 && $md5sum == 1); |
| 9957 |
# Final sound file stuff |
| 9958 |
my $album = clean_all($album_utf8); |
| 9959 |
my $riptrackname; |
| 9960 |
|
| 9961 |
# New parameters for tracktemplate used for file names only, i.e. |
| 9962 |
# less verbose than the corresponding tags $artistag and tracktag. |
| 9963 |
my $trackartist; |
| 9964 |
my $artistag; |
| 9965 |
my $tracktitle; |
| 9966 |
|
| 9967 |
my ($delimiter, $dummy) = check_va(0) if($vatag > 0); |
| 9968 |
my $delim = ""; |
| 9969 |
if(defined $delimiter) { |
| 9970 |
my $delim = quotemeta($delimiter); |
| 9971 |
$vatag = 0 if($delim eq ""); |
| 9972 |
} |
| 9973 |
|
| 9974 |
# Array @tracksel has not yet been updated in case ghost songs are |
| 9975 |
# found. |
| 9976 |
my $orig_size = $#tracksel + 1; # Is this a bug? Version 4.0.0 fails |
| 9977 |
# if only on track with ghost song is to be ripped... |
| 9978 |
# The above line does not work if a track selection has been used... |
| 9979 |
foreach(@tracksel) { |
| 9980 |
# Don't alter array @tracksel, rather the original not the |
| 9981 |
# modified one. |
| 9982 |
my $tn = $_; |
| 9983 |
# Update array @tracksel if ghost songs have been detected, but |
| 9984 |
# only once. |
| 9985 |
if($ghost == 1 && $tn == $tracksel[$#tracksel] |
| 9986 |
&& -r "$wavdir/ghost.log") { |
| 9987 |
open(GHOST, "<$wavdir/ghost.log") |
| 9988 |
or print "Can not read file ghost.log!\n"; |
| 9989 |
my @errlines = <GHOST>; |
| 9990 |
close(GHOST); |
| 9991 |
my @selines = grep(s/^Array seltrack: //, @errlines); |
| 9992 |
@tracksel = split(/ /, $selines[$#selines]); |
| 9993 |
chomp($_) foreach(@tracksel); |
| 9994 |
$ghost = 2; |
| 9995 |
} |
| 9996 |
# Did I need this with tracks split into several parts? |
| 9997 |
# if($ghost == 2) { |
| 9998 |
# $tn = $orig_size++; |
| 9999 |
# } |
| 10000 |
my $riptracktag = $tracktags[$tn - 1]; |
| 10001 |
$riptracktag = $tracktags[$tn] if($hiddenflag == 1); |
| 10002 |
# Split the tracktag into its artist part and track part if |
| 10003 |
# VA style is used, no messages to be printed. |
| 10004 |
if($va_flag > 0 && $riptracktag =~ /$delim/) { |
| 10005 |
($artistag, $riptracktag) = split_tags($riptracktag, $delim); |
| 10006 |
} |
| 10007 |
# Actually, we do not need the "full" tags, only names for files. |
| 10008 |
$artistag = clean_all($artist_utf8) unless(defined $artistag); |
| 10009 |
$trackartist = clean_all($artistag); |
| 10010 |
$trackartist = clean_name($trackartist); |
| 10011 |
$trackartist = clean_chars($trackartist); |
| 10012 |
$tracktitle = clean_all($riptracktag); |
| 10013 |
$tracktitle = clean_name($tracktitle); |
| 10014 |
$tracktitle = clean_chars($tracktitle); |
| 10015 |
$trackartist =~ s/ /_/g if($underscore == 1); |
| 10016 |
$tracktitle =~ s/ /_/g if($underscore == 1); |
| 10017 |
|
| 10018 |
# Note, here we work on the track number coming from @tracksel. |
| 10019 |
if($rip == 1) { |
| 10020 |
$riptrackname = get_trackname($_, $tracklist[$tn - 1], 0, $trackartist, $tracktitle); |
| 10021 |
$riptrackname = get_trackname($_, $tracklist[$tn], 0, $trackartist, $tracktitle) |
| 10022 |
if($hiddenflag == 1); |
| 10023 |
} |
| 10024 |
# Tracklist already has a track counter as prefix in case we |
| 10025 |
# re-encode... this will break trackoffset... |
| 10026 |
# |
| 10027 |
else { |
| 10028 |
# $riptrackname = $tracklist[$_ - 1]; |
| 10029 |
# $riptrackname = $tracklist[$_] if($hiddenflag == 1); |
| 10030 |
$riptrackname = get_trackname($tn, $tracktitle, 0, $trackartist, $tracktitle); |
| 10031 |
# Just to make things clear. |
| 10032 |
$riptrackname = get_trackname($tn, $tracktitle, 0, $trackartist, $tracktitle) if($hiddenflag == 1); |
| 10033 |
} |
| 10034 |
$riptrackname = $album if($book == 1 or $cdcue > 0); |
| 10035 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 10036 |
chmod oct($fpermission), |
| 10037 |
"$sepdir[$c]/$riptrackname.$suffix[$c]" |
| 10038 |
if($fpermission); |
| 10039 |
# Generate md5sum of files. |
| 10040 |
if($md5sum == 1) { |
| 10041 |
if(-r "$sepdir[$c]/$riptrackname.$suffix[$c]") { |
| 10042 |
md5_sum("$sepdir[$c]", |
| 10043 |
"$riptrackname.$suffix[$c]", 1); |
| 10044 |
} |
| 10045 |
else { |
| 10046 |
print "Error, no file \"$sepdir[$c]/$riptrackname.$suffix[$c]\" found.\n" if($verbose > 0); |
| 10047 |
} |
| 10048 |
} |
| 10049 |
} |
| 10050 |
last if($book > 0 || $cdcue > 0); |
| 10051 |
} |
| 10052 |
|
| 10053 |
# Change file permissions for md5 files. |
| 10054 |
if($fpermission && $md5sum == 1){ |
| 10055 |
foreach(@sepdir, $wavdir) { |
| 10056 |
opendir(MD5, "$_") or print "Can not read in $_: $!\n"; |
| 10057 |
my @md5files = grep {/\.md5$/i} readdir(MD5); |
| 10058 |
close(MD5); |
| 10059 |
# Security check: if encoder not installed, but directory |
| 10060 |
# created, then no md5sum-file will be found and the |
| 10061 |
# directory instead of the file gets the permissions. |
| 10062 |
next unless($md5files[0]); |
| 10063 |
if($_ eq $wavdir) { |
| 10064 |
chmod oct($fpermission), "$_/$md5files[0]" if($wav == 1); |
| 10065 |
} |
| 10066 |
else { |
| 10067 |
chmod oct($fpermission), "$_/$md5files[0]"; |
| 10068 |
} |
| 10069 |
} |
| 10070 |
} |
| 10071 |
chmod oct($fpermission), "$wavdir/cd.toc" if($fpermission); |
| 10072 |
my @ulink = grep(/^Track /, @errlines); |
| 10073 |
if(!@ulink && $multi == 0) { |
| 10074 |
unlink("$wavdir/error.log"); |
| 10075 |
} |
| 10076 |
elsif($fpermission) { |
| 10077 |
chmod oct($fpermission), "$wavdir/error.log"; |
| 10078 |
} |
| 10079 |
if($ghost > 0 && -r "$wavdir/ghost.log") { |
| 10080 |
unlink("$wavdir/ghost.log"); |
| 10081 |
} |
| 10082 |
if(defined $coverpath && defined $covs[0] && -f "$covs[0]") { |
| 10083 |
unlink("$covs[0]"); |
| 10084 |
} |
| 10085 |
if($wav == 0 && $wavdir ne $homedir) { |
| 10086 |
# I don't like the -p option. |
| 10087 |
log_system("rmdir -p \"$wavdir\" 2> /dev/null"); |
| 10088 |
} |
| 10089 |
} |
| 10090 |
######################################################################## |
| 10091 |
# |
| 10092 |
# Escape special characters when using scp. |
| 10093 |
# |
| 10094 |
sub esc_char { |
| 10095 |
$_[0] =~ s,\\,x,g if($_[1] == 0); |
| 10096 |
$_[0] =~ s/\(/\\\(/g; |
| 10097 |
$_[0] =~ s/\)/\\\)/g; |
| 10098 |
$_[0] =~ s/\[/\\\[/g; |
| 10099 |
$_[0] =~ s/\]/\\\]/g; |
| 10100 |
$_[0] =~ s/\&/\\\&/g; |
| 10101 |
$_[0] =~ s/\!/\\\!/g; |
| 10102 |
$_[0] =~ s/\?/\\\?/g; |
| 10103 |
$_[0] =~ s/\'/\\\'/g; |
| 10104 |
$_[0] =~ s/\$/\\\$/g; |
| 10105 |
$_[0] =~ s/ /\\ /g if($_[1] == 0); |
| 10106 |
return $_[0]; |
| 10107 |
} |
| 10108 |
######################################################################## |
| 10109 |
# |
| 10110 |
# Calculate how much time ripping and encoding needed. |
| 10111 |
# |
| 10112 |
sub cal_times { |
| 10113 |
my $encend = `date \'+%R\'`; |
| 10114 |
chomp $encend; |
| 10115 |
# Read times from the file $wavdir/error.log. |
| 10116 |
open(ERR, "$wavdir/error.log") |
| 10117 |
or print "Can't calculate time, $wavdir/error.log disappeared!\n"; |
| 10118 |
my @errlines = <ERR>; |
| 10119 |
close(ERR); |
| 10120 |
my @enctime = grep(s/^Encoding needed //, @errlines); |
| 10121 |
my @ripstart = grep(s/^Ripping started: //, @errlines); |
| 10122 |
my @ripend = grep(s/^Ripping ended: //, @errlines); |
| 10123 |
# Read info about trimmed tracks in file $wavdir/ghost.log. |
| 10124 |
if(-r "$wavdir/ghost.log") { |
| 10125 |
open(ERR, "$wavdir/ghost.log") |
| 10126 |
or print "Can't read $wavdir/ghost.log.\n"; |
| 10127 |
@errlines = <ERR>; |
| 10128 |
close(ERR); |
| 10129 |
} |
| 10130 |
chomp(my $blanktrks = join(', ', grep(s/^Blankflag = //, @errlines))); |
| 10131 |
chomp(my $ghostrks = join(', ', grep(s/^Ghostflag = //, @errlines))); |
| 10132 |
chomp(my $splitrks = join(', ', grep(s/^Splitflag = //, @errlines))); |
| 10133 |
$blanktrks =~ s/\n//g; |
| 10134 |
$ghostrks =~ s/\n//g; |
| 10135 |
$splitrks =~ s/\n//g; |
| 10136 |
$blanktrks =~ s/,\s(\d+)$/ and $1/g; |
| 10137 |
$ghostrks =~ s/,\s(\d+)$/ and $1/g; |
| 10138 |
$splitrks =~ s/,\s(\d+)$/ and $1/g; |
| 10139 |
|
| 10140 |
my $riptime = 0; |
| 10141 |
if($rip == 1) { |
| 10142 |
@ripstart = split(/:/, $ripstart[0]); |
| 10143 |
@ripend = split(/:/, $ripend[0]); |
| 10144 |
$ripend[0] += 24 if($ripend[0] < $ripstart[0]); |
| 10145 |
$riptime = ($ripend[0] * 60 + $ripend[1]) - |
| 10146 |
($ripstart[0] * 60 + $ripstart[1]); |
| 10147 |
} |
| 10148 |
|
| 10149 |
my $enctime = "@enctime"; |
| 10150 |
chomp $enctime; |
| 10151 |
if($encode == 1) { |
| 10152 |
@enctime = split(/ /, $enctime); |
| 10153 |
$enctime[0] = 0 unless(@enctime); |
| 10154 |
$enctime = int($enctime[0]/60); |
| 10155 |
} |
| 10156 |
else { |
| 10157 |
$enctime = 0; |
| 10158 |
} |
| 10159 |
|
| 10160 |
# Return to sub finish_process. |
| 10161 |
return ($riptime,$enctime,$encend,$blanktrks,$ghostrks,$splitrks); |
| 10162 |
} |
| 10163 |
######################################################################## |
| 10164 |
# |
| 10165 |
# Thanks to mjb: log info to file. |
| 10166 |
# |
| 10167 |
sub log_info { |
| 10168 |
if(!defined($infolog)) { return; } |
| 10169 |
elsif($infolog eq "") { return; } |
| 10170 |
open(SYSLOG, ">>$infolog") or |
| 10171 |
print "Can't open info log file <$infolog>.\n"; |
| 10172 |
print SYSLOG "@_\n"; |
| 10173 |
close(SYSLOG); |
| 10174 |
} |
| 10175 |
######################################################################## |
| 10176 |
# |
| 10177 |
# Thanks to mjb and Stefan Wartens improvements: |
| 10178 |
# log_system used throughout in place of system() calls. |
| 10179 |
# |
| 10180 |
sub log_system { |
| 10181 |
my $P_command = shift; |
| 10182 |
if($verbose > 3) { |
| 10183 |
# A huge hack only not to interfere with the ripper output. |
| 10184 |
if($P_command =~ /faac|flac|lame|machine|mpc|mp4als|oggenc|vorbiscomment/ && |
| 10185 |
$P_command !~ /cdparanoia|cdda2wav|dagrab|icedax|vorbiscomment.*COVERART/) { |
| 10186 |
enc_print("$P_command", 3); |
| 10187 |
} |
| 10188 |
elsif($P_command =~ /mkdir|COVERART/) { |
| 10189 |
my $prcmd = $P_command; |
| 10190 |
$prcmd =~ s/COVERART=.*$/COVERART=binary-data-removed/; |
| 10191 |
print "system: $prcmd\n\n" if($verbose > 4); |
| 10192 |
} |
| 10193 |
else { |
| 10194 |
print "system: $P_command\n\n"; |
| 10195 |
} |
| 10196 |
} |
| 10197 |
|
| 10198 |
# Log the system command to logfile unless it's the coverart command |
| 10199 |
# for vorbiscomment with the whole binary picture data. |
| 10200 |
log_info("system: $P_command") unless($P_command =~ /vorbiscomment/); |
| 10201 |
|
| 10202 |
# Start a watch process to check progress of ripped tracks. |
| 10203 |
if($parano == 2 && $P_command =~ /^cdparano/ |
| 10204 |
&& $P_command !~ /-Z/ |
| 10205 |
&& $P_command !~ /-V/) { |
| 10206 |
my $pid = 0; |
| 10207 |
# This is probably dangerous, very dangerous because of zombies... |
| 10208 |
$SIG{CHLD} = 'IGNORE'; |
| 10209 |
unless($pid = fork) { |
| 10210 |
exec($P_command); |
| 10211 |
exit; |
| 10212 |
} |
| 10213 |
# ... but we check and wait for $pid to finish in subroutine. |
| 10214 |
my $result = check_ripper($P_command, $pid); |
| 10215 |
waitpid($pid, 0); |
| 10216 |
$SIG{CHLD} = 'DEFAULT'; |
| 10217 |
return $result; |
| 10218 |
} |
| 10219 |
else { |
| 10220 |
system($P_command); |
| 10221 |
} |
| 10222 |
|
| 10223 |
# system() returns several pieces of information about the launched |
| 10224 |
# subprocess squeezed into a 16-bit integer: |
| 10225 |
# |
| 10226 |
# 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 |
| 10227 |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 10228 |
# | | | | | | | | | | | | | | | | | [ $? ] |
| 10229 |
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 10230 |
# \_____________________/ \/ \__________________/ |
| 10231 |
# exit code core signal number |
| 10232 |
# |
| 10233 |
# To get the exit code, use ($? >> 8) |
| 10234 |
# To get the signal number, use ($? & 127) |
| 10235 |
# To get the dumped core flag, use ($? & 128) |
| 10236 |
|
| 10237 |
# Subprocess has been executed successfully. |
| 10238 |
return 1 if $? == 0; |
| 10239 |
|
| 10240 |
# Subprocess was killed by SIGINT (CTRL-C). Exit RipIT. |
| 10241 |
die "\n\nRipit caught a SIGINT.\n" if(( $? & 127) == 2); |
| 10242 |
|
| 10243 |
# Subprocess could not be executed or failed. |
| 10244 |
return 0; |
| 10245 |
} |
| 10246 |
######################################################################## |
| 10247 |
# |
| 10248 |
# Special characters in cd.toc file won't be written correctly by |
| 10249 |
# cdrdao, so map them to octal. |
| 10250 |
# |
| 10251 |
# Thanks to pancho horrillo: |
| 10252 |
# http://perldoc.perl.org/perluniintro.html#Displaying-Unicode-As-Text |
| 10253 |
# |
| 10254 |
sub oct_char { |
| 10255 |
$_[0] = join '', |
| 10256 |
map { $_ > 191 |
| 10257 |
? sprintf '\%o', $_ |
| 10258 |
: chr $_ |
| 10259 |
} unpack("C0U*", "$_[0]"); |
| 10260 |
} |
| 10261 |
######################################################################## |
| 10262 |
# |
| 10263 |
# Check if there is a CD in the CD device. If a CD is present, start |
| 10264 |
# process. If not, wait until operator inserts a CD, i.e. come back! |
| 10265 |
# Problem: when used with option loop, the CD already done should not |
| 10266 |
# be reread again. In this case, don't close the tray automatically. |
| 10267 |
# |
| 10268 |
sub cd_present { |
| 10269 |
print "\nExecuting sysopen(CD, $scsi_cddev, O_RDONLY | O_NONBLOCK) ", |
| 10270 |
"or return;\n" if($verbose > 5); |
| 10271 |
sysopen(CD, $scsi_cddev, O_RDONLY | O_NONBLOCK) or return; |
| 10272 |
my $os = `uname -s`; |
| 10273 |
my $CDROMREADTOCHDR = 0x5305; # Linux |
| 10274 |
if($os eq "SunOS") { |
| 10275 |
$CDROMREADTOCHDR = 0x49b; |
| 10276 |
} |
| 10277 |
elsif($os =~ /BSD/i) { |
| 10278 |
$CDROMREADTOCHDR = 0x40046304; |
| 10279 |
} |
| 10280 |
my $tochdr = ""; |
| 10281 |
my $err = ioctl(CD, $CDROMREADTOCHDR, $tochdr); |
| 10282 |
close(CD); |
| 10283 |
return $err; |
| 10284 |
} |
| 10285 |
######################################################################## |
| 10286 |
# |
| 10287 |
# A hack to reinitialize global variables before starting a new loop. |
| 10288 |
# |
| 10289 |
sub init_var { |
| 10290 |
# We lost and tweaked too many things, start from scratch: |
| 10291 |
read_config() if($config == 1); |
| 10292 |
# But all arguments passed on CL should remain... |
| 10293 |
$categ = ""; |
| 10294 |
$cddbid = 0; |
| 10295 |
$cdid = ""; |
| 10296 |
$discid = ""; |
| 10297 |
@audio = (); |
| 10298 |
@isrcs = (); |
| 10299 |
@idata = (); |
| 10300 |
@framelist = (); |
| 10301 |
@secondlist = (); |
| 10302 |
@tracklist = (); |
| 10303 |
@tracktags = (); |
| 10304 |
@seltrack = (); |
| 10305 |
@tracksel = (); |
| 10306 |
%cd = (); |
| 10307 |
$cddbsubmission = 2; |
| 10308 |
$hiddenflag = 0; |
| 10309 |
$wavdir = ""; |
| 10310 |
@sepdir = (); |
| 10311 |
$year = ""; |
| 10312 |
$genre = ""; |
| 10313 |
$album_utf8 = ""; |
| 10314 |
$artist_utf8 = ""; |
| 10315 |
if(defined $pscsi_cddev) { |
| 10316 |
$scsi_cddev = $pscsi_cddev; |
| 10317 |
} |
| 10318 |
else { |
| 10319 |
$scsi_cddev = $pcddev if($pcddev); |
| 10320 |
} |
| 10321 |
if($scsi_cddev eq "") { |
| 10322 |
$scsi_cddev = $cddev; |
| 10323 |
} |
| 10324 |
} |
| 10325 |
######################################################################## |
| 10326 |
# |
| 10327 |
# Get the revision number of the CDDB entry. |
| 10328 |
# |
| 10329 |
sub get_rev { |
| 10330 |
my @revision = grep(/^\#\sRevision:\s/, @{$cd{raw}}); |
| 10331 |
my $revision = join('', grep(s/^\#\sRevision:\s//, @revision)); |
| 10332 |
chomp $revision if($revision); |
| 10333 |
return $revision; |
| 10334 |
} |
| 10335 |
######################################################################## |
| 10336 |
# |
| 10337 |
# Change case to lowercase and uppercase first if wanted. Test command: |
| 10338 |
# perl -e '$string="gLabber (live/mix:radio edit [perl re-mix])"; $string=~s/(\w+)/\u\L$1/g; print "\nString is: $string\n"' |
| 10339 |
# |
| 10340 |
sub change_case { |
| 10341 |
# We want to differentiate if coming from a track or directory string to |
| 10342 |
# be lowercased (or put to ucfirst). Second argument gives that hint: |
| 10343 |
# "t" for track, "d" for directory. |
| 10344 |
# use encoding "utf8"; # This will break every single non ascii char! |
| 10345 |
if($lowercase == 1 or ($lowercase == 2 and $_[1] eq "t") |
| 10346 |
or ($lowercase == 3 and $_[1] eq "d") |
| 10347 |
or $uppercasefirst == 1) { |
| 10348 |
$_[0] = lc($_[0]); |
| 10349 |
$_[0] =~ tr/[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ]/[àáâãäåæçèéêëìíîï]/; |
| 10350 |
$_[0] =~ tr/[ÐÑÒÓÔÕÖØÙÚÛÜÝÞ]/[ðñòóôõöøùúûüýþ]/; |
| 10351 |
} |
| 10352 |
if($uppercasefirst == 1) { |
| 10353 |
# s/(\w+)/\u\L$1/g; # Does not work with non ascii chars... |
| 10354 |
my @words = split(/ /, $_[0]); |
| 10355 |
foreach (@words) { |
| 10356 |
s/(\w+)/\u\L$1/g; # Ensure ucfirst within brackets etc. |
| 10357 |
$_ = "\u$_"; |
| 10358 |
$_ =~ tr/^[àáâãäåæçèéêëìíîï]/[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ]/; |
| 10359 |
$_ =~ tr/^[ðñòóôõöøùúûüýþ]/[ÐÑÒÓÔÕÖØÙÚÛÜÝÞ]/; |
| 10360 |
} |
| 10361 |
$_[0] = join(' ', @words); |
| 10362 |
} |
| 10363 |
return $_[0]; |
| 10364 |
} |
| 10365 |
######################################################################## |
| 10366 |
# |
| 10367 |
# Strip dodgey chars I. This will be done for file names and tags. |
| 10368 |
# |
| 10369 |
# TODO: Do we really have to erase all of them? Maybe we should keep |
| 10370 |
# some for the tags... |
| 10371 |
# |
| 10372 |
sub clean_all { |
| 10373 |
return unless(defined $_[0]); |
| 10374 |
$_[0] =~ s/[;><"\015]//g; |
| 10375 |
$_[0] =~ s/\`/\'/g; |
| 10376 |
$_[0] =~ s/´/\'/g; |
| 10377 |
$_[0] =~ s/\s+/ /g; |
| 10378 |
return $_[0]; |
| 10379 |
} |
| 10380 |
######################################################################## |
| 10381 |
# |
| 10382 |
# Strip dodgey chars II. This will only be done for file names. |
| 10383 |
# |
| 10384 |
sub clean_name { |
| 10385 |
return unless(defined $_[0]); |
| 10386 |
$_[0] =~ s/[*]//g; |
| 10387 |
$_[0] =~ s/\// - /g; |
| 10388 |
$_[0] =~ s/\s+/ /g; |
| 10389 |
return $_[0]; |
| 10390 |
} |
| 10391 |
######################################################################## |
| 10392 |
# |
| 10393 |
# Strip dodgey chars III. This will optionally be done for file names |
| 10394 |
# and paths. Remember the default chars to be erased are: |\:*?$ plus |
| 10395 |
# blanks and periods at begin and end of file names and directories. |
| 10396 |
# But the ending periods problem is not done here, because |
| 10397 |
# it should only affect directories, not files which have a suffix |
| 10398 |
# anyway! See subroutine create_dirs! |
| 10399 |
# |
| 10400 |
sub clean_chars { |
| 10401 |
return unless(defined $_[0]); |
| 10402 |
# Delete beginning blanks in directory names. |
| 10403 |
$_[0] =~ s,/\s+,/,g if($chars =~ /NTFS/); |
| 10404 |
# Delete beginning blanks in file names. |
| 10405 |
$_[0] =~ s/^\s+//g if($chars =~ /NTFS/); |
| 10406 |
# Delete beginning periods in directory names. |
| 10407 |
$_[0] =~ s,/\.+,/,g if($chars =~ /HFS|NTFS/); |
| 10408 |
# Delete beginning periods in file names. |
| 10409 |
$_[0] =~ s/^\.+//g if($chars =~ /HFS|NTFS/); |
| 10410 |
my $purged_chars = $chars; |
| 10411 |
$purged_chars = ":" if($chars =~ /HFS/); |
| 10412 |
$purged_chars = "[|\\\\:*?\$]" if($chars =~ /NTFS/); |
| 10413 |
$_[0] =~ s/$purged_chars//g if($purged_chars ne ""); |
| 10414 |
$_[0] =~ s/\s+/ /g; |
| 10415 |
$_[0] =~ s/\s$//; |
| 10416 |
return $_[0]; |
| 10417 |
} |
| 10418 |
######################################################################## |
| 10419 |
# |
| 10420 |
# Put all chars in brackets and escape some. |
| 10421 |
# |
| 10422 |
sub check_chars { |
| 10423 |
$chars =~ s/\\/\\\\/; |
| 10424 |
$chars =~ s/-/\\-/; |
| 10425 |
$chars =~ s/]/\\]/; |
| 10426 |
$chars =~ s/\s/\\s/; |
| 10427 |
$chars = "[" . $chars . "]" unless($chars =~ /HFS|NTFS|off/); |
| 10428 |
} |
| 10429 |
######################################################################## |
| 10430 |
# |
| 10431 |
# Extract the CDDB comment lines starting with EXTD=. |
| 10432 |
# NOTE: Each EXTD line my have \n's, but two EXTD lines do NOT |
| 10433 |
# mean that there's a line break in between! So, what we have to do |
| 10434 |
# is, put all comment lines into a string and split the string |
| 10435 |
# according to the explicitly \n's (i.e. use \\n).and add a \n at the |
| 10436 |
# end of each line! |
| 10437 |
# |
| 10438 |
sub extract_comm { |
| 10439 |
my @comment = grep(/^EXTD=/, @{$cd{raw}}); |
| 10440 |
@comment = grep(s/^EXTD=//, @comment); |
| 10441 |
my $line = "@comment"; |
| 10442 |
$line =~ s/[\015]//g; |
| 10443 |
@comment = split(/\\n/, $line); |
| 10444 |
foreach (@comment) { |
| 10445 |
chomp $_; |
| 10446 |
$_ =~ s/^\s+//g; |
| 10447 |
} |
| 10448 |
return (@comment); |
| 10449 |
} |
| 10450 |
######################################################################## |
| 10451 |
# |
| 10452 |
# Display a help page and exit. |
| 10453 |
# |
| 10454 |
# New options step 12: Add a short explanation for option --help and do |
| 10455 |
# not forget to update the manpage ripit.1 to be checked with option -l. |
| 10456 |
# |
| 10457 |
sub print_help { |
| 10458 |
print <<END |
| 10459 |
|
| 10460 |
SYNOPSIS: |
| 10461 |
ripit [options] |
| 10462 |
|
| 10463 |
OPTIONS: |
| 10464 |
[track_selection] |
| 10465 |
If not specified, all tracks will be ripped. Type a number |
| 10466 |
or a selection of tracks using numbers separated by commas |
| 10467 |
or hyphens. Use 1-a to rip all consecutive audio tracks |
| 10468 |
and prevent trying to rip data tracks. Default: not set. |
| 10469 |
-I, --span number-number |
| 10470 |
Give a span or interval to rip only a part of the track. |
| 10471 |
The cdparanoia notation is used in the format hh:mm:ss.ff |
| 10472 |
without brackets. The hyphen is mandatory. |
| 10473 |
--merge ordered list of comma separated intervals |
| 10474 |
Place a hyphen or a + between first and last track number |
| 10475 |
to be merged, default: not set. |
| 10476 |
-o, --outputdir directory |
| 10477 |
Where the sound should go. If not set, \$HOME will be used. |
| 10478 |
Default: not set. |
| 10479 |
--dpermission number |
| 10480 |
Define directory permissions, default: 0755. |
| 10481 |
--fpermission number |
| 10482 |
Define permissions of sound and log files, default: not |
| 10483 |
set, i.e. depending on the system settings. |
| 10484 |
-d, --device cddevice |
| 10485 |
Path of audio CD device, default: /dev/cdrom. |
| 10486 |
--scsidevice cddevice |
| 10487 |
Devicename for a different device node of cddevice |
| 10488 |
where non ripping commands shall be executed. |
| 10489 |
-r, --ripper number |
| 10490 |
0 dagrab, 1 cdparanoia, 2 cdda2wav, 3 tosha, 4 cdd, |
| 10491 |
default: 1. |
| 10492 |
--ripopt options |
| 10493 |
Additional options for specific ripper. Default: not set. |
| 10494 |
--offset number |
| 10495 |
Give a sample offset for the ripper. Optiononly supported |
| 10496 |
by cdparanoia and rip (Morituri). Default: not set. |
| 10497 |
-Q, --accuracy number |
| 10498 |
Check rips at AccurateRip using Morituri (rip) which must |
| 10499 |
be installed. Default: off (0). |
| 10500 |
-Y, --verify number |
| 10501 |
Rip track until md5sum for 2 rips match, maximum tries |
| 10502 |
is number given as argument, default: 1, i.e. no checks |
| 10503 |
will be done. |
| 10504 |
--nicerip value |
| 10505 |
Set niceness of ripping process, default: 0. |
| 10506 |
-Z, --disable-paranoia [number] |
| 10507 |
When using dagrab, the number of retries will be set to 3, |
| 10508 |
with cdparanoia this option is equal to the -Z option of |
| 10509 |
cdparanoia. Usefull for faster ripping but not recommended. |
| 10510 |
Use no argument or 1 to swith paranoia off or 2 if failed |
| 10511 |
tracks should be done again without paranoia (only one |
| 10512 |
retry). Default: off (i.e. paranoia on). |
| 10513 |
-G, --ghost Analyze wav and split into possible chunks of sound or try |
| 10514 |
to trim lead-in/out. This may override option merge! |
| 10515 |
Delete blank tracks if only silence ("zero bytes") are |
| 10516 |
found. Experimental! Default: off. |
| 10517 |
--extend seconds |
| 10518 |
Enlarge splitted chunk by number of seconds if possible, |
| 10519 |
or track may be trimmed if value is small (e.g. 0.2), use |
| 10520 |
with caution! default: 2.0. |
| 10521 |
--prepend seconds |
| 10522 |
Enlarge splitted chunk by number of seconds if possible, |
| 10523 |
or track may be trimmed if value is small (e.g. 0.2), use |
| 10524 |
with caution! Default: 2.0. |
| 10525 |
-c, --coder encoder |
| 10526 |
0 Lame, 1 Oggenc, 2 Flac, 3 Faac, 4 mp4als, 5 Musepack, |
| 10527 |
6 Wavpack, 7 ffmpge, a comma separated list or use -c for |
| 10528 |
each encoder. |
| 10529 |
The same encoder may be stated more than once. Adapt |
| 10530 |
--dirtemplate in this case, see below. Default: 0. |
| 10531 |
--musenc name |
| 10532 |
Pass the command line name of Musepack encoder, e. g. |
| 10533 |
mppenc. Default: mpcenc. |
| 10534 |
--faacopt Faac-options |
| 10535 |
Pass other options to the encoder, quote them with double |
| 10536 |
quotes if needed; comma separated list if same enocder |
| 10537 |
is used more than once. Default: not set. |
| 10538 |
--flacopt Flac-options |
| 10539 |
Same as above. |
| 10540 |
--lameopt Lame-options |
| 10541 |
Same as above. |
| 10542 |
--museopt Musepack-options |
| 10543 |
Same as above. |
| 10544 |
--mp4alsopt mp4als-options |
| 10545 |
Same as above. |
| 10546 |
--oggencopt Oggenc-options |
| 10547 |
Same as above. |
| 10548 |
--wavpacopt Wavpack-options |
| 10549 |
Same as above. |
| 10550 |
--ffmpegopt ffmpeg-options |
| 10551 |
Same as above. |
| 10552 |
--ffmpegsuffix suffix |
| 10553 |
Suffix of the choosen encoder in ffmpeg, a comma sparated |
| 10554 |
list; default: not set. |
| 10555 |
-q, --quality quality |
| 10556 |
A comma separated list of values or the word \"off\", passed |
| 10557 |
in the same order as the list of encoders! If no encoders |
| 10558 |
passed, follow the order of the config file! No quality |
| 10559 |
for wavpack and ffmpeg, use options instead. Default |
| 10560 |
5,3,5,100,0,5. |
| 10561 |
-v, --vbrmode mode |
| 10562 |
Variable bitrate, only used with Lame, mode is new or old, |
| 10563 |
see Lame manpage. The Lame-option quality will be changed |
| 10564 |
to -V instead of -q if vbr-mode is used; default: not set. |
| 10565 |
-b, --bitrate rate |
| 10566 |
Encode \"mp3\" at this bitrate for Lame. If option --vbrmode |
| 10567 |
used, bitrate is equal to the -b option, so one might want |
| 10568 |
to set it \"off\", default: 128. |
| 10569 |
-B, --maxrate rate |
| 10570 |
maxrate (Bitrate) for Lame using --vbrmode is equal to the |
| 10571 |
-B option for Lame or the -M option for Oggenc, |
| 10572 |
default: 0. |
| 10573 |
-S, --preset mode |
| 10574 |
Use the preset switch when encoding with Lame. With option |
| 10575 |
--vbrmode new --preset fast will be used. Default: off. |
| 10576 |
-W, --chars [list] |
| 10577 |
Exclude special characters and (ending!) periods in file |
| 10578 |
names and path. The argument is optional. Following |
| 10579 |
characters will be erased, if no argument is stated: |
| 10580 |
|\\:*?\$ else only ending periods and all passed ones. |
| 10581 |
Default: off. |
| 10582 |
--comment comment |
| 10583 |
Specify a comment tag (mp3, m4a), or a description tag for |
| 10584 |
(ogg, flac). To write the cddbid used for freedb |
| 10585 |
or the MusicBrainz discid into the comment, use the word |
| 10586 |
\"cddbid\" or \"discid\". Default: not set. |
| 10587 |
-g, --genre genre |
| 10588 |
Specify (and override CDDB) genre, must be a valid ID3- |
| 10589 |
genre name if using Lame, can (but shouldn't) be anything |
| 10590 |
if using other encoders, default: not set. |
| 10591 |
-y, --year year |
| 10592 |
Specify (and override CDDB) year tag (mp3, m4a), or a date |
| 10593 |
tag (ogg, flac), default: not set. |
| 10594 |
-D, --dirtemplate '\" foo \$parameters \"' |
| 10595 |
Use single and double quotes to pass the parameters of the |
| 10596 |
templates. More than one --dirtemplate may be stated, or |
| 10597 |
use variables \$quality and \$suffix. See manpage for more |
| 10598 |
info. Default: '\"\$artist - \$album\"' |
| 10599 |
-T, --tracktemplate '\"foo \$parameters\"' |
| 10600 |
See above. Only one tracktemplate can be stated. Default: |
| 10601 |
'"\$tracknum \$trackname"'. |
| 10602 |
--trackoffset number |
| 10603 |
Use an offset to be added to \$tracknum, default 0. |
| 10604 |
--addtrackoffset |
| 10605 |
With MusicBrainz check for multi disc release and use |
| 10606 |
offset if found. Overwrite mode will be switched on for |
| 10607 |
those runs where the first track of the disc is not found |
| 10608 |
in an existing direcotry. Default off. |
| 10609 |
--discno number |
| 10610 |
Set a discnumber in the tags if encoder supports the tag. |
| 10611 |
Set manually a value above 0 or when using MB let it set |
| 10612 |
automatically (discno=1). Default 0 (off). |
| 10613 |
--coverart list |
| 10614 |
Add coverart to the sound files. Comma separated list |
| 10615 |
according to option coder with values 0 (no) or 1 (yes), |
| 10616 |
default 0. |
| 10617 |
--coverpath path |
| 10618 |
Path to the coverart picture to be included in the |
| 10619 |
meta data of the sound files, default: not set. |
| 10620 |
-F, --coversize format |
| 10621 |
Resize coverart pictures to be included in the meta data |
| 10622 |
of the sound files to a XXXxYYY format. To ensure aspect |
| 10623 |
ratio, only the width can be stated, default: not set. |
| 10624 |
--copycover path |
| 10625 |
Copy an image (may also be any other file) to all |
| 10626 |
directories containing encoded files. |
| 10627 |
Value: absolute path to file. Default: not set. |
| 10628 |
--coverorg number |
| 10629 |
Search for coverart at coverartarchive.org. |
| 10630 |
Value: 0 (no) or 1 (yes), default 0. |
| 10631 |
--flactags FRAME=tag |
| 10632 |
Special frames to be added to the flac file with meta |
| 10633 |
data provided e.g. when using MB. Use option --flacopt |
| 10634 |
for regular hard coded tags to be added. Use this option |
| 10635 |
to add following predefined frames: ASIN, BARCODE, |
| 10636 |
CATALOG, CDDBID, DISCID and MBREID |
| 10637 |
(musicbrainz release ID), tag names in lower case. |
| 10638 |
Default: not set. |
| 10639 |
--mp3tags FRAME=tag or FRAME=[description]tag |
| 10640 |
Additional frames to be added to the mp3 file if encoder |
| 10641 |
does not support the frame or if some unofficial FRAMEs |
| 10642 |
shall be used. More than one --mp3tags can be used if |
| 10643 |
several tags shall be added. Special tags to TXXX or |
| 10644 |
WXXX frame need a description. If stated with a special |
| 10645 |
description the tag names are evaluated. |
| 10646 |
Special descriptions are ASIN, BARCODE, CATALOG, CDDBID, |
| 10647 |
DISCID and MBREID (musicbrainz release ID), tag names in |
| 10648 |
lower case. |
| 10649 |
Default: not set. |
| 10650 |
--oggtags FRAME=tag |
| 10651 |
Same as flactags, default: not set. |
| 10652 |
--vatag number |
| 10653 |
Analyze track names for "various artists" style and split |
| 10654 |
the meta data in case one of the delimiters (colon, hyphen, |
| 10655 |
slash or parenthesis) are found. Use unpair numbers for |
| 10656 |
the scheme "artist ? tracktitle" and pair numbers in the |
| 10657 |
opposite case. Default: not set. |
| 10658 |
--vastring string |
| 10659 |
A string (regular expression) that defines the "various |
| 10660 |
artists" style, default: \bVA\b|Variou*s|Various\\sArtists|Soundtrack|OST |
| 10661 |
--flacgain Flacgain command with options but no filenames, e.g. |
| 10662 |
metflac. |
| 10663 |
--mp3gain mp3gain command with options but no filenames. |
| 10664 |
--mpcgain mpdgain command with options but no filenames. |
| 10665 |
--aacgain aacgain command with options but no filenames. |
| 10666 |
--vorbgain vorbisgain command with options but no filenames. |
| 10667 |
--wvgain wvgain command with options but no filenames. |
| 10668 |
--sshlist list |
| 10669 |
Comma separated list of remote machines where RipIT should |
| 10670 |
encode. Default: not set. |
| 10671 |
--scp If the filesystem can not be accessed on the remote |
| 10672 |
machines, copy the wavs to the remote machines, |
| 10673 |
default: off. |
| 10674 |
--local Only used with option --sshlist; if all encodings shall be |
| 10675 |
done on remote machines, use --nolocal, default: on. |
| 10676 |
--mb Use musicbrainz instead of freedb, default: off. |
| 10677 |
--mbrels number Retrieve relationships for each track and add vocal |
| 10678 |
performer to track title if found, default: off. |
| 10679 |
--mbname login |
| 10680 |
Give MB login name to submitt ISRCs to the database. Saved |
| 10681 |
in plain when using a config, default not set. |
| 10682 |
--mbpass password |
| 10683 |
Give MB password to submitt ISRCs to the database. Saved |
| 10684 |
in plain when using a config, default not set. |
| 10685 |
--isrc number |
| 10686 |
Enable ISRC detection and submission to MB (1 yes, 0 no); |
| 10687 |
default: 0 |
| 10688 |
--cdtext number |
| 10689 |
Check for CD text if no DB entry found, default: 0 - off. |
| 10690 |
-C, --cddbserver server |
| 10691 |
CDDB server, default freedb.org. Note, the full address is |
| 10692 |
\"mirror\".freedb.org, i. e. default is freedb.freedb.org. |
| 10693 |
-m, --mirror mirror |
| 10694 |
Choose \"freedb\" or one of the possible freedb |
| 10695 |
mirrors, default: freedb. |
| 10696 |
-L, --protocol level |
| 10697 |
CDDB protocol level for CDDB query. Level 6 supports UTF-8 |
| 10698 |
and level 5 not. Default: 6 |
| 10699 |
-P, --proxy address |
| 10700 |
The http proxy to use when accessing the cddb server. The |
| 10701 |
CDDB protocol must be http! Default: not set. |
| 10702 |
-t, --transfer mode |
| 10703 |
Transfer mode, cddb or http, will set default port to 8880 |
| 10704 |
or 80 (for http), default: cddb. |
| 10705 |
-n, --nice value |
| 10706 |
Set niceness of encoding process, default: not set. |
| 10707 |
-a, --archive |
| 10708 |
Read and save CDDB files in \$HOME/.cddb/\"category\" |
| 10709 |
directory. Default: off. |
| 10710 |
-e, --eject Ejects the CD when finished, default off. |
| 10711 |
--ejectcmd cmd |
| 10712 |
Command to use for ejecting CD (see --eject), default: |
| 10713 |
eject. |
| 10714 |
--ejectopt options |
| 10715 |
Arguments to the ejecting CD command (see --ejectcmd), |
| 10716 |
default: path of CD device. |
| 10717 |
--halt Powers off the machine when finished if the configuration |
| 10718 |
supports it, default: off. |
| 10719 |
-s, --submission |
| 10720 |
Specify --nosubmission if the computer is offline and the |
| 10721 |
created file cddb.toc shall be saved in the home directory |
| 10722 |
instead of being submitted. With option --archive it will |
| 10723 |
also be saved in the \$HOME/.cddb directory. Default: on. |
| 10724 |
-M, --mail address |
| 10725 |
Users return email address, needed for submitting an entry |
| 10726 |
to freedb.org. Default: not set. |
| 10727 |
--mailopt options |
| 10728 |
Special options to sendmail program, default: -t |
| 10729 |
-p, --playlist number |
| 10730 |
Create a m3u playlist file with full paths in filenames. |
| 10731 |
For filenames without paths use --playlist 2. To prevent |
| 10732 |
playlist creation, use: --playlist 0. Default: 1 - on. |
| 10733 |
-i, --interaction |
| 10734 |
Specify --nointeraction if ripit shall take the first CDDB |
| 10735 |
entry found and rip without any questioning. Default: on. |
| 10736 |
--lcd Use lcdproc to display status, default: on. |
| 10737 |
--lcdhost Specify the lcdproc host, default: localhost. |
| 10738 |
--lcdport Specify the lcdport, default: 13666. |
| 10739 |
--infolog file |
| 10740 |
Log operations (system calls, file/directory creation) to |
| 10741 |
file, given with full path; default: not set. |
| 10742 |
-l, --lowercase number |
| 10743 |
Lowercase file and / or directory names, default: off. |
| 10744 |
0 off; 1 on; 2 on only for file names; 3 on only for |
| 10745 |
directory names. |
| 10746 |
-u, --underscore |
| 10747 |
Use underscores _ instead of spaces in filenames, default: |
| 10748 |
off. |
| 10749 |
--uppercasefirst |
| 10750 |
Uppercase first characters of each word in filenames and |
| 10751 |
tags, default: off. |
| 10752 |
-U, --utftag If negated decodes Lame-tags to ISO8859-1. Default: off. |
| 10753 |
--rip Rip the CD, to be used as --norip if wavs of flacs are |
| 10754 |
present in --inputdir. |
| 10755 |
Default: on. |
| 10756 |
--inputdir directory |
| 10757 |
Full path to the directory with wav or flac files to be |
| 10758 |
re-encoded using option --norip. Default: not set. |
| 10759 |
--cdid id Give a freedb.ord CDDBID or a musicbrainz discid in case |
| 10760 |
look-up shall be done when re-encoding wav or flac files |
| 10761 |
using --norip. Default: not set. |
| 10762 |
--encode Prevent encoding (generate only wavs) with --noencode. |
| 10763 |
Default: on. |
| 10764 |
-w, --wav Keep the wav files after encoding instead of deleting them |
| 10765 |
default: off. |
| 10766 |
-N, --normalize |
| 10767 |
Normalizes the wav-files to a given dB-value (default: |
| 10768 |
-12dB). Default: off. |
| 10769 |
--normcmd Command to use for normalizing, default: normalize. |
| 10770 |
-z, --normopt |
| 10771 |
Options to pass to normalize. For further options see |
| 10772 |
normalize documentation (http://normalize.nongnu.org). |
| 10773 |
Keeping the default value of -12dB is recommended. |
| 10774 |
Default: -b. Option v will be set according to verbosity. |
| 10775 |
--cdtoc n |
| 10776 |
n=1: Create a toc file to burn the wavs with cd-text using |
| 10777 |
cdrdao or cdrecord (in dao mode), default: 0 - off. |
| 10778 |
--cdcue n |
| 10779 |
n=1: Create a cue file to burn the merged wavs with |
| 10780 |
cd-text, default: 0 - off. |
| 10781 |
--cue n |
| 10782 |
n=1: Create a cue file to play or burn the wavs with |
| 10783 |
cd-text, default: 0 - off. |
| 10784 |
--inf n |
| 10785 |
n=1: Creat inf files for each track to burn the wavs with |
| 10786 |
cd-text using wodim or cdrecord (in dao mode), |
| 10787 |
default: 0 - off. |
| 10788 |
-h, --help Print this and exit. |
| 10789 |
-V, --version |
| 10790 |
Print version and exit. |
| 10791 |
-x, --verbose number |
| 10792 |
Run silent (0), with minimal (1), normal without encoder |
| 10793 |
messages (2), normal (3), verbose (4) or extremely verbose |
| 10794 |
(5). Default 3 |
| 10795 |
--config Read parameters from config file or specify --noconfig to |
| 10796 |
prevent reading it; default: on. |
| 10797 |
--save Add parameters passed on command line to config file. This |
| 10798 |
options does not overwrite other settings. An existing |
| 10799 |
config file will be saved as config.old. Default: off. |
| 10800 |
--savenew Save all parameters passed on command line to a new config |
| 10801 |
file, backup an existing file to config.old. Default: off. |
| 10802 |
-A, --book number |
| 10803 |
Create an audiobook, i. e. merge all tracks into one sinlge |
| 10804 |
file, option --ghost will be switched off and file suffix |
| 10805 |
will be m4b in case faac is used. A chapter file |
| 10806 |
will be written for chapter marks. Default: off |
| 10807 |
--loop number |
| 10808 |
Continue to ripp and encode as soon as the previous CD has |
| 10809 |
finished. This option forces ejection of the CD. Set |
| 10810 |
number to 2 for immediate restart of ripping process, |
| 10811 |
experimental. Default off. |
| 10812 |
--quitnodb value |
| 10813 |
Give up CD if no CDDB entry found. |
| 10814 |
Possible values: 0 - off, 1 - on, default: off |
| 10815 |
--resume Resume a previously started session. Default: not set. |
| 10816 |
- O, --overwrite argument |
| 10817 |
Overwrite existing rip (y), quit if directory exists (q) |
| 10818 |
or force ejection of disc if directory exists (e). Default |
| 10819 |
off (n), do not overwrite existing directories, use a |
| 10820 |
directory name with a suffix instead. |
| 10821 |
--md5sum Create a MD5-sum file for each type of sound files. |
| 10822 |
Default: not set. |
| 10823 |
--threads number |
| 10824 |
Comma separated list of numbers giving maximum of allowed |
| 10825 |
encoders to run at the same time, default: 1. |
| 10826 |
--execmd command |
| 10827 |
State a command to be executed when ripit finished. Make |
| 10828 |
sure to escape the command if needed. Default: not set. |
| 10829 |
--precmd command |
| 10830 |
State a command to be executed when ripping starts. Make |
| 10831 |
sure to escape the command if needed. Default: not set. |
| 10832 |
|
| 10833 |
|
| 10834 |
SEE ALSO |
| 10835 |
ripit(1), cdparanoia(1), lame(1), oggenc(1), flac(1), |
| 10836 |
normalize(1), cdda2wav(1), vorbgain(1). |
| 10837 |
|
| 10838 |
AUTHORS |
| 10839 |
RipIT is now maintained by Felix Suwald, please send bugs, wishes |
| 10840 |
comments to ripit _[at]_ suwald _[dot]_ com. For bugs, wishes and |
| 10841 |
comments about lcdproc, contact max.kaesbauer [at] gmail[dot]com. |
| 10842 |
Former maintainer: Mads Martin Joergensen; RipIT was originally |
| 10843 |
developed by Simon Quinn. |
| 10844 |
|
| 10845 |
DATE |
| 10846 |
April 4th, 2014 |
| 10847 |
|
| 10848 |
END |
| 10849 |
} |
| 10850 |
######################################################################## |
| 10851 |
# |
| 10852 |
# Display available options and exit! |
| 10853 |
# |
| 10854 |
# New options step 13: Add the new options to the short help/error msg. |
| 10855 |
# |
| 10856 |
sub print_usage { |
| 10857 |
print <<END |
| 10858 |
|
| 10859 |
Usage: |
| 10860 |
ripit [--device|d cd-device] [--scsidevice path] [--outputdir|o path] |
| 10861 |
[--dirtemplate '\"\$parameters\"'] [--chars|W [list]] |
| 10862 |
[--tracktemplate '\"\$parameters\"'] [--trackoffset number] |
| 10863 |
[--addtrackoffset] [--dpermission number] [--fpermission number] |
| 10864 |
[--overwrite|O argument] [--resume|R] [--inputdir path] [--rip] |
| 10865 |
[--ripper|r cdripper] [--ripopt ripper-options] [--offset number] |
| 10866 |
[--nicerip number] [--disable-paranoia|Z] [--wav|w] |
| 10867 |
[--verify|Y number] [--accuracy|Q number] [--flacdecopt options] |
| 10868 |
[--ghost|G] [--extend seconds] [--prepend seconds] [--cdid id] |
| 10869 |
[--quitnodb value] [--encode] [--coder|c encoders] [--musenc cmd] |
| 10870 |
[--faacopt options] [--flacopt options] [--oggencopt options] |
| 10871 |
[--lameopt options] [--mp4alsopt options] [--museopt options] |
| 10872 |
[--wavpacopt options] [--ffmpegopt options] [--ffmpegsuffix suffix] |
| 10873 |
[--quality qualities-list] [--bitrate|b rate] |
| 10874 |
[--maxrate|B rate] [--vbrmode|v old or new] [--preset|S mode] |
| 10875 |
[--vatag number] [--vastring string or regular expression] |
| 10876 |
[--comment id3-comment] [--genre|g genre-tag] [--year|y year-tag] |
| 10877 |
[--mp3gain| cmd options] [--vorbgain| cmd options] |
| 10878 |
[--flacgain| cmd options] [--aacgain| cmd options] |
| 10879 |
[--mpcgain| cmd options] [--wvgain| cmd options] |
| 10880 |
[--lowercase|l number] [--underscore|u] [--uppercasefirst] |
| 10881 |
[--utftag|U] [--mb] [--mbrels| number] [coverorg| number] |
| 10882 |
[--coverart list] [--coverpath path] [--coversize|F format] |
| 10883 |
[--copycover path] [--mp3tags FRAME=tag or FRAME=[desciption]tag] |
| 10884 |
[--falctags FRAME=tag] [--oggtags FRAME=tag] [--discno number] |
| 10885 |
[--mbname MB-login] [--mbpass MB-password] [--isrc number] |
| 10886 |
[--cddbserver|C server] [--mirror|m mirror] [--protocol|L level] |
| 10887 |
[--transfer|t cddb or http] [--submission|s] [--cdtext|number] |
| 10888 |
[--proxy|P path] [--mail|M address] [--mailopt options] |
| 10889 |
[--eject|e] [--ejectcmd command] [--ejectopt options for command] |
| 10890 |
[--lcd] [--lcdhost host] [--lcdport port] |
| 10891 |
[--config] [--confdir] [--confname] [--save] [--savenew] |
| 10892 |
[--sshlist remote hosts] [--local] [--scp] [--threads numbers] |
| 10893 |
[--archive|a] [--playlist|p number] [--infolog path] [--md5sum] |
| 10894 |
[--cdtoc number] [--inf number] [--cdcue number] [--cue number] |
| 10895 |
[--loop number] [--verbose|x number] |
| 10896 |
[--normalize|N] [--normcmd] [--normopt|z options] |
| 10897 |
[--interaction|i] [--nice|n adjustment] [--halt] |
| 10898 |
[--help|h] [--version|V] [--precmd cmd] [--execmd|X cmd] |
| 10899 |
[--book|A number] [--merge list] [--span|I span] [track_selection] |
| 10900 |
|
| 10901 |
|
| 10902 |
For general usage information see the manpage or type: |
| 10903 |
ripit --help | less |
| 10904 |
or try to run |
| 10905 |
ripit |
| 10906 |
without any options. |
| 10907 |
|
| 10908 |
END |
| 10909 |
} |
| 10910 |
######################################################################## |
| 10911 |
# |
| 10912 |
# Define the tracks to be skipped, change the passed values of the form |
| 10913 |
# 2+3,5-7 to an array @skip with 3,6,7. Note that we use the untouched |
| 10914 |
# variable $pmerge to determine the tracks to be skipped. |
| 10915 |
# In the same time, the intervals have to be tested if valid. |
| 10916 |
# |
| 10917 |
sub skip_tracks { |
| 10918 |
my $fill_array_flag = shift; |
| 10919 |
my @merge = split(/,/, $pmerge); |
| 10920 |
foreach (@merge) { |
| 10921 |
# Split each interval into a BeginEndArray. |
| 10922 |
my @bea = split(/-|\+/, $_); |
| 10923 |
my $i = $bea[0] + 1; |
| 10924 |
# Missing separator in command line argument? |
| 10925 |
if($#bea > 1) { |
| 10926 |
print "\nStrange interval in argument of option merge ($_)!", |
| 10927 |
"\nIs there a comma missing?\n\n"; |
| 10928 |
exit; |
| 10929 |
} |
| 10930 |
# Operator forgot to give last track or wanted the whole CD to be |
| 10931 |
# merged. But don't add zeros if we come here from the initial |
| 10932 |
# argument check when the CD-data is still unknown. |
| 10933 |
if($#tracklist >= 0) { |
| 10934 |
$pmerge .= $#tracklist + 1 unless($bea[1]); |
| 10935 |
$bea[1] = $#tracklist + 1 unless($bea[1]); |
| 10936 |
} |
| 10937 |
# Track number larger than number of tracks on CD? |
| 10938 |
if($#tracklist > 0) { |
| 10939 |
if($bea[0] > $#tracklist + 1 || $bea[1] > $#tracklist + 1) { |
| 10940 |
print "\nWrong interval in argument of option merge ($_)!", |
| 10941 |
"\nHigher track number than tracks on CD?\n\n"; |
| 10942 |
exit; |
| 10943 |
} |
| 10944 |
} |
| 10945 |
while($i <= $bea[$#bea]) { |
| 10946 |
push(@skip, $i) if($fill_array_flag == 1); |
| 10947 |
$i++; |
| 10948 |
} |
| 10949 |
} |
| 10950 |
return(@skip); |
| 10951 |
} |
| 10952 |
######################################################################## |
| 10953 |
# |
| 10954 |
# Read the header of the wav file yet still called $trn.rip and use a |
| 10955 |
# flag $prn if info shall be printed. |
| 10956 |
# |
| 10957 |
sub get_wavhead { |
| 10958 |
my $trn = shift; |
| 10959 |
my $prn = shift; |
| 10960 |
open(IN, "< $wavdir/$trn") or print "Can't open $wavdir/$trn: $!\n"; |
| 10961 |
binmode(IN); |
| 10962 |
my $H = {}; |
| 10963 |
$H->{header_size} = 44; |
| 10964 |
my $wavheader; |
| 10965 |
print "Can not read full WAV header!\n" |
| 10966 |
if($H->{header_size} != read(IN, $wavheader, $H->{header_size})); |
| 10967 |
close(IN); |
| 10968 |
|
| 10969 |
# Unpack the wav header and fill all values into a hashref. |
| 10970 |
($H->{RIFF_header}, $H->{file_size_8}, $H->{WAV_header}, |
| 10971 |
$H->{FMT_header}, $H->{WAV_chunk_size}, $H->{WAV_type}, |
| 10972 |
$H->{channels}, $H->{sample_rate}, $H->{byte_per_sec}, |
| 10973 |
$H->{block_align}, $H->{bit_per_sample}, $H->{data_header}, |
| 10974 |
$H->{data_size} |
| 10975 |
) = unpack("a4Va4a4VvvVVvva4V", $wavheader); |
| 10976 |
|
| 10977 |
$H->{sample_size} = ($H->{channels} * $H->{bit_per_sample})>>3; |
| 10978 |
if($verbose >= 4 && $prn == 1) { |
| 10979 |
print "\nThe wav header has following entries:\n"; |
| 10980 |
print "$_ \t -> $H->{$_} \n" foreach (keys %$H); |
| 10981 |
print "\n"; |
| 10982 |
} |
| 10983 |
return($wavheader, $H); |
| 10984 |
} |
| 10985 |
######################################################################## |
| 10986 |
# |
| 10987 |
# Analyze the wav for chunks and gaps. Fill an array @times with two |
| 10988 |
# blank separated numbers in each entry. These two numbers are the |
| 10989 |
# time in seconds of the starting point of sound and the duration of |
| 10990 |
# that chunk. This is important because this number will be used to seek |
| 10991 |
# to that point of sound from the beginning of the file, not form the |
| 10992 |
# end point of the previous cycle. For each chunk we start to seek from |
| 10993 |
# zero; this is not a large time loss, seeking is fast. |
| 10994 |
# |
| 10995 |
# There were weeks of testing to manage Audio::FindChunks-0.03, gave up! |
| 10996 |
# The behaviour seems inconsistent. For example: ripping all tracks of |
| 10997 |
# the CD: Lamb - What Sound gave *no* gaps. When ripping only the last |
| 10998 |
# track, gaps were immediately detected. |
| 10999 |
# First, changing the sec_per_chunk value gave better results, but |
| 11000 |
# suddenly no gaps at all were found. The threshold stayed at zero. |
| 11001 |
# So then I introduced a loop where the sec_per_chunk increases from |
| 11002 |
# 0.1 - 0.8 in steps of 0.1, and in the same time, the threshold from |
| 11003 |
# 0.1 in steps of 0.2 only if the resulting threshold is less than 100. |
| 11004 |
# You say that this is ugly? No, it is extremely ugly. And all this |
| 11005 |
# because there might be a caching problem in Audio::FindChunks-0.03? |
| 11006 |
# Then, testing on a 64bit machine was a drawback, no gaps at all. |
| 11007 |
# |
| 11008 |
# So I gave up this sophisticated and "fully documented" PM, and coded a |
| 11009 |
# few lines to solve the problem. This code might not be useful to |
| 11010 |
# split manually recorded vinyl, but the results for ripped CDs are |
| 11011 |
# much more precise than with the PM. Of course, I can test only on a |
| 11012 |
# limited range of CDs, and I have no classical or Death-Metal to test. |
| 11013 |
# But for the following CDs (and hundreds of CDs with no gaps --> |
| 11014 |
# thousands of tracks and not one was erroneously split) this |
| 11015 |
# snippet works. (See below for explanation!) |
| 11016 |
# |
| 11017 |
# |
| 11018 |
# Testreport (CDs with correctly split ghost songs): |
| 11019 |
# |
| 11020 |
# OK: 2raumwohnung: in wirklich: 11 |
| 11021 |
# OK: A Camp: Colonia: 12 |
| 11022 |
# OK: Archive: Londonium: 13 |
| 11023 |
# OK: Archive: Take My Head: 10 |
| 11024 |
# OK: Aromabar: 1!: 15 (2 ghost songs!) |
| 11025 |
# OK: Autour de Lucie: L'échappée belle: 11 |
| 11026 |
# OK: Camille: Sac des filles: 11 |
| 11027 |
# OK: Camille: Le fil: 15 (Ghost song without zero-gap... not splitted!) |
| 11028 |
# OK: Cibelle: Cibelle: 11 |
| 11029 |
# OK: Dining Rooms: Experiments In Ambient Soul: 13 |
| 11030 |
# OK: Distain!: [li:quíd]: 11 |
| 11031 |
# OK: Falco: Out of the Dark: 9+1 renamed |
| 11032 |
# OK: Fiji: Fijical: 11+1 renamed |
| 11033 |
# OK: Helena: Née dans la nature: 11 |
| 11034 |
# OK: Imogen Heap: Ellipse (disc 2): Half Life (instr.):13+1 renamed |
| 11035 |
# OK: Jay-Jay Johanson: Antenna: 10 |
| 11036 |
# OK: Laika: Sound Of The Satellites: 12 |
| 11037 |
# OK: Lamb: Debut: 10 |
| 11038 |
# OK: Lamb: Fear Of Fours: 00 Hidden Track |
| 11039 |
# OK: Lamb: What Sound: 10 |
| 11040 |
# OK: Little Boots: Hands: 12+1 renamed |
| 11041 |
# OK: Lunik: Preparing To Leave: 11 |
| 11042 |
# OK: Lunik: Weather: 11 |
| 11043 |
# OK: Mãozinha: Aerosferas: 11 |
| 11044 |
# OK: Massive Attack: 100th Window: 09 |
| 11045 |
# OK: Moby: Last Night: 14 |
| 11046 |
# OK: Moloko: Do You Like My Tight Sweater?: 17+1 |
| 11047 |
# OK: Olive: Trickle: 12 |
| 11048 |
# OK: Ott: Blumenkraft: 00 Hidden Track |
| 11049 |
# OK: Rightous Men: Disconnected: 11 |
| 11050 |
# OK: Samia Farah: Samia Farah: 12 |
| 11051 |
# OK: Saint Etienne: Heart Failed [In The Back Of A Taxi] (CD1): 03 |
| 11052 |
# OK: Stereo Total: Musique Automatique 15 |
| 11053 |
# OK: Yoshinori Sunahara: Pan Am: 09 |
| 11054 |
# |
| 11055 |
# Deleted blank tracks: |
| 11056 |
# |
| 11057 |
# OK: 22 Pistepirkko: Ralley of Love: 0 (hidden track - copy protection) |
| 11058 |
# OK: NPG: New Power Soul: all blank tracks |
| 11059 |
# OK: Dave Matthews Band: Under the Table and Dreaming: all blank tracks |
| 11060 |
# |
| 11061 |
# |
| 11062 |
sub get_chunks { |
| 11063 |
my ($tcn, $trn) = @_; |
| 11064 |
my @times = (); |
| 11065 |
$trn = $trn . ".rip"; |
| 11066 |
my ($wavheader, $H) = get_wavhead("$trn", 0); |
| 11067 |
|
| 11068 |
# How do I analyze the chunks? I calculate a threshold value called |
| 11069 |
# $thresh of the actual chunk by summing up its binary values - perl is |
| 11070 |
# so cool! Then this value is used to calculate a kind of mean value |
| 11071 |
# with the previous one --> $deltathre, but only at every 5th value, to |
| 11072 |
# cancel short fluctuations. If the actual $thresh value lies |
| 11073 |
# within a small range compared to the deltathre, a weight (counter) |
| 11074 |
# will be increased and deltathre will be raised to cancel (not so) |
| 11075 |
# short peak changes (not only) at the end of a track (gap). |
| 11076 |
# Silence is defined as (not so) significant drop of the $thresh value |
| 11077 |
# compared to the $deltathre one. Use an upper cut-off value $maxthresh |
| 11078 |
# (70% of maximum value) to allow deltathre to grow (quickly) in the |
| 11079 |
# beginning but prevent to bailing out immediately. During the track, a |
| 11080 |
# weight will help to prevent the same. If the silence lasts more than |
| 11081 |
# 4 seconds, the detected startsound and duration values will be pushed |
| 11082 |
# into the @times array. In version 3.7.0 additionally a $trimcn is |
| 11083 |
# introduced, to enable RipIT to trim tracks at beginning and end. This |
| 11084 |
# can now be done, if the --extend and --prepend options are set to 0, |
| 11085 |
# not recommended. If the lead-in/out and gaps are really zero, the |
| 11086 |
# $trimcn will correct the values pushed into @times which correspond to |
| 11087 |
# the time points where volume is below the thresh value, but not yet |
| 11088 |
# zero. With these values a --prepend or --extend of 0 would cut off a |
| 11089 |
# few fractions of seconds. This may still happen, if the lead-in/out |
| 11090 |
# and/or gap is not really zero. How should RipIT know about silence? |
| 11091 |
# If lead-in/out and gaps are zero, $trimcn will slightly enlarge the |
| 11092 |
# chunks of sound and trimming should not cut away sound, hopefully. |
| 11093 |
# As far as I understand, the unpack function returns the number of bits |
| 11094 |
# set -- in a bit vector. Using this value, I stress that we deal with |
| 11095 |
# bits and not bytes for the variables $thresh and $maxthresh. Therefore |
| 11096 |
# $maxthresh is multiplied by 8! |
| 11097 |
|
| 11098 |
my $bindata; |
| 11099 |
my $bytecn = 0; |
| 11100 |
my $silencecn = 0; |
| 11101 |
my $chunkcn = 0; |
| 11102 |
my $chunksize = 0.1; # Chunk size in seconds. |
| 11103 |
my $chunkbyte = $H->{byte_per_sec} * $chunksize; |
| 11104 |
my $chunklen = 0; |
| 11105 |
my $leadinflag = 0; |
| 11106 |
my $startsnd = 0; |
| 11107 |
my $soundflag = 0; |
| 11108 |
my $deltathre = $H->{byte_per_sec} * $chunksize; |
| 11109 |
my $totalthre = 0; |
| 11110 |
my $trimcn = 0; |
| 11111 |
my $weight = 1; |
| 11112 |
my $maxthresh = $deltathre * 8 * 0.7; |
| 11113 |
|
| 11114 |
open(IN, "< $wavdir/$trn") or print "Can't open $trn: $!\n"; |
| 11115 |
binmode(IN); |
| 11116 |
seek(IN, 44, 0); |
| 11117 |
while(read(IN, $bindata, $chunkbyte)) { |
| 11118 |
$chunkcn++; |
| 11119 |
my $thresh = unpack('%32b*', $bindata); |
| 11120 |
$totalthre += $thresh / 1000 if($thresh < $maxthresh * 1.1 ); |
| 11121 |
$weight++ |
| 11122 |
if($thresh > 0.8 * $deltathre && $thresh < 1.1 * $deltathre); |
| 11123 |
$deltathre = ($deltathre * $weight + $thresh) / (1 + $weight) |
| 11124 |
if($thresh > 0.8 * $deltathre && $thresh < $maxthresh && |
| 11125 |
$chunkcn =~ /[05]$/); |
| 11126 |
# According to the $thresh value, decide whether it is sound or |
| 11127 |
# not. |
| 11128 |
# The if-condition itself is a little more tricky. We have to |
| 11129 |
# force this condition at beginning, even if there is no silence! |
| 11130 |
# Why this? If there is a lead-in with immediate sound but very |
| 11131 |
# short interruptions, the switch of $soundflag = 1 will be the |
| 11132 |
# reason that the startsnd will increase, although it shouldn't, |
| 11133 |
# it should stay at 0.0, but will become 0.1 or similar in this |
| 11134 |
# case! In this way, if the interruptions are short (< 4s) nothing |
| 11135 |
# will happen, and the fact that $startsnd will not set back to |
| 11136 |
# zero until a true gap will be found, $startsnd will not be |
| 11137 |
# recalculated in the else-part. |
| 11138 |
if($thresh < 0.8 * $deltathre || $bytecn == 0) { |
| 11139 |
$silencecn += $chunkbyte; |
| 11140 |
# If thresh is zero, use an other counter to calculate more |
| 11141 |
# precise values. |
| 11142 |
$trimcn += $chunkbyte if($thresh == 0); |
| 11143 |
$leadinflag = 1 if($thresh == 0 && $bytecn == 0); |
| 11144 |
# If the gap is 4 seconds long, save values in array @times, or |
| 11145 |
# to detect lead-ins shorter than 4s, set the $soundflag to 1. |
| 11146 |
if($silencecn == $H->{byte_per_sec} * 4 || |
| 11147 |
$bytecn < $H->{byte_per_sec} * 4) { |
| 11148 |
$chunklen = ($bytecn - $silencecn) / $H->{byte_per_sec}; |
| 11149 |
# Otherwise: |
| 11150 |
$chunklen = ($bytecn - $trimcn) / $H->{byte_per_sec} |
| 11151 |
if($trimcn < $silencecn && $trimcn > 0); |
| 11152 |
$chunklen -= $startsnd; |
| 11153 |
# The chunk of sound must be longer than 4.0 seconds! |
| 11154 |
if($chunklen < 4) { |
| 11155 |
$chunklen = 0; |
| 11156 |
} |
| 11157 |
else { |
| 11158 |
push(@times, "$startsnd $chunklen"); |
| 11159 |
# Prevent re-entering a duplicate last entry outside of |
| 11160 |
# the loop. |
| 11161 |
$startsnd = 0; |
| 11162 |
} |
| 11163 |
# Chunk of sound has been detected. Doing this here and not |
| 11164 |
# just above where $starsnd is set to zero, will enable |
| 11165 |
# detection of short lead-ins! |
| 11166 |
$soundflag = 1; |
| 11167 |
# From now on we are in silence! |
| 11168 |
# Set $trimcn to $silencecn to detect another difference |
| 11169 |
# at the end of the gap, if the gap consists of zeros. |
| 11170 |
$trimcn = $silencecn if($bytecn > $H->{byte_per_sec} * 4); |
| 11171 |
} |
| 11172 |
# We will stay in this condition, until... |
| 11173 |
} |
| 11174 |
else { |
| 11175 |
# ... sound is detected (again)! |
| 11176 |
# If we get here the first time, save the $startsound time. |
| 11177 |
if($soundflag == 1 && $startsnd == 0) { |
| 11178 |
if($trimcn < $silencecn && |
| 11179 |
$trimcn > (0.8 * $silencecn)) { |
| 11180 |
$startsnd = ($bytecn - $silencecn + $trimcn) / |
| 11181 |
$H->{byte_per_sec}; |
| 11182 |
} |
| 11183 |
elsif($startsnd == 0) { |
| 11184 |
$startsnd = $bytecn / $H->{byte_per_sec}; |
| 11185 |
} |
| 11186 |
$soundflag = 0; |
| 11187 |
} |
| 11188 |
$trimcn = 0; |
| 11189 |
$silencecn = 0; |
| 11190 |
} |
| 11191 |
$bytecn += $chunkbyte; |
| 11192 |
} |
| 11193 |
# Calculations for the last (only) chunk of sound. |
| 11194 |
$chunklen = ($bytecn - $silencecn) / $H->{byte_per_sec}; |
| 11195 |
# Otherwise (slightly different condition than above): |
| 11196 |
$chunklen = ($bytecn - $trimcn) / $H->{byte_per_sec} |
| 11197 |
if($trimcn < $silencecn); |
| 11198 |
$chunklen -= $startsnd; |
| 11199 |
push(@times, "$startsnd $chunklen") unless($startsnd == 0); |
| 11200 |
push(@times, "$startsnd $chunklen") unless(@times); |
| 11201 |
$times[0] =~ s/^0.1/0/ if($startsnd == 0.1 && $leadinflag == 0); |
| 11202 |
|
| 11203 |
my $tracklen = int(($framelist[$tcn] - $framelist[$tcn - 1]) / 7.5); |
| 11204 |
$tracklen = int($framelist[$tcn] / 7.5) if($tcn == 0); |
| 11205 |
$tracklen /= 10; |
| 11206 |
|
| 11207 |
# I don't like it, but it might be OK to delete very short tracks |
| 11208 |
# if their content is blank. |
| 11209 |
if(-s "$wavdir/$trn" < 200000 && $totalthre >= 200) { |
| 11210 |
$chunkcn = 0; |
| 11211 |
$totalthre = 0; |
| 11212 |
open(IN, "< $wavdir/$trn") or print "Can't open $trn: $!\n"; |
| 11213 |
binmode(IN); |
| 11214 |
seek(IN, 44, 0); |
| 11215 |
while(read(IN, $bindata, 2)) { |
| 11216 |
$chunkcn++; |
| 11217 |
my $thresh = unpack('%32b*', $bindata); |
| 11218 |
$thresh = 0 if($thresh >= 14); |
| 11219 |
$totalthre += $thresh; |
| 11220 |
} |
| 11221 |
$totalthre = $totalthre * 4 / $chunkcn; |
| 11222 |
} |
| 11223 |
|
| 11224 |
if($totalthre < 200) { |
| 11225 |
unlink("$wavdir/$trn") or print "Can't delete $trn: $!\n"; |
| 11226 |
if($verbose >= 1) { |
| 11227 |
print "\n\nRipIT found blank track $trn\n", |
| 11228 |
"and decided to delete it.\n\n"; |
| 11229 |
} |
| 11230 |
if($inf > 0) { |
| 11231 |
my $infile = $trn; |
| 11232 |
$infile =~ s/.wav$/.inf/i; |
| 11233 |
if(-f "$wavdir/$infile") { |
| 11234 |
unlink("$wavdir/$infile") or |
| 11235 |
print "Can't delete $infile: $!\n"; |
| 11236 |
} |
| 11237 |
} |
| 11238 |
open(ERO,">>$wavdir/error.log") |
| 11239 |
or print "Can not append to file $wavdir/error.log\"!\n"; |
| 11240 |
print ERO "Blankflag = $tcn\nTrack $tcn on CD failed!\n"; |
| 11241 |
close(ERO); |
| 11242 |
log_info("blank track deleted: $wavdir/$trn"); |
| 11243 |
$times[0] = "blank"; |
| 11244 |
return(@times); |
| 11245 |
} |
| 11246 |
|
| 11247 |
if($verbose >= 2) { |
| 11248 |
printf "\n%02d:%02d:%02d: ", |
| 11249 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 11250 |
print "RipIT found following chunks for track\n", |
| 11251 |
"$trn (${tracklen}s long):\nstart duration (in seconds)\n"; |
| 11252 |
log_info("\nRipIT found following chunks for track:"); |
| 11253 |
log_info("$trn (${tracklen}s long):\nstart duration (in seconds)"); |
| 11254 |
foreach(@times) { |
| 11255 |
my @interval = split(/ /, $_); |
| 11256 |
printf("%5.1f %9.1f\n", $interval[0], $interval[1]); |
| 11257 |
log_info("@interval"); |
| 11258 |
} |
| 11259 |
} |
| 11260 |
return(@times); |
| 11261 |
} |
| 11262 |
######################################################################## |
| 11263 |
# |
| 11264 |
# Split the wav into chunks of sound and rename all of them to |
| 11265 |
# "Ghost Song $counter.wav". |
| 11266 |
# |
| 11267 |
sub split_chunks { |
| 11268 |
my ($tcn, $trn, $cdtocn, @times) = @_; |
| 11269 |
my $album = clean_all($album_utf8); |
| 11270 |
$album = clean_name($album); |
| 11271 |
$album = clean_chars($album) if($chars); |
| 11272 |
$album =~ s/ /_/g if($underscore == 1); |
| 11273 |
my $artist = clean_all($artist_utf8); |
| 11274 |
$artist = clean_name($artist); |
| 11275 |
$artist = clean_chars($artist) if($chars); |
| 11276 |
$artist =~ s/ /_/g if($underscore == 1); |
| 11277 |
my $bindata; |
| 11278 |
my ($wavheader, $H) = get_wavhead("$trn.rip", 1); |
| 11279 |
my $chunksize = 0.1; # Chunk size in seconds. |
| 11280 |
my $chunkbyte = $H->{byte_per_sec} * $chunksize; |
| 11281 |
my $chunkcn = 0; |
| 11282 |
# Save the track length of the original track to be compared with the |
| 11283 |
# chunks of sound. |
| 11284 |
my $tracklen = int($H->{data_size} / $H->{byte_per_sec} * 10); |
| 11285 |
$tracklen /= 10; |
| 11286 |
# Let the other processes know, if the track has been shorten or not. |
| 11287 |
my $shorten = 0; |
| 11288 |
|
| 11289 |
# We may need to delete a single index in array @times: |
| 11290 |
my $prn_flag = 0; |
| 11291 |
my @times_new = (); |
| 11292 |
my $times_cn = 0; |
| 11293 |
foreach(@times) { |
| 11294 |
# Remember: each entry of @times has the form: "start duration" |
| 11295 |
# where start is the beginning of sound in seconds, and duration |
| 11296 |
# the time in seconds. |
| 11297 |
my @interval = split(/ /, $_); |
| 11298 |
if($interval[0] >= $prepend) { |
| 11299 |
$interval[0] -= $prepend; |
| 11300 |
$interval[1] += $prepend; |
| 11301 |
} |
| 11302 |
else{ |
| 11303 |
$interval[1] += $interval[0]; |
| 11304 |
$interval[0] = 0; |
| 11305 |
} |
| 11306 |
# Extend the interval, this might result in a too long interval. |
| 11307 |
$interval[1] += $extend; |
| 11308 |
# Don't allow too long end-times, this can happen with the above |
| 11309 |
# extend command. |
| 11310 |
if($interval[0] + $interval[1] > $tracklen) { |
| 11311 |
$interval[1] = $tracklen - $interval[0]; |
| 11312 |
} |
| 11313 |
# Update the times array. |
| 11314 |
$times_new[$times_cn] = "$interval[0] $interval[1]"; |
| 11315 |
$times_cn++; |
| 11316 |
# Modify the @times array. |
| 11317 |
$_ = "$interval[0] $interval[1]"; |
| 11318 |
|
| 11319 |
# Don't split if interval is larger than track length from cdtoc. |
| 11320 |
# Use a threshold of $extend + $prepend. Reasonable? |
| 11321 |
if(($tracklen - $extend - $prepend) <= $interval[1] || |
| 11322 |
$interval[1] < 3) { |
| 11323 |
print "Track $tcn not splitted.\n\n" |
| 11324 |
if($verbose >= 1); |
| 11325 |
log_info("Track $tcn not splitted."); |
| 11326 |
|
| 11327 |
# Merge track into album-track if $cdcue == 1. |
| 11328 |
merge_wav($trn, $chunkbyte, $album) if($cdcue == 1); |
| 11329 |
# Do not return here, more pairs might exist in @times... |
| 11330 |
# return($shorten, @times); |
| 11331 |
# And further more the array still holds the additional pair |
| 11332 |
# not used. |
| 11333 |
|
| 11334 |
# Clean up counters: |
| 11335 |
$prn_flag--; # Do not print. |
| 11336 |
pop(@times_new) if($times_cn > 1); # Remove pair if no ghost. |
| 11337 |
next; |
| 11338 |
} |
| 11339 |
|
| 11340 |
# Use array @secondlist to save new track lengths to allow the |
| 11341 |
# ripper (!) process to write correct playlist files. The array |
| 11342 |
# will be printed to ghost.log for encoder process in the "next" |
| 11343 |
# subroutine called rename_chunks, see below. |
| 11344 |
if($chunkcn == 0) { |
| 11345 |
$secondlist[$tcn - 1] = int($interval[1]) if($hiddenflag == 0); |
| 11346 |
$secondlist[$tcn] = int($interval[1]) if($hiddenflag == 1); |
| 11347 |
} |
| 11348 |
else { |
| 11349 |
push(@secondlist, int($interval[1])); |
| 11350 |
} |
| 11351 |
|
| 11352 |
# Print info message about what is going on (only once): |
| 11353 |
if($verbose >= 2 && $chunkcn == 0) { |
| 11354 |
print "Splitting \"$trn\" into " . ($#times + 1) . " chunk"; |
| 11355 |
print ".\n" if($#times == 0); |
| 11356 |
print "s.\n" unless($#times == 0); |
| 11357 |
} |
| 11358 |
if($chunkcn == 0) { |
| 11359 |
log_info("Splitting \"$trn\" into " . ($#times + 1) . " chunk.") |
| 11360 |
if($#times == 0); |
| 11361 |
log_info("Splitting \"$trn\" into " . ($#times + 1) . " chunks.") |
| 11362 |
unless($#times == 0); |
| 11363 |
} |
| 11364 |
if($verbose >= 4) { |
| 11365 |
print "\n\nUsing these values for chunk $chunkcn:\n"; |
| 11366 |
printf("%5.1f %5.1f\n", $interval[0], $interval[1]); |
| 11367 |
} |
| 11368 |
log_info("\nUsing these values for chunk $chunkcn:"); |
| 11369 |
log_info("@interval"); |
| 11370 |
|
| 11371 |
# Prepare the filename for output. |
| 11372 |
my $outr = "Ghost Song $chunkcn"; |
| 11373 |
$outr = get_trackname($tcn, $outr, 0, $artist, $outr) . ".rip"; |
| 11374 |
|
| 11375 |
if($cdcue == 1) { |
| 11376 |
my $file_size = -s "$wavdir/$album.wav"; |
| 11377 |
print "\nAppending $outr to album.wav, yet $file_size B large", |
| 11378 |
".\n" if($verbose > 4); |
| 11379 |
log_info("\nAppending $outr to album.wav, yet $file_size B large.\n"); |
| 11380 |
open(OUT, ">> $wavdir/$album.wav") |
| 11381 |
or print "Can not append to file ", |
| 11382 |
"\"$wavdir/$album.wav\"!\n"; |
| 11383 |
} |
| 11384 |
else { |
| 11385 |
open(OUT, "> $wavdir/$outr"); |
| 11386 |
} |
| 11387 |
binmode(OUT); |
| 11388 |
|
| 11389 |
# From now on count in bytes instead of seconds. |
| 11390 |
$interval[0] = $interval[0] * $H->{byte_per_sec} + 44; |
| 11391 |
$interval[1] = $interval[1] * $H->{byte_per_sec}; |
| 11392 |
|
| 11393 |
# Edit header according to size of the chunk. |
| 11394 |
$H->{data_size} = $interval[1]; |
| 11395 |
$H->{file_size_8} = $H->{data_size} + 36; |
| 11396 |
substr($wavheader, 4, 4) = pack("V", $H->{file_size_8}); |
| 11397 |
substr($wavheader, 40, 4) = pack("V", $H->{data_size}); |
| 11398 |
|
| 11399 |
# This is nuts, don't know why this happens, but the chunk sizes |
| 11400 |
# in the RIFF header are sometimes one byte smaller leading to an |
| 11401 |
# unpaired number. This causes flac to fail on splitted tracks! |
| 11402 |
# So let's do it the ugly way: add 1 byte and rewrite the header. |
| 11403 |
# What goes wrong in the above substr command or elsewhere? |
| 11404 |
# If someone finds out, please submit code. |
| 11405 |
my $loopcn = 0; |
| 11406 |
# Initialization: |
| 11407 |
($H->{RIFF_header}, $H->{file_size_8}, $H->{WAV_header}, |
| 11408 |
$H->{FMT_header}, $H->{WAV_chunk_size}, $H->{WAV_type}, |
| 11409 |
$H->{channels}, $H->{sample_rate}, $H->{byte_per_sec}, |
| 11410 |
$H->{block_align}, $H->{bit_per_sample}, $H->{data_header}, |
| 11411 |
$H->{data_size} |
| 11412 |
) = unpack("a4Va4a4VvvVVvva4V", $wavheader); |
| 11413 |
|
| 11414 |
while($loopcn < 10 and $H->{data_size} ne $interval[1]) { |
| 11415 |
if($verbose > 5) { |
| 11416 |
print "\nFatal error, unpair chunk sizes detected\n", |
| 11417 |
"in new header of ghost track part $chunkcn:\n", |
| 11418 |
"\$H->{data_size} is $H->{data_size} ", |
| 11419 |
"instead of chunk length = $interval[1]!\n", |
| 11420 |
"The new wav header has following entries:\n"; |
| 11421 |
print "$_ \t -> $H->{$_} \n" foreach(keys %$H); |
| 11422 |
print "\n"; |
| 11423 |
} |
| 11424 |
log_info("\nFatal error, unpair chunk sizes detected\n", |
| 11425 |
"in new header of ghost track part $chunkcn:\n", |
| 11426 |
"\$H->{data_size} is $H->{data_size} ", |
| 11427 |
"instead of chunk length = $interval[1]!\n", |
| 11428 |
"The new wav header has following entries:"); |
| 11429 |
log_info("$_ \t -> $H->{$_}") foreach(keys %$H); |
| 11430 |
log_info("\n"); |
| 11431 |
|
| 11432 |
$H->{data_size} = 2 * $interval[1] - $H->{data_size}; |
| 11433 |
# $H->{data_size} = $interval[1] + 1; |
| 11434 |
$H->{file_size_8} = $H->{data_size} + 36; |
| 11435 |
|
| 11436 |
substr($wavheader, 4, 4) = pack("V", $H->{file_size_8}); |
| 11437 |
substr($wavheader, 40, 4) = pack("V", $H->{data_size}); |
| 11438 |
|
| 11439 |
($H->{RIFF_header}, $H->{file_size_8}, $H->{WAV_header}, |
| 11440 |
$H->{FMT_header}, $H->{WAV_chunk_size}, $H->{WAV_type}, |
| 11441 |
$H->{channels}, $H->{sample_rate}, $H->{byte_per_sec}, |
| 11442 |
$H->{block_align}, $H->{bit_per_sample}, $H->{data_header}, |
| 11443 |
$H->{data_size} |
| 11444 |
) = unpack("a4Va4a4VvvVVvva4V", $wavheader); |
| 11445 |
|
| 11446 |
$loopcn++; |
| 11447 |
} |
| 11448 |
|
| 11449 |
if($loopcn >= 9 && $verbose >= 3) { |
| 11450 |
print "\nMajor problem writing the wav header."; |
| 11451 |
log_info("\nMajor problem writing the wav header."); |
| 11452 |
if($wcoder =~ /2/) { |
| 11453 |
print "\nWon't split this track because Flac will fail."; |
| 11454 |
log_info("\nWon't split this track because Flac will fail."); |
| 11455 |
# Reset the @times array. |
| 11456 |
@interval = (0, $tracklen); |
| 11457 |
@times_new = ("0 $tracklen"); |
| 11458 |
if($chunkcn == 0) { |
| 11459 |
$secondlist[$tcn - 1] = $interval[1] if($hiddenflag == 0); |
| 11460 |
$secondlist[$tcn] = $interval[1] if($hiddenflag == 1); |
| 11461 |
} |
| 11462 |
else { |
| 11463 |
pop(@secondlist); |
| 11464 |
} |
| 11465 |
} |
| 11466 |
else { |
| 11467 |
print "\nTrying to continue anyway.\n"; |
| 11468 |
log_info("\nTrying to continue anyway.\n"); |
| 11469 |
} |
| 11470 |
} |
| 11471 |
# Return with a default pair number in the @times array in case |
| 11472 |
# wav header could not be written. |
| 11473 |
return($shorten, @times_new) if($loopcn >= 9 && $wcoder =~ /2/); |
| 11474 |
|
| 11475 |
syswrite(OUT, $wavheader, 44) if($cdcue == 0); |
| 11476 |
log_info("The length of data is $interval[1]."); |
| 11477 |
log_info("The final wav header has following entries:"); |
| 11478 |
log_info("$_ \t -> $H->{$_}") foreach(keys %$H); |
| 11479 |
log_info("\n"); |
| 11480 |
if($verbose > 5) { |
| 11481 |
print "The length of data is $interval[1].\nThe final wav", |
| 11482 |
"header of chunk $chunkcn has following entries:\n"; |
| 11483 |
print "$_ \t -> $H->{$_} \n" foreach (keys %$H); |
| 11484 |
print "\n"; |
| 11485 |
} |
| 11486 |
|
| 11487 |
# Seek from beginning of file to start of sound of chunk. |
| 11488 |
open(IN, "< $wavdir/$trn.rip") or |
| 11489 |
print "Can't open $trn.rip: $!\n"; |
| 11490 |
binmode(IN); |
| 11491 |
print "Seeking to: ${interval[0]} B, starting from 0B.\n" |
| 11492 |
if($verbose >= 4); |
| 11493 |
log_info("Seeking to: ${interval[0]} B, starting from 0 B."); |
| 11494 |
seek(IN, $interval[0], 0) or |
| 11495 |
print "\nCould not seek in file IN: $!\n"; |
| 11496 |
|
| 11497 |
# I don't know if it is good to read so many bytes a time, but it |
| 11498 |
# is faster than reading byte by byte. |
| 11499 |
my $start_snd = $interval[0]; |
| 11500 |
$interval[1] = $interval[1] + $interval[0]; |
| 11501 |
while(read(IN, $bindata, $chunkbyte) && |
| 11502 |
$interval[0] < $interval[1] - 1) { |
| 11503 |
$interval[0] += $chunkbyte; |
| 11504 |
# Before we write the data, check it, because it happens that |
| 11505 |
# seek does not seek to a pair number, starting to read an |
| 11506 |
# unpair (right-channel) byte. In this case, the wav will sound |
| 11507 |
# like pure noise, and adding or deleting a single byte right |
| 11508 |
# after the header will heal the wav. |
| 11509 |
# The amount of data in the read $bindata seems OK, only the |
| 11510 |
# position is wrong. |
| 11511 |
my $pos = tell(IN); |
| 11512 |
if($pos !~ /[02468]$/) { |
| 11513 |
print "After chunkbyte = <$chunkbyte> reached pos <$pos>.\n" |
| 11514 |
if($verbose > 5); |
| 11515 |
log_info("After chunkbyte = <$chunkbyte> reached pos <$pos>.\n"); |
| 11516 |
# Move one byte! |
| 11517 |
read(IN, my $dummybyte, 1); |
| 11518 |
$pos = tell(IN); |
| 11519 |
print "After 1 byte read reached pos <$pos>.\n" |
| 11520 |
if($verbose > 5); |
| 11521 |
} |
| 11522 |
print OUT $bindata; |
| 11523 |
} |
| 11524 |
print "This chunk should be ", $interval[0] - $start_snd, |
| 11525 |
"B large.\n" if($verbose > 5); |
| 11526 |
log_info("This chunk should be ", $interval[0] - $start_snd, |
| 11527 |
"B large."); |
| 11528 |
log_info("Remember, steps in the size of $chunkbyte B are used."); |
| 11529 |
close(OUT); |
| 11530 |
write_wavhead("$wavdir/$album.wav") if($cdcue == 1); |
| 11531 |
$chunkcn++; |
| 11532 |
$prn_flag++; |
| 11533 |
} |
| 11534 |
close(IN); |
| 11535 |
@times = @times_new; |
| 11536 |
|
| 11537 |
open(ERO,">>$wavdir/ghost.log") |
| 11538 |
or print "Can not append to file \"$wavdir/error.log\"!\n"; |
| 11539 |
if($#times == 0) { |
| 11540 |
if($prn_flag > 0) { |
| 11541 |
print "Track $tcn successfully trimmed.\n\n" if($verbose >= 1); |
| 11542 |
log_info("Track $tcn successfully trimmed.\n\n"); |
| 11543 |
print ERO "Splitflag = $tcn\n"; |
| 11544 |
$shorten = 1; |
| 11545 |
} |
| 11546 |
} |
| 11547 |
else { |
| 11548 |
if($prn_flag > 0) { |
| 11549 |
print "Track $tcn successfully splitted.\n\n" if($verbose >= 1); |
| 11550 |
log_info("Track $tcn successfully splitted.\n\n"); |
| 11551 |
print ERO "Ghostflag = $tcn\n"; |
| 11552 |
$shorten = 1; |
| 11553 |
} |
| 11554 |
} |
| 11555 |
close(ERO); |
| 11556 |
return($shorten, @times); |
| 11557 |
} |
| 11558 |
######################################################################## |
| 11559 |
# |
| 11560 |
# Rename the chunks called "XY Ghost Song $chunkcn" to the appropriate |
| 11561 |
# file name according to the track-template. |
| 11562 |
# |
| 11563 |
sub rename_chunks { |
| 11564 |
|
| 11565 |
# The ripper uses a copy of the initial @seltrack array, called |
| 11566 |
# @tracksel. Ghost songs will be added in @seltrack, but not in array |
| 11567 |
# @tracksel. This means: the ripper will behave as usual and not |
| 11568 |
# care about additional songs. Note that splitted songs are of course |
| 11569 |
# already ripped, so we do not need to notify the ripper process |
| 11570 |
# about ghost songs. |
| 11571 |
|
| 11572 |
# If there is only one chunk, this chunk gets the true track name. |
| 11573 |
# If there is more than one chunk the first chunk gets the true |
| 11574 |
# track name. Note that this is not done here but only when back in |
| 11575 |
# the ripper process right after this routine. |
| 11576 |
# This kind of renaming might be wrong, but who knows? |
| 11577 |
# Renaming of all subsequent chunks is done here. |
| 11578 |
# If there are only two chunks, the second will get the suffix |
| 11579 |
# Ghost Song without a counter. If the track name holds a slash, the |
| 11580 |
# track name will be splitted, the first part will be used for the |
| 11581 |
# actual track, the second part for the ghost song. |
| 11582 |
# If there are more than two chunks, a counter will be added. |
| 11583 |
|
| 11584 |
# Another problem is with data tracks. Then the track-counter will |
| 11585 |
# not increase for ghost songs, as we expect for ghost songs that |
| 11586 |
# appear in the last track, sad (see below). |
| 11587 |
|
| 11588 |
my ($tcn, $trn, $rip_wavnam, $cdtocn, $cue_point, $shorten, $artistag, $trt, @times) = @_; |
| 11589 |
|
| 11590 |
my $album = clean_all($album_utf8); |
| 11591 |
$album = clean_name($album); |
| 11592 |
$album = clean_chars($album) if($chars); |
| 11593 |
$album =~ s/ /_/g if($underscore == 1); |
| 11594 |
my $artist = clean_all($artist_utf8); |
| 11595 |
$artist = clean_name($artist); |
| 11596 |
$artist = clean_chars($artist) if($chars); |
| 11597 |
$artist =~ s/ /_/g if($underscore == 1); |
| 11598 |
|
| 11599 |
my $chunkcn = 0; |
| 11600 |
my $ghostflag = 0; |
| 11601 |
my $outr = "Ghost Song $chunkcn"; |
| 11602 |
$outr = get_trackname($tcn, $outr, 0, $artist, $outr) . ".rip"; |
| 11603 |
# The first track must be renamed to the *.rip file because the |
| 11604 |
# ripper will rename it to wav! |
| 11605 |
log_info("perl rename \"$wavdir/$outr\", \"$wavdir/$trn.rip\""); |
| 11606 |
rename("$wavdir/$outr", "$wavdir/$trn.rip"); |
| 11607 |
|
| 11608 |
# Write the toc file in case $cdtoc == 1. |
| 11609 |
# Note that $rip_wavnam is the name the actual snd file will get |
| 11610 |
# in the ripping process. |
| 11611 |
if($cdtoc == 1) { |
| 11612 |
my $cdtocartis = $artistag; |
| 11613 |
oct_char($cdtocartis); |
| 11614 |
my $cdtoctitle = $trt; |
| 11615 |
$cdtoctitle = clean_name($cdtoctitle); |
| 11616 |
oct_char($cdtoctitle); |
| 11617 |
open(CDTOC, ">>$wavdir/cd.toc") |
| 11618 |
or print "Can not append to file \"$wavdir/cd.toc\"!\n"; |
| 11619 |
print CDTOC "\n//Track $cdtocn:\nTRACK AUDIO\n"; |
| 11620 |
print CDTOC "TWO_CHANNEL_AUDIO\nCD_TEXT {LANGUAGE 0 {\n\t\t"; |
| 11621 |
print CDTOC "TITLE \"$cdtoctitle\"\n\t\t"; |
| 11622 |
print CDTOC "PERFORMER \"$cdtocartis\"\n\t}\n}\n"; |
| 11623 |
print CDTOC "FILE \"$rip_wavnam.wav\" 0\n"; |
| 11624 |
print CDTOC "ISRC " . $isrcs[$tcn-1] . "\n" |
| 11625 |
if($isrc == 1 and defined $isrcs[$tcn-1] and $isrcs[$tcn-1] ne ""); |
| 11626 |
close(CDTOC); |
| 11627 |
} |
| 11628 |
|
| 11629 |
# Writing the cue file in case $cdcue == 1 (forcing option ghost). |
| 11630 |
# The value $cue_point has already been calculated and should be |
| 11631 |
# correct. |
| 11632 |
if($cdcue > 0) { |
| 11633 |
my $points = track_length($cue_point, 2); |
| 11634 |
my $cuetrackno = sprintf("%02d", $cdtocn); |
| 11635 |
open(CDCUE ,">>$wavdir/cd.cue") |
| 11636 |
or print "Can not append to file \"$wavdir/cd.cue\"!\n"; |
| 11637 |
print CDCUE "TRACK $cuetrackno AUDIO\n", |
| 11638 |
" TITLE \"$trt\"\n", |
| 11639 |
" PERFORMER \"$artistag\"\n", |
| 11640 |
" INDEX 01 $points\n"; |
| 11641 |
close(CDCUE); |
| 11642 |
} |
| 11643 |
# Extract first entry of array @times. If only one chunk has been |
| 11644 |
# trimmed, we are done, array @times is empty now. |
| 11645 |
my $interval = shift(@times); |
| 11646 |
# Calculate length of this track for next cue point (start point of |
| 11647 |
# next track). A similar calculation will be done below in case the |
| 11648 |
# @times array has more than one entry i.e. more chunks are found. |
| 11649 |
my ($start, $chunk_length) = split(/ /, $interval); |
| 11650 |
$chunk_length *= 75; |
| 11651 |
if($shorten == 0) { |
| 11652 |
if($span) { |
| 11653 |
print "Track length detection in sub rename_chunks because ", |
| 11654 |
"span > 0 form wav file <$wavdir/$trn>.\n" |
| 11655 |
if($verbose > 5); |
| 11656 |
my ($wavheader, $H) = get_wavhead("$trn.rip", 0); |
| 11657 |
$chunk_length = int($H->{data_size} / $H->{byte_per_sec} * 10); |
| 11658 |
$chunk_length *= 7.5; |
| 11659 |
} |
| 11660 |
else { |
| 11661 |
# Note that for the last track [$tcn + 1] is not defined |
| 11662 |
# and not needed, so chunk_length must not be calculated. |
| 11663 |
$chunk_length = $framelist[$tcn + 1] - $framelist[$tcn] |
| 11664 |
if($hiddenflag == 0 && defined $framelist[$tcn + 1]); |
| 11665 |
$chunk_length = $framelist[$tcn] - $framelist[$tcn - 1] |
| 11666 |
if($hiddenflag == 1); |
| 11667 |
} |
| 11668 |
} |
| 11669 |
$cue_point += $chunk_length; |
| 11670 |
|
| 11671 |
# If there are two or more chunks then array @times is not empty and |
| 11672 |
# has more entries. Proceed and hack all necessary arrays needed for |
| 11673 |
# the encoder process. They will be written in the ghost.log file. |
| 11674 |
# Note that with only one ghost song no counter is needed in the |
| 11675 |
# filename. The suffix can now be wav instead of rip. |
| 11676 |
# TODO: check if final track name already exists. |
| 11677 |
# So, the track name of a new ghost song shall have the same leading |
| 11678 |
# track number to identify its origin, except if it comes from |
| 11679 |
# the last track, then the leading number may increase! Define a new |
| 11680 |
# ghost counter $gcn. |
| 11681 |
my $gcn = $tcn; |
| 11682 |
$ghostflag = 1 if($tcn == $#framelist); |
| 11683 |
$ghostflag = 1 if($hiddenflag == 1 && $tcn == $#framelist - 1); |
| 11684 |
$gcn++ if($ghostflag == 1); |
| 11685 |
$chunkcn++; |
| 11686 |
|
| 11687 |
my ($delimiter, $dummy) = check_va(0) if($vatag > 0); |
| 11688 |
my $delim = ""; |
| 11689 |
if(defined $delimiter) { |
| 11690 |
$delim = quotemeta($delimiter); |
| 11691 |
$vatag = 0 if($delim eq ""); |
| 11692 |
} |
| 11693 |
foreach (@times) { |
| 11694 |
my $trt = $tracktags[$tcn - 1]; |
| 11695 |
$trt = $tracktags[$tcn] if($hiddenflag == 1); |
| 11696 |
# Some tracks with ghost songs contain the ghost song name after |
| 11697 |
# a slash. Prevent splitting in case VA-style is used because |
| 11698 |
# tracks might have been splitted already and chunks of snd will |
| 11699 |
# mix up with chunks of meta data used differently. New in 4.0 |
| 11700 |
my @ghostnames = split(/\//, $trt) |
| 11701 |
if($vatag == 0 or $vatag == 1 and $delim and $delim !~ /\//); |
| 11702 |
if($ghostnames[$chunkcn]) { |
| 11703 |
$trt = $ghostnames[$chunkcn]; |
| 11704 |
$trt =~ s/^\s+|\s+$//; |
| 11705 |
# Split the tracktag into its artist part and track part if |
| 11706 |
# VA style is used and delimiter is not a slash. Note, here |
| 11707 |
# to only aim is to get the track artist, the tracktag trt |
| 11708 |
# will not be used as track stuff is handled with @ghostnames. |
| 11709 |
my $trackartist = ""; |
| 11710 |
my $dummy; |
| 11711 |
if($va_flag > 0 && $trt =~ /$delim/) { |
| 11712 |
($trackartist, $dummy) = split_tags($trt, $delim); |
| 11713 |
} |
| 11714 |
# We need to update the track-arrays as the first track will |
| 11715 |
# get only its name without the ghost songs name. |
| 11716 |
if($chunkcn == 1) { |
| 11717 |
my $prev_trt = $ghostnames[0]; |
| 11718 |
$prev_trt =~ s/^\s+|\s+$//; |
| 11719 |
$tracktags[$#tracktags] = $prev_trt; |
| 11720 |
my $prev_trn = $prev_trt; |
| 11721 |
$prev_trn = clean_all($prev_trn); |
| 11722 |
$prev_trn = clean_name($prev_trn); |
| 11723 |
$prev_trn = clean_chars($prev_trn) if($chars); |
| 11724 |
$prev_trn = change_case($prev_trn, "t"); |
| 11725 |
$prev_trn =~ s/ /_/g if($underscore == 1); |
| 11726 |
$tracklist[$#tracklist] = $prev_trn; |
| 11727 |
# The cdtoc needs to be hacked too. |
| 11728 |
if($cdtoc == 1) { |
| 11729 |
open(CDTOC, "<$wavdir/cd.toc") |
| 11730 |
or print "Can not read file cd.toc!\n"; |
| 11731 |
my @toclines = <CDTOC>; |
| 11732 |
close(CDTOC); |
| 11733 |
open(CDTOC, ">$wavdir/cd.toc") |
| 11734 |
or print "Can't append to file \"$wavdir/cd.toc\"!\n"; |
| 11735 |
foreach (@toclines) { |
| 11736 |
last if(/\/\/Track\s$cdtocn:/); |
| 11737 |
print CDTOC $_; |
| 11738 |
} |
| 11739 |
my $cdtocartis = $artistag; |
| 11740 |
oct_char($cdtocartis); |
| 11741 |
my $cdtoctitle = $prev_trt; |
| 11742 |
$cdtoctitle = clean_name($cdtoctitle); |
| 11743 |
oct_char($cdtoctitle); |
| 11744 |
my $cdtoctrckartis = $trackartist; |
| 11745 |
oct_char($cdtoctrckartis); |
| 11746 |
$prev_trn = get_trackname($tcn, $prev_trn, 0, $artist, $prev_trn); |
| 11747 |
print CDTOC "\n//Track $cdtocn:\nTRACK AUDIO\n"; |
| 11748 |
print CDTOC "TWO_CHANNEL_AUDIO\nCD_TEXT {LANGUAGE 0 {\n\t\t"; |
| 11749 |
print CDTOC "TITLE \"$cdtoctitle\"\n\t\t"; |
| 11750 |
print CDTOC "PERFORMER \"$cdtocartis\""; |
| 11751 |
print CDTOC "\n\t\tSONGWRITER \"$cdtoctrckartis\"" |
| 11752 |
if($vatag > 0 and $cdtoctrckartis ne ""); |
| 11753 |
print CDTOC "\n\t}\n}\n"; |
| 11754 |
print CDTOC "FILE \"$prev_trn.wav\" 0\n"; |
| 11755 |
close(CDTOC); |
| 11756 |
} |
| 11757 |
# The cdcue needs to be hacked too, because the track length |
| 11758 |
# is different if the track has been splitted. |
| 11759 |
# Hey, wait a second. No track length update here, only |
| 11760 |
# track name is updated...? Confused. |
| 11761 |
if($cdcue > 0) { |
| 11762 |
open(CDCUE, "<$wavdir/cd.cue") |
| 11763 |
or print "Can not read file cd.cue!\n"; |
| 11764 |
my @cuelines = <CDCUE>; |
| 11765 |
close(CDCUE); |
| 11766 |
open(CDCUE, ">$wavdir/cd.cue") |
| 11767 |
or print "Can't write to file \"$wavdir/cd.cue\"!\n"; |
| 11768 |
my $cuetrackno = sprintf("%02d", $cdtocn); |
| 11769 |
my $track_flag = 0; |
| 11770 |
foreach (@cuelines) { |
| 11771 |
if($track_flag == 1) { |
| 11772 |
print " TITLE \"$prev_trt\"\n"; |
| 11773 |
print CDCUE " TITLE \"$prev_trt\"\n"; |
| 11774 |
$track_flag = 0; |
| 11775 |
} |
| 11776 |
else { |
| 11777 |
print $_; |
| 11778 |
print CDCUE $_; |
| 11779 |
} |
| 11780 |
$track_flag = 1 if(/^TRACK\s$cuetrackno\sAUDIO/); |
| 11781 |
} |
| 11782 |
close(CDCUE); |
| 11783 |
} |
| 11784 |
} |
| 11785 |
} |
| 11786 |
else { |
| 11787 |
# Split the tracktag into its artist part and track part if |
| 11788 |
# VA style is used. |
| 11789 |
if(defined $delim && $delim ne "" && $va_flag > 0 && $trt =~ /$delim/) { |
| 11790 |
($artist, $trt) = split_tags($trt, $delim); |
| 11791 |
} |
| 11792 |
# The name for the tags will be with originating track name as |
| 11793 |
# prefix. |
| 11794 |
$trt = $trt . " - Ghost Song" if($#times == 0); |
| 11795 |
$trt = $trt . " - Ghost Song $chunkcn" if($#times > 0); |
| 11796 |
} |
| 11797 |
# The actual track name will be slightly different. |
| 11798 |
$trn = $trt; |
| 11799 |
$trn = clean_all($trn); |
| 11800 |
$trn = clean_name($trn); |
| 11801 |
$trn = clean_chars($trn) if($chars); |
| 11802 |
$trn = change_case($trn, "t"); |
| 11803 |
$trn =~ s/ /_/g if($underscore == 1); |
| 11804 |
my $track_delim = $delimiter; |
| 11805 |
$track_delim =~ s/\//-/g if(defined $delimiter && $delimiter =~ /\//); |
| 11806 |
push(@seltrack, $gcn); |
| 11807 |
# Again, when snipping around with VA schemes, we need to |
| 11808 |
# mirror the delimiters: |
| 11809 |
my $delim_l_close = $delimiter; # for the track List |
| 11810 |
my $delim_t_close = $delimiter; # for the track Tags |
| 11811 |
$delim_l_close =~ tr/\({\[/)}]/ if(defined $delimiter); |
| 11812 |
$delim_t_close =~ tr/\({\[/)}]/ if(defined $delimiter); |
| 11813 |
# Brainfood. |
| 11814 |
if(defined $delim && $delim ne "" && $vatag > 0 and $vatag % 2 == 0) { |
| 11815 |
if($track_delim =~ /[([{]/) { |
| 11816 |
push(@tracklist, "$trn $track_delim$artist$delim_l_close"); |
| 11817 |
push(@tracktags, "$trt $delimiter$artist$delim_t_close"); |
| 11818 |
} |
| 11819 |
else { |
| 11820 |
push(@tracklist, "$trn $track_delim $artist"); |
| 11821 |
push(@tracktags, "$trt $delimiter $artist"); |
| 11822 |
} |
| 11823 |
} |
| 11824 |
elsif(defined $delim && $delim ne "" && $vatag > 0 and $vatag % 2 == 1) { |
| 11825 |
if($track_delim =~ /[([{]/) { |
| 11826 |
push(@tracklist, "$artist $track_delim$trn$delim_l_close"); |
| 11827 |
push(@tracktags, "$artist $delimiter$trt$delim_t_close"); |
| 11828 |
} |
| 11829 |
else { |
| 11830 |
push(@tracklist, "$artist $track_delim $trn"); |
| 11831 |
push(@tracktags, "$artist $delimiter $trt"); |
| 11832 |
} |
| 11833 |
} |
| 11834 |
else { |
| 11835 |
push(@tracklist, $trn); |
| 11836 |
push(@tracktags, "$trt"); |
| 11837 |
} |
| 11838 |
# Remember: $outr is the output track name of the splitted wav. |
| 11839 |
$outr = "Ghost Song $chunkcn"; |
| 11840 |
if($vatag > 0) { |
| 11841 |
$outr = get_trackname($tcn, $outr, 0, "Various", $outr) . ".rip"; |
| 11842 |
} |
| 11843 |
else { |
| 11844 |
$outr = get_trackname($tcn, $outr, 0, $artist, $outr) . ".rip"; |
| 11845 |
} |
| 11846 |
$trn = get_trackname($gcn, $tracklist[$#tracklist], 0, $artist, $tracklist[$#tracklist]); |
| 11847 |
log_info("perl rename \"$wavdir/$outr\", \"$wavdir/$trn.wav\""); |
| 11848 |
rename("$wavdir/$outr", "$wavdir/$trn.wav"); |
| 11849 |
md5_sum("$wavdir", "$trn.wav", 0) if($md5sum == 1 && $wav == 1); |
| 11850 |
if($cdtoc > 0 || $cdcue > 0) { |
| 11851 |
$cdtocn++; |
| 11852 |
} |
| 11853 |
if($cdtoc == 1) { |
| 11854 |
my $cdtocartis = $artistag; |
| 11855 |
oct_char($cdtocartis); |
| 11856 |
my $cdtoctitle = $trt; |
| 11857 |
$cdtoctitle = clean_name($cdtoctitle); |
| 11858 |
oct_char($cdtoctitle); |
| 11859 |
my $cdtoctrckartis = $artist; |
| 11860 |
oct_char($cdtoctrckartis); |
| 11861 |
open(CDTOC, ">>$wavdir/cd.toc") |
| 11862 |
or print "Can not append to file \"$wavdir/cd.toc\"!\n"; |
| 11863 |
print CDTOC "\n//Track $cdtocn:\nTRACK AUDIO\n"; |
| 11864 |
print CDTOC "TWO_CHANNEL_AUDIO\nCD_TEXT {LANGUAGE 0 {\n\t\t"; |
| 11865 |
print CDTOC "TITLE \"$cdtoctitle\"\n\t\t"; |
| 11866 |
print CDTOC "PERFORMER \"$cdtocartis\""; |
| 11867 |
print CDTOC "\n\t\tSONGWRITER \"$cdtoctrckartis\"" if($vatag > 0); |
| 11868 |
print CDTOC "\n\t}\n}\n"; |
| 11869 |
print CDTOC "FILE \"$trn.wav\" 0\n"; |
| 11870 |
# No writing of ISRC here, as ghost songs won't have any ISRCs |
| 11871 |
# provided. |
| 11872 |
# print CDTOC "ISRC " . $isrcs[$_-1] . "\n" |
| 11873 |
# if($isrc == 1 and $isrcs[$_-1] ne ""); |
| 11874 |
close(CDTOC); |
| 11875 |
} |
| 11876 |
if($cdcue > 0) { |
| 11877 |
my $points = track_length($cue_point, 2); |
| 11878 |
my $cuetrackno = sprintf("%02d", $cdtocn); |
| 11879 |
open(CDCUE ,">>$wavdir/cd.cue") |
| 11880 |
or print "Can not append to file \"$wavdir/cd.cue\"!\n"; |
| 11881 |
print CDCUE "TRACK $cuetrackno AUDIO\n", |
| 11882 |
" TITLE \"$trt\"\n", |
| 11883 |
" PERFORMER \"$artistag\"\n", |
| 11884 |
" INDEX 01 $points\n"; |
| 11885 |
close(CDCUE); |
| 11886 |
} |
| 11887 |
|
| 11888 |
# Calculate length of track for next cue point. No problems with |
| 11889 |
# option span here as the chunks have been splitted and effective |
| 11890 |
# lengths are detected. |
| 11891 |
my ($start, $chunk_length) = split(/ /, $_); |
| 11892 |
$cue_point += $chunk_length * 75; |
| 11893 |
print "\nNext cue_point based on interval: $cue_point.\n", |
| 11894 |
"This is: ", track_length($cue_point, 2), ".\n" |
| 11895 |
if($verbose > 5); |
| 11896 |
$gcn++ if($ghostflag == 1); |
| 11897 |
$chunkcn++; |
| 11898 |
} |
| 11899 |
print "\n\n" if($verbose >= 2); |
| 11900 |
log_info("\n"); |
| 11901 |
|
| 11902 |
# Is there another way to communicate with the encoder process (child |
| 11903 |
# process) than writing log files? |
| 11904 |
# Oops: As we use ghost.log to collect info about trimmed tracks, we |
| 11905 |
# can't overwrite existing ghost.log with updated info about arrays, |
| 11906 |
# we need to reed it first. |
| 11907 |
my @ghostlines = (); |
| 11908 |
if(-r "$wavdir/ghost.log") { |
| 11909 |
open(ERR, "$wavdir/ghost.log") |
| 11910 |
or print "Can't read $wavdir/ghost.log.\n"; |
| 11911 |
@ghostlines = <ERR>; |
| 11912 |
close(ERR); |
| 11913 |
} |
| 11914 |
|
| 11915 |
open(GHOST, ">$wavdir/ghost.log") |
| 11916 |
or print "Can not append to file ghost.log!\n"; |
| 11917 |
print GHOST "Array seltrack: @seltrack\n"; |
| 11918 |
print GHOST "Array secondlist: @secondlist\n"; |
| 11919 |
print GHOST "Array tracklist: $_\n" foreach(@tracklist); |
| 11920 |
print GHOST "Array tracktags: $_\n" foreach(@tracktags); |
| 11921 |
foreach(@ghostlines) { |
| 11922 |
chomp; |
| 11923 |
print GHOST "$_\n" unless(/^Array\s/); |
| 11924 |
} |
| 11925 |
close(GHOST); |
| 11926 |
return($cdtocn, $cue_point); |
| 11927 |
} |
| 11928 |
######################################################################## |
| 11929 |
# |
| 11930 |
# Check if the necessary modules are available. |
| 11931 |
# |
| 11932 |
sub init_mod { |
| 11933 |
print "\n" if($verbose >= 1); |
| 11934 |
|
| 11935 |
# We need to know if coverart is added to mp3 or ogg because those |
| 11936 |
# encoders can't handle picture tags. The pictures are added after |
| 11937 |
# encoding process using an additional module. |
| 11938 |
# Create a coverart array supposing its exactly in the same order as |
| 11939 |
# encoder. |
| 11940 |
my $mp3art = 0; |
| 11941 |
my $oggart = 0; |
| 11942 |
my $wvpart = 0; |
| 11943 |
if($coverart && ($lameflag == 1 || $oggflag == 1 || $wvpflag == 1)) { |
| 11944 |
my @coverart = split(/,/, $coverart); |
| 11945 |
for(my $c = 0; $c <= $#coder; $c++) { |
| 11946 |
if(defined $coverart[$c]) { |
| 11947 |
$mp3art = 1 if($coder[$c] == 0 && $coverart[$c] > 0); |
| 11948 |
$oggart = 1 if($coder[$c] == 1 && $coverart[$c] > 0); |
| 11949 |
$wvpart = 1 if($coder[$c] == 6 && $coverart[$c] > 0); |
| 11950 |
} |
| 11951 |
} |
| 11952 |
} |
| 11953 |
|
| 11954 |
eval { require CDDB_get }; |
| 11955 |
if($@) { |
| 11956 |
print "\nPerl module CDDB_get not found. Needed for", |
| 11957 |
"\nchecking the CD-ID and retrieving the CDDB", |
| 11958 |
"\nentry from freeDB.org!", |
| 11959 |
"\nPlease install CDDB_get from your closest", |
| 11960 |
"\nCPAN mirror before trying again.", |
| 11961 |
"\nInstall by hand or e.g. type as root:", |
| 11962 |
"\nperl -MCPAN -e 'install CDDB_get'\n\n"; |
| 11963 |
exit 0; |
| 11964 |
} |
| 11965 |
$@ = (); |
| 11966 |
|
| 11967 |
eval { require XML::Simple }; |
| 11968 |
if($@) { |
| 11969 |
print "\nPerl module XML::Simple not found. Needed for", |
| 11970 |
"\nchecking trackoffsets with multi disc releases when using", |
| 11971 |
"\nMusicbrainz.", |
| 11972 |
"\nPlease install XML::Simple and dependencies ", |
| 11973 |
"\nfrom your closest CPAN mirror or submission will fail.", |
| 11974 |
"\nInstall by hand or e.g. type as root:", |
| 11975 |
"\nperl -MCPAN -e 'install XML::Simple'\n\n"; |
| 11976 |
sleep 2; |
| 11977 |
} |
| 11978 |
$@ = (); |
| 11979 |
|
| 11980 |
eval { require LWP::Simple }; |
| 11981 |
if($@) { |
| 11982 |
print "\nPerl module LWP::Simple not found. Needed for", |
| 11983 |
"\nchecking free categories before submitting CDDB", |
| 11984 |
"\nentries to freeDB.org!", |
| 11985 |
"\nPlease install LWP::Simple and dependencies ", |
| 11986 |
"\nfrom your closest CPAN mirror or submission will fail.", |
| 11987 |
"\nInstall by hand or e.g. type as root:", |
| 11988 |
"\nperl -MCPAN -e 'install LWP::Simple'\n\n"; |
| 11989 |
sleep 2; |
| 11990 |
} |
| 11991 |
$@ = (); |
| 11992 |
|
| 11993 |
eval { require Digest::MD5 } if($md5sum == 1 or $verify > 1); |
| 11994 |
if($@) { |
| 11995 |
print "\nPlease install Digest::MD5 and dependencies", |
| 11996 |
"\nfrom your closest CPAN mirror before trying again with", |
| 11997 |
"\noption --md5sum. Install by hand or e.g. type as root:", |
| 11998 |
"\nperl -MCPAN -e 'install Digest::MD5'\n\n"; |
| 11999 |
exit 0; |
| 12000 |
} |
| 12001 |
$@ = (); |
| 12002 |
|
| 12003 |
eval { require Unicode::UCD } if($utftag == 0); |
| 12004 |
if($@) { |
| 12005 |
print "\nPlease install Unicode::UCD and dependencies", |
| 12006 |
"\nfrom your closest CPAN mirror before trying again with", |
| 12007 |
"\noption --noutftag. Install by hand or e.g. type as", |
| 12008 |
"root: \nperl -MCPAN -e 'install Unicode::UCD'\n\n"; |
| 12009 |
exit 0; |
| 12010 |
} |
| 12011 |
$@ = (); |
| 12012 |
|
| 12013 |
eval { require Text::Unidecode } if($utftag == 0); |
| 12014 |
if($@) { |
| 12015 |
print "\nPlease install Text::Unidecode and dependencies", |
| 12016 |
"\nfrom your closest CPAN mirror before trying again with", |
| 12017 |
"\noption --noutftag. Install by hand or e.g. type as", |
| 12018 |
"root: \nperl -MCPAN -e 'install Text::Unidecode'\n\n"; |
| 12019 |
exit 0; |
| 12020 |
} |
| 12021 |
$@ = (); |
| 12022 |
|
| 12023 |
eval { use MP3::Tag; |
| 12024 |
MP3::Tag->config(write_v24 => 1); |
| 12025 |
MP3::Tag->config(id3v23_unsync => 1); |
| 12026 |
} if(($mp3art == 1 || $mp3tags[0]) && $lameflag == 1); |
| 12027 |
if($@) { |
| 12028 |
print "\nPlease install MP3::Tag and dependencies", |
| 12029 |
"\nfrom your closest CPAN mirror before trying again with", |
| 12030 |
"\noption --coverart. Install by hand or e.g. type as", |
| 12031 |
"root: \nperl -MCPAN -e 'install MP3::Tag'\n\n"; |
| 12032 |
exit 0; |
| 12033 |
} |
| 12034 |
$@ = (); |
| 12035 |
|
| 12036 |
eval { require MIME::Base64 } if($oggart == 1 && $oggflag == 1); |
| 12037 |
if($@) { |
| 12038 |
print "\nPlease install MIME::Base64 and dependencies", |
| 12039 |
"\nfrom your closest CPAN mirror before trying again with", |
| 12040 |
"\noption --coverart. Install by hand or e.g. type as", |
| 12041 |
"root: \nperl -MCPAN -e 'install MIME::Base64'\n\n"; |
| 12042 |
exit 0; |
| 12043 |
} |
| 12044 |
|
| 12045 |
eval { require WebService::MusicBrainz::Release } if($mb == 1); |
| 12046 |
if($@) { |
| 12047 |
print "\nPlease install WebService::MusicBrainz and dependencies", |
| 12048 |
"\nfrom your closest CPAN mirror before trying again with", |
| 12049 |
"\noption --mb.", |
| 12050 |
"\nInstall by hand or using force because using (as root):", |
| 12051 |
"\nperl -MCPAN -e 'install WebService::MusicBrainz'", |
| 12052 |
"\nmight fail.\n\n"; |
| 12053 |
exit 0; |
| 12054 |
} |
| 12055 |
|
| 12056 |
eval { require MusicBrainz::DiscID } if($mb == 1); |
| 12057 |
if($@) { |
| 12058 |
print "\nError message is: $@\n" if($verbose > 4); |
| 12059 |
print "\nPlease install MusicBrainz::DiscID and dependencies", |
| 12060 |
"\nfrom your closest CPAN mirror; e.g. type as root:", |
| 12061 |
"\nperl -MCPAN -e 'install MusicBrainz::DiscID'\n\n"; |
| 12062 |
sleep 2; |
| 12063 |
# exit 0; |
| 12064 |
} |
| 12065 |
|
| 12066 |
if($wvpart == 1) { |
| 12067 |
open(WAVPAK, "wavpack 2>&1|"); |
| 12068 |
my @response = <WAVPAK>; |
| 12069 |
close(WAVPAK); |
| 12070 |
chomp(my $wvpver = join('', grep(s/.*Linux\sVersion\s//, @response))); |
| 12071 |
$wvpver =~ s/(\d+\.\d).*/$1/; |
| 12072 |
if($wvpver <= 4.5) { |
| 12073 |
print "\n\nWarning:\nThere is a newer version of wavpack ", |
| 12074 |
"with coverart support.\nThis version of wavpack does ", |
| 12075 |
"not write binary-tags.\n\n" if($verbose > 0); |
| 12076 |
sleep 3; |
| 12077 |
} |
| 12078 |
} |
| 12079 |
|
| 12080 |
if($cdtext == 1) { |
| 12081 |
my $cdinfo = `which cd-info`; |
| 12082 |
unless($cdinfo) { |
| 12083 |
print "\n\nWarning:\ncd-info (from cdda2wav or cdio-utils ", |
| 12084 |
"package (libcdio-utils)) not installed!\n\n" |
| 12085 |
if($verbose > 0); |
| 12086 |
sleep 3; |
| 12087 |
} |
| 12088 |
} |
| 12089 |
|
| 12090 |
if(defined $coversize && $coversize =~ /\d+/) { |
| 12091 |
my $convert = `which convert`; |
| 12092 |
unless($convert) { |
| 12093 |
print "\n\nWarning:\nconvert (from ImageMagick package) ", |
| 12094 |
"not installed!\n\n" |
| 12095 |
if($verbose > 0); |
| 12096 |
sleep 3; |
| 12097 |
} |
| 12098 |
my $identify = `which identify`; |
| 12099 |
unless($identify) { |
| 12100 |
print "\n\nWarning:\nidentfy (from ImageMagick package) ", |
| 12101 |
"not installed!\n\n" |
| 12102 |
if($verbose > 0); |
| 12103 |
sleep 3; |
| 12104 |
} |
| 12105 |
} |
| 12106 |
|
| 12107 |
if($multi == 1) { |
| 12108 |
eval "use Color::Output"; |
| 12109 |
if($@) {print "\nColor::Output not installed!\n"}; |
| 12110 |
eval "Color::Output::Init"; |
| 12111 |
} |
| 12112 |
|
| 12113 |
print "\n\n" if($verbose >= 1); |
| 12114 |
} |
| 12115 |
######################################################################## |
| 12116 |
# |
| 12117 |
# Check if lame is installed. |
| 12118 |
# |
| 12119 |
sub check_enc { |
| 12120 |
my ($enc, $suf) = @_; |
| 12121 |
unless(log_system("$enc --version > /dev/null 2>&1")) { |
| 12122 |
$enc = "\u$enc"; |
| 12123 |
if(!@pcoder && "@coder" =~ /0/ || "@pcoder" =~ /0/) { |
| 12124 |
print "\n$enc not found (needed to encode $suf)!", |
| 12125 |
"\nUse oggenc instead (to generate ogg)?\n"; |
| 12126 |
my $ans = "x"; |
| 12127 |
while($ans !~ /^[yn]$/i) { |
| 12128 |
print "Do you want to try oggenc? [y/n] (y) "; |
| 12129 |
$ans = <STDIN>; |
| 12130 |
chomp $ans; |
| 12131 |
$ans = "y" if($ans eq ""); |
| 12132 |
} |
| 12133 |
if($ans eq "y") { |
| 12134 |
my $coders = "@coder"; |
| 12135 |
my $pcoders = "@pcoder"; |
| 12136 |
if($coders !~ /1/) { |
| 12137 |
$coders =~ s/0/1/g if($enc =~ /Lame/); |
| 12138 |
$coders =~ s/3/1/g if($enc =~ /Faac/); |
| 12139 |
} |
| 12140 |
else { |
| 12141 |
$coders =~ s/0//g if($enc =~ /Lame/); |
| 12142 |
$coders =~ s/3//g if($enc =~ /Faac/); |
| 12143 |
} |
| 12144 |
if($pcoders !~ /1/) { |
| 12145 |
$pcoders =~ s/0/1/g if($enc =~ /Lame/); |
| 12146 |
$pcoders =~ s/3/1/g if($enc =~ /Faac/);; |
| 12147 |
} |
| 12148 |
else { |
| 12149 |
$pcoders =~ s/0//g if($enc =~ /Lame/); |
| 12150 |
$pcoders =~ s/3//g if($enc =~ /Faac/); |
| 12151 |
} |
| 12152 |
$lameflag = -1; |
| 12153 |
@coder = split(/ /, $coders); |
| 12154 |
@pcoder = split(/ /, $pcoders); |
| 12155 |
} |
| 12156 |
else { |
| 12157 |
print "\n", |
| 12158 |
"Install $enc or choose another encoder with option", |
| 12159 |
"\n", |
| 12160 |
"-c 1 for oggenc, -c 2 for flac, -c 3 for faac,", |
| 12161 |
"\n", |
| 12162 |
"-c 4 for mp4als, -c 5 for Musepack,", |
| 12163 |
"\n", |
| 12164 |
"-c 6 for Wavpack or -c 7 for ffmpeg.", |
| 12165 |
"\n\n", |
| 12166 |
"Type ripit --help or check the manpage for info.", |
| 12167 |
"\n\n"; |
| 12168 |
exit; |
| 12169 |
} |
| 12170 |
} |
| 12171 |
else { |
| 12172 |
$lameflag = -1; |
| 12173 |
} |
| 12174 |
} |
| 12175 |
} |
| 12176 |
######################################################################## |
| 12177 |
# |
| 12178 |
# Create MD5sum file of sound files. |
| 12179 |
# |
| 12180 |
sub md5_sum { |
| 12181 |
my $sepdir = shift; |
| 12182 |
my $filename = shift; |
| 12183 |
my $ripcomplete = shift; |
| 12184 |
my $suffix = $filename; |
| 12185 |
$suffix =~ s/^.*\.//; |
| 12186 |
chomp($filename); |
| 12187 |
chomp($suffix); |
| 12188 |
|
| 12189 |
# What name should the md5 file get? |
| 12190 |
my @paths = split(/\//, $sepdir); |
| 12191 |
my $md5file = $paths[$#paths] . " - " . $suffix . ".md5"; |
| 12192 |
$md5file =~ s/ /_/g if($underscore == 1); |
| 12193 |
|
| 12194 |
return unless(-r "$sepdir/$filename"); |
| 12195 |
|
| 12196 |
open(my $SND, '<', "$sepdir/$filename") or |
| 12197 |
print "Can not open $sepdir/$filename: $!\n"; |
| 12198 |
binmode($SND); |
| 12199 |
if($verbose > 3) { |
| 12200 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 12201 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 12202 |
print ENCLOG "\n\nCalculating MD5-sum for $filename..."; |
| 12203 |
close(ENCLOG); |
| 12204 |
} |
| 12205 |
else { |
| 12206 |
print "\nCalculating MD5-sum for $filename..."; |
| 12207 |
} |
| 12208 |
} |
| 12209 |
my $md5 = Digest::MD5->new->addfile($SND)->hexdigest; |
| 12210 |
close($SND); |
| 12211 |
|
| 12212 |
my $time = sprintf "%02d:%02d:%02d:", |
| 12213 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 12214 |
|
| 12215 |
if($verbose > 3) { |
| 12216 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 12217 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 12218 |
print ENCLOG "\n$time The MD5-sum for $filename is: $md5.\n\n"; |
| 12219 |
close(ENCLOG); |
| 12220 |
} |
| 12221 |
else { |
| 12222 |
print "\n$time The MD5-sum for $filename is: $md5.\n"; |
| 12223 |
} |
| 12224 |
} |
| 12225 |
log_info("$time MD5-sum for $filename is: $md5."); |
| 12226 |
open(MD5SUM,">>$sepdir/$md5file") |
| 12227 |
or print "Can not append to file \"$sepdir/$md5file\"!\n"; |
| 12228 |
print MD5SUM "$md5 *$filename\n"; |
| 12229 |
close(MD5SUM); |
| 12230 |
} |
| 12231 |
######################################################################## |
| 12232 |
# |
| 12233 |
# Sort the options and fill the globopt array according to the encoder. |
| 12234 |
# Remember, the list of options for one encoder stated several times is |
| 12235 |
# separated by commas. The *opt arrays below will have only one |
| 12236 |
# entry, if the corresponding encoder has been stated only once. If one |
| 12237 |
# needs to find globopt in the code, search for "$globopt[" and not for |
| 12238 |
# @globopt. |
| 12239 |
# |
| 12240 |
sub check_options { |
| 12241 |
my @flacopt = split(/,/, $flacopt); |
| 12242 |
my @lameopt = split(/,/, $lameopt); |
| 12243 |
my @oggencopt = split(/,/, $oggencopt); |
| 12244 |
my @faacopt = split(/,/, $faacopt); |
| 12245 |
my @mp4alsopt = split(/,/, $mp4alsopt); |
| 12246 |
my @museopt = split(/,/, $museopt); |
| 12247 |
my @wavpacopt = split(/,/, $wavpacopt); |
| 12248 |
my @ffmpegopt = split(/,/, $ffmpegopt); |
| 12249 |
$faacopt[0] = " " unless($faacopt[0]); |
| 12250 |
$flacopt[0] = " " unless($flacopt[0]); |
| 12251 |
$lameopt[0] = " " unless($lameopt[0]); |
| 12252 |
$mp4alsopt[0] = " " unless($mp4alsopt[0]); |
| 12253 |
$museopt[0] = " " unless($museopt[0]); |
| 12254 |
$oggencopt[0] = " " unless($oggencopt[0]); |
| 12255 |
$wavpacopt[0] = " " unless($wavpacopt[0]); |
| 12256 |
$ffmpegopt[0] = " " unless($ffmpegopt[0]); |
| 12257 |
for(my $c=0; $c<=$#coder; $c++) { |
| 12258 |
if($coder[$c] == 0) { |
| 12259 |
if($preset) { |
| 12260 |
$lameopt[0] .= " --preset $preset"; |
| 12261 |
} |
| 12262 |
else { |
| 12263 |
$lameopt[0] .= " --vbr-$vbrmode" if($vbrmode); |
| 12264 |
$lameopt[0] .= " -b $bitrate" if($bitrate ne "off"); |
| 12265 |
$lameopt[0] .= " -B $maxrate" if($maxrate != 0); |
| 12266 |
$lameopt[0] .= " -V $quality[$c]" |
| 12267 |
if($qualame ne "off" && $vbrmode); |
| 12268 |
$lameopt[0] .= " -q $quality[$c]" |
| 12269 |
if($quality[$c] ne "off" && !$vbrmode); |
| 12270 |
} |
| 12271 |
# Nice output of Lame-encoder messages. |
| 12272 |
if($quality[$c] eq "off" && $lameopt[0] =~ /\s*-q\s\d\s*/) { |
| 12273 |
$quality[$c] = $lameopt[0]; |
| 12274 |
$quality[$c] =~ s/^.*-q\s(\d).*$/$1/; |
| 12275 |
} |
| 12276 |
$lameopt[0] =~ s/^\s*//; |
| 12277 |
push(@globopt, $lameopt[0]); |
| 12278 |
shift(@lameopt); |
| 12279 |
} |
| 12280 |
elsif($coder[$c] == 1) { |
| 12281 |
$oggencopt[0] .= " -q $quality[$c]" if($quality[$c] ne "off"); |
| 12282 |
$oggencopt[0] .= " -M $maxrate" if($maxrate != 0); |
| 12283 |
$oggencopt[0] =~ s/^\s*//; |
| 12284 |
push(@globopt, $oggencopt[0]); |
| 12285 |
shift(@oggencopt); |
| 12286 |
} |
| 12287 |
elsif($coder[$c] == 2) { |
| 12288 |
$flacopt[0] .= " -$quality[$c]" if($quality[$c] ne "off"); |
| 12289 |
$flacopt[0] =~ s/^\s*//; |
| 12290 |
push(@globopt, $flacopt[0]); |
| 12291 |
shift(@flacopt); |
| 12292 |
} |
| 12293 |
elsif($coder[$c] == 3) { |
| 12294 |
$faacopt[0] .= " -q $quality[$c]" if($quality[$c] ne "off"); |
| 12295 |
$faacopt[0] =~ s/^\s*//; |
| 12296 |
push(@globopt, $faacopt[0]); |
| 12297 |
shift(@faacopt); |
| 12298 |
} |
| 12299 |
elsif($coder[$c] == 4) { |
| 12300 |
$mp4alsopt[0] .= " -q $quality[$c]" if($quality[$c] ne "off"); |
| 12301 |
$mp4alsopt[0] =~ s/^\s*//; |
| 12302 |
push(@globopt, $mp4alsopt[0]); |
| 12303 |
shift(@mp4alsopt); |
| 12304 |
} |
| 12305 |
elsif($coder[$c] == 5) { |
| 12306 |
$museopt[0] .= " --quality $quality[$c]" if($quality[$c] ne "off"); |
| 12307 |
$museopt[0] =~ s/^\s*//; |
| 12308 |
push(@globopt, $museopt[0]); |
| 12309 |
shift(@museopt); |
| 12310 |
} |
| 12311 |
elsif($coder[$c] == 6) { |
| 12312 |
push(@globopt, $wavpacopt[0]); |
| 12313 |
shift(@wavpacopt); |
| 12314 |
} |
| 12315 |
elsif($coder[$c] == 7) { |
| 12316 |
push(@globopt, $ffmpegopt[0]); |
| 12317 |
shift(@ffmpegopt); |
| 12318 |
} |
| 12319 |
} |
| 12320 |
} |
| 12321 |
######################################################################## |
| 12322 |
# |
| 12323 |
# Check ripper (cdparanoia) and calculate a timeout according to track |
| 12324 |
# length. |
| 12325 |
# |
| 12326 |
sub check_ripper { |
| 12327 |
my $P_command = shift; |
| 12328 |
my $pid = shift; |
| 12329 |
my @commands = split(/ /, $P_command); |
| 12330 |
my $riptrackno = $commands[3]; |
| 12331 |
# Remember, $riptrackno might hold an span (interval) format. |
| 12332 |
$riptrackno =~ s/\[.*$//; |
| 12333 |
$riptrackno =~ s/-.*$//; |
| 12334 |
# The $P_command is slightly different in case of hidden tracks. |
| 12335 |
# Prevent warning when $riptrackno holds the device path instead of |
| 12336 |
# the hidden track number. |
| 12337 |
$riptrackno = 0 if($hiddenflag == 1 && $riptrackno !~ /^\d+$/); |
| 12338 |
my $tlength = $secondlist[$riptrackno - 1]; |
| 12339 |
$tlength = $secondlist[$riptrackno] if($hiddenflag == 1); |
| 12340 |
$tlength = int(exp(- $tlength / 2000) * ($tlength + 20)); |
| 12341 |
my $cn = 0; |
| 12342 |
while(kill 0, $pid) { |
| 12343 |
if($cn > $tlength) { |
| 12344 |
unless(kill 9, $pid) { |
| 12345 |
warn "\nProcess $pid already finished!\n"; |
| 12346 |
} |
| 12347 |
return 0; |
| 12348 |
} |
| 12349 |
sleep 3; |
| 12350 |
$cn += 3; |
| 12351 |
} |
| 12352 |
return 1; |
| 12353 |
} |
| 12354 |
######################################################################## |
| 12355 |
# |
| 12356 |
# Check distribution. |
| 12357 |
# |
| 12358 |
sub check_distro { |
| 12359 |
$distro = "debian" if(-f "/etc/debian_version"); |
| 12360 |
} |
| 12361 |
######################################################################## |
| 12362 |
# |
| 12363 |
# Get discid and number of tracks of inserted disc. |
| 12364 |
# |
| 12365 |
sub get_cddbid { |
| 12366 |
CDDB_get->import( qw( get_cddb get_discids ) ); |
| 12367 |
my $cd = get_discids($scsi_cddev); |
| 12368 |
my ($id, $tracks, $toc) = ($cd->[0], $cd->[1], $cd->[2]); |
| 12369 |
$cddbid = sprintf("%08x", $id); |
| 12370 |
my $totaltime = |
| 12371 |
sprintf("%02d:%02d",$toc->[$tracks]->{min},$toc->[$tracks]->{sec}); |
| 12372 |
return($cddbid, $tracks, $totaltime); |
| 12373 |
} |
| 12374 |
######################################################################## |
| 12375 |
# |
| 12376 |
# Analyze string build from CDDB data for latin and wide chars. |
| 12377 |
# Simplified code by T. Kukuk |
| 12378 |
# |
| 12379 |
sub check_encoding { |
| 12380 |
my $char_string = shift; |
| 12381 |
# Check if utf-8 or alike |
| 12382 |
my $enc = Encode::Guess->guess($char_string); |
| 12383 |
|
| 12384 |
# If it is not utf-8 or something similar, check for latin1. |
| 12385 |
# Guess_encoding cannot always differentiate between latin1 and utf-8 |
| 12386 |
# so check utf-8 first alone. |
| 12387 |
if(!ref($enc)) { |
| 12388 |
$enc = Encode::Guess->guess($char_string, 'latin1'); |
| 12389 |
} |
| 12390 |
|
| 12391 |
# Still nothing found, assume cp1252, works most of the cases. |
| 12392 |
if(!ref($enc)) { |
| 12393 |
return('cp1252'); |
| 12394 |
} |
| 12395 |
|
| 12396 |
return($enc->name); |
| 12397 |
} |
| 12398 |
######################################################################## |
| 12399 |
# |
| 12400 |
# Transform length of span in seconds. Argument has hh:mm:ss.ff format. |
| 12401 |
# |
| 12402 |
sub span_length { |
| 12403 |
my $time = shift; |
| 12404 |
my @time = split(/:/, $time); |
| 12405 |
my $factor = 60; |
| 12406 |
$time = pop(@time); |
| 12407 |
# Cut off frames (sectors). |
| 12408 |
my $frames = 0; |
| 12409 |
($time, $frames) = split(/\./, $time) if($time =~ /\./); |
| 12410 |
# Round the value of frames. |
| 12411 |
$time++ if($frames > 37); |
| 12412 |
while ($time[0]) { |
| 12413 |
$time += pop(@time) * $factor; |
| 12414 |
# TODO: stop, this is a bug! Multiplication by 60, not sum! |
| 12415 |
$factor += 60; |
| 12416 |
} |
| 12417 |
return($time); |
| 12418 |
} |
| 12419 |
######################################################################## |
| 12420 |
# |
| 12421 |
# Transform length of span from frames to (hh:)mm:ss.ff format. Type $t |
| 12422 |
# is eq 1 when chapatermarks are wanted (HH:MM:SS:FF format) and eq 2 |
| 12423 |
# when cue-points shall be returned (in MM:SS:FF format without hours). |
| 12424 |
# Thanks to perlmonks for input. |
| 12425 |
# |
| 12426 |
sub track_length { |
| 12427 |
my $f = shift; |
| 12428 |
my $t = shift; |
| 12429 |
my $s = int($f / 75); |
| 12430 |
$f = $f % 75; |
| 12431 |
return sprintf("%s%02d", "00:00:", $s) if($s < 60 and $t == 1); |
| 12432 |
return sprintf("%s%02d:%02d", "00:", $s , $f) if($s < 60 and $t == 2); |
| 12433 |
|
| 12434 |
my $m = $s / 60; |
| 12435 |
$s = $s % 60; |
| 12436 |
return sprintf("%s%02d:%02d", "00:", $m, $s) if($m < 60 and $t == 1); |
| 12437 |
return sprintf("%02d:%02d:%02d", $m, $s , $f) if($t == 2); |
| 12438 |
|
| 12439 |
my $h = $m / 60; |
| 12440 |
$m %= 60; |
| 12441 |
return sprintf("%02d:%02d:%02d", $h, $m, $s) if($h < 24); |
| 12442 |
|
| 12443 |
my $d = $h / 24; |
| 12444 |
$h %= 24; |
| 12445 |
return sprintf("%d:%02d:%02d:%02d", $d, $h, $m, $s); |
| 12446 |
} |
| 12447 |
######################################################################## |
| 12448 |
# |
| 12449 |
# Finish process. |
| 12450 |
# |
| 12451 |
sub finish_process { |
| 12452 |
if($sshflag == 1) { |
| 12453 |
check_wav(); |
| 12454 |
} |
| 12455 |
else { |
| 12456 |
wait; |
| 12457 |
} |
| 12458 |
|
| 12459 |
if($playlist >= 1 && $encode == 1) { |
| 12460 |
create_m3u(); |
| 12461 |
} |
| 12462 |
|
| 12463 |
my ($riptime, $enctime, $encend, $blanktrks, $ghostrks, $splitrks) |
| 12464 |
= cal_times(); |
| 12465 |
del_erlog() if(-r "$wavdir/error.log"); |
| 12466 |
|
| 12467 |
if(-r "$wavdir/error.log" && $blanktrks eq "") { |
| 12468 |
if($verbose >= 1) { |
| 12469 |
print "\nCD may not be complete! Check the error.log \n", |
| 12470 |
"in $wavdir!\n"; |
| 12471 |
} |
| 12472 |
elsif($verbose >= 3) { |
| 12473 |
print "\nRipping needed $riptime min and encoding needed ", |
| 12474 |
"$enctime min.\n\n"; |
| 12475 |
} |
| 12476 |
} |
| 12477 |
else { |
| 12478 |
if($verbose >= 1) { |
| 12479 |
if($ghost == 1) { |
| 12480 |
if($blanktrks) { |
| 12481 |
print "\nCD may not be complete! Check the error.log \n", |
| 12482 |
"in $wavdir!\n"; |
| 12483 |
print "Blank track deleted: $blanktrks!\n" |
| 12484 |
if($blanktrks !~ /and/); |
| 12485 |
print "Blank tracks deleted: $blanktrks!\n" |
| 12486 |
if($blanktrks =~ /and/); |
| 12487 |
} |
| 12488 |
else { |
| 12489 |
printf "\n%02d:%02d:%02d: ", |
| 12490 |
sub {$_[2], $_[1], $_[0]}->(localtime); |
| 12491 |
print "All complete!\n"; |
| 12492 |
} |
| 12493 |
if($ghostrks) { |
| 12494 |
print "Ghost song found in track $ghostrks!\n" |
| 12495 |
if($ghostrks !~ /and/); |
| 12496 |
print "Ghost songs found in tracks $ghostrks!\n" |
| 12497 |
if($ghostrks =~ /and/); |
| 12498 |
} |
| 12499 |
else { |
| 12500 |
print "No ghost songs found!\n"; |
| 12501 |
} |
| 12502 |
if($splitrks) { |
| 12503 |
print "Track $splitrks trimmed!\n" |
| 12504 |
if($splitrks !~ /and/); |
| 12505 |
print "Tracks $splitrks trimmed!\n" |
| 12506 |
if($splitrks =~ /and/); |
| 12507 |
} |
| 12508 |
else { |
| 12509 |
print "No tracks trimmed!\n" unless($splitrks); |
| 12510 |
} |
| 12511 |
} |
| 12512 |
else { |
| 12513 |
print "\nAll complete!\n"; |
| 12514 |
} |
| 12515 |
print "Ripping needed $riptime min and "; |
| 12516 |
print "encoding needed $enctime min.\n\n"; |
| 12517 |
} |
| 12518 |
} |
| 12519 |
|
| 12520 |
log_info("\nRipping needed $riptime minutes."); |
| 12521 |
log_info("Encoding needed $enctime minutes."); |
| 12522 |
|
| 12523 |
if($lcd == 1) { # lcdproc |
| 12524 |
$lcdline1 = " "; |
| 12525 |
$lcdline2 = " RipIT finished "; |
| 12526 |
$lcdline3 = " "; |
| 12527 |
ulcd(); |
| 12528 |
close($lcdproc) or print "close: $!"; |
| 12529 |
} |
| 12530 |
|
| 12531 |
if($multi == 1) { |
| 12532 |
open(SRXY,">>$logfile") |
| 12533 |
or print "Can not append to file \"$logfile\"!\n"; |
| 12534 |
print SRXY "\nEncoding ended: $encend"; |
| 12535 |
print SRXY "\nRipping needed: $riptime min."; |
| 12536 |
print SRXY "\nEncoding needed: $enctime min."; |
| 12537 |
print SRXY "\nGhost song(s) found in tracks $ghostrks!\n" |
| 12538 |
if($ghostrks && $ghost == 1); |
| 12539 |
print SRXY "\nTrack(s) $splitrks trimmed!\n" |
| 12540 |
if($splitrks && $ghost == 1); |
| 12541 |
print SRXY "\nTrack(s) $blanktrks deleted!\n" |
| 12542 |
if($blanktrks && $ghost == 1); |
| 12543 |
close(SRXY); |
| 12544 |
my $cddevno = $cddev; |
| 12545 |
$cddevno =~ s/\/dev\///; |
| 12546 |
open(SUCC,">>$outputdir/done.log") |
| 12547 |
or print "Can not append to file \"$outputdir/succes.log\"!\n"; |
| 12548 |
print SUCC "$cd{artist};$cd{title};$genre;$categ;$cddbid;"; |
| 12549 |
print SUCC "$cddevno;$hostnam;$riptime;$enctime\n"; |
| 12550 |
close(SUCC); |
| 12551 |
$cddev =~ s/\/dev\//device /; |
| 12552 |
$cddev = $cddev . " " unless($cddev =~ /\d\d$/); |
| 12553 |
my $time = sprintf("%02d:%02d", sub {$_[2], $_[1]}->(localtime)); |
| 12554 |
cprint("\x037Encoding done $time in $cddev with:\x030"); |
| 12555 |
cprint("\x037\n$cd{artist} - $cd{title}.\x030"); |
| 12556 |
cprint("\x033\nGhost song(s) found in tracks $ghostrks!\x030") |
| 12557 |
if($ghostrks =~ /1/ && $ghost == 1); |
| 12558 |
cprint("\x033\nTrack(s) $splitrks trimmed!\x030") |
| 12559 |
if($splitrks =~ /1/ && $ghost == 1); |
| 12560 |
cprint("\x033\nTrack(s) $blanktrks deleted!\x030") |
| 12561 |
if($blanktrks =~ /1/ && $ghost == 1); |
| 12562 |
} |
| 12563 |
|
| 12564 |
if($execmd) { |
| 12565 |
$execmd =~ s/\$/\\\$/g; |
| 12566 |
print "Will execute command \"$execmd\".\n" if($verbose >= 3); |
| 12567 |
log_system("$execmd"); |
| 12568 |
} |
| 12569 |
|
| 12570 |
if($halt == 1 && $verbose >= 1) { |
| 12571 |
print "\nShutdown...\n"; |
| 12572 |
log_system("shutdown -h now"); |
| 12573 |
} |
| 12574 |
|
| 12575 |
log_info("*" x 72, "\n"); |
| 12576 |
print "\n"; |
| 12577 |
print "Please insert a new CD!\n\n" if($loop == 2); |
| 12578 |
return; |
| 12579 |
} |
| 12580 |
######################################################################## |
| 12581 |
# |
| 12582 |
# Write inf file for each track. |
| 12583 |
# |
| 12584 |
sub write_inf { |
| 12585 |
my $wavdir = shift; |
| 12586 |
my $riptrackname = shift; |
| 12587 |
my $artistag = shift; |
| 12588 |
my $albumtag = shift; |
| 12589 |
my $tracktag = shift; |
| 12590 |
my $riptrackno = shift; |
| 12591 |
my $nofghosts = shift; |
| 12592 |
my $trackstart = shift; |
| 12593 |
my $artist = shift; |
| 12594 |
my $tracktitle = shift; |
| 12595 |
my $rip_wavnam = shift; |
| 12596 |
|
| 12597 |
print "\nWriting inf file for $riptrackname.wav.\n" if($verbose > 3); |
| 12598 |
$nofghosts = $nofghosts - $riptrackno + 1; |
| 12599 |
my $ripstart = sprintf("%02d:%02d:%02d", |
| 12600 |
sub {$_[2], $_[1], $_[0]}->(localtime)); |
| 12601 |
my $date = sprintf("%04d-%02d-%02d", |
| 12602 |
sub {$_[5]+1900, $_[4]+1, $_[3]}->(localtime)); |
| 12603 |
|
| 12604 |
my ($delim, $dummy) = check_va(0) if($vatag > 0); |
| 12605 |
$delim = quotemeta($delim) if(defined $delim); |
| 12606 |
|
| 12607 |
while($nofghosts > 0) { |
| 12608 |
# This is not as ugly as it looks like. Remember that subroutine |
| 12609 |
# rename_chunks alters the track name if that track has a slash |
| 12610 |
# in. |
| 12611 |
if(-r "$wavdir/$riptrackname.wav" and $rip_wavnam ne $riptrackname) { |
| 12612 |
$rip_wavnam = $riptrackname unless($riptrackname =~ /short/ and length("$wavdir/$rip_wavnam.wav") > 190); |
| 12613 |
} |
| 12614 |
open(INF, ">$wavdir/$rip_wavnam.inf"); |
| 12615 |
print INF "# Wave-info file created by ripit $version on ", |
| 12616 |
"$date at $ripstart.\n# To burn the wav files use e.g.", |
| 12617 |
" command:\n# wodim dev=/dev/scd0 -v -eject -pad -dao ", |
| 12618 |
"-useinfo -text *.wav\n#\n"; |
| 12619 |
print INF "CDINDEX_DISCID=\t'$cd{discid}'\n" if($cd{discid}); |
| 12620 |
print INF "CDDB_DISCID=\t$cddbid\n"; |
| 12621 |
print INF "DISCID=\t$discid\n#\n" if($discid ne ""); # New 4.0 |
| 12622 |
if($va_flag == 1) { |
| 12623 |
print INF "Albumperformer=\t'$artist_utf8'\n"; |
| 12624 |
} |
| 12625 |
else { |
| 12626 |
print INF "Albumperformer=\t'$artistag'\n"; |
| 12627 |
} |
| 12628 |
print INF "Performer=\t'$artistag'\n"; |
| 12629 |
print INF "Albumtitle=\t'$albumtag'\n"; |
| 12630 |
print INF "Tracktitle=\t'$tracktag'\n"; |
| 12631 |
print INF "Tracknumber=\t$riptrackno\n"; |
| 12632 |
print INF "Trackstart=\t$trackstart\n"; |
| 12633 |
my $length = 0; |
| 12634 |
# The wav does not exist if ripper failed. |
| 12635 |
if(-f "$wavdir/$riptrackname.wav") { |
| 12636 |
$length = -s "$wavdir/$riptrackname.wav"; |
| 12637 |
} |
| 12638 |
$length = int(($length - 44) / 2352) if($length > 0); |
| 12639 |
print INF "# track length in sectors (1/75 seconds each), rest samples\n"; |
| 12640 |
print INF "Tracklength=\t'", $length, ", 0'\n"; |
| 12641 |
$trackstart += $length; |
| 12642 |
print INF "Pre-emphasis=\tno\n"; |
| 12643 |
print INF "Channels=\t2\n"; |
| 12644 |
print INF "Endianess=\tlittle\n"; |
| 12645 |
print INF "# index list\n"; |
| 12646 |
print INF "Index=\t0\n"; |
| 12647 |
print INF "Index0=\t-1\n"; |
| 12648 |
close(INF); |
| 12649 |
$nofghosts--; |
| 12650 |
if($nofghosts > 0) { |
| 12651 |
my $gcn = $seltrack[$#seltrack - $nofghosts + 1]; |
| 12652 |
my $trn = $tracklist[$#tracklist - $nofghosts + 1]; |
| 12653 |
$tracktag = $tracktags[$#tracktags - $nofghosts + 1]; |
| 12654 |
# Split the tracktag into its artist part and track part if |
| 12655 |
# VA style is used. |
| 12656 |
if($va_flag > 0 && $trn =~ /$delim/) { |
| 12657 |
($artist, $trn) = split_tags($trn, $delim); |
| 12658 |
} |
| 12659 |
$riptrackname = get_trackname($gcn, $trn, 0, $artist, $trn); |
| 12660 |
$rip_wavnam = $riptrackname; |
| 12661 |
$riptrackno++; |
| 12662 |
} |
| 12663 |
} |
| 12664 |
return($trackstart); |
| 12665 |
} |
| 12666 |
######################################################################## |
| 12667 |
# |
| 12668 |
# Write coverart to mp3 files. |
| 12669 |
# |
| 12670 |
sub mp3_cover { |
| 12671 |
my($snd_file, $coverpath) = @_; |
| 12672 |
my $mp3 = MP3::Tag->new($snd_file); |
| 12673 |
$mp3->get_tags; |
| 12674 |
my $id3v2 = exists $mp3->{'ID3v2'} |
| 12675 |
? $mp3->{'ID3v2'} |
| 12676 |
: $mp3->new_tag('ID3v2'); |
| 12677 |
my $type = $coverpath; |
| 12678 |
$type =~ s/.*\.(gif|jpg|jpeg|png)$/$1/; |
| 12679 |
$type =~ s/jpg/jpeg/; |
| 12680 |
|
| 12681 |
my $msg = "\nAdding a $type to $snd_file."; |
| 12682 |
enc_print("$msg", 3); |
| 12683 |
log_info("$msg"); |
| 12684 |
# Read coverart into $data. |
| 12685 |
open(PIC, "< $coverpath" ) |
| 12686 |
or print "Cannot open file $coverpath: $!\n\n"; |
| 12687 |
binmode(PIC); |
| 12688 |
my $data = do { local($/); <PIC> }; |
| 12689 |
|
| 12690 |
# http://id3.org/id3v2.4.0-frames |
| 12691 |
# ------------------------------- |
| 12692 |
# <Header for 'Attached picture', ID: "APIC"> |
| 12693 |
# Text encoding $xx |
| 12694 |
# MIME type <text string> $00 |
| 12695 |
# Picture type $xx |
| 12696 |
# Description <text string according to encoding> $00 (00) |
| 12697 |
# Picture data <binary data> |
| 12698 |
# |
| 12699 |
# http://id3.org/id3v2.4.0-structure |
| 12700 |
# ---------------------------------- |
| 12701 |
# Frames that allow different types of text encoding contains a text |
| 12702 |
# encoding description byte. Possible encodings: |
| 12703 |
# |
| 12704 |
# $00 ISO-8859-1 [ISO-8859-1]. Terminated with $00. |
| 12705 |
# $01 UTF-16 [UTF-16] encoded Unicode [UNICODE] with BOM. All |
| 12706 |
# strings in the same frame SHALL have the same byteorder. |
| 12707 |
# Terminated with $00 00. |
| 12708 |
# $02 UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM. |
| 12709 |
# Terminated with $00 00. |
| 12710 |
# $03 UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00. |
| 12711 |
|
| 12712 |
|
| 12713 |
$id3v2->add_frame('APIC', chr(0x3), "image/$type", chr(0x3), "", $data); |
| 12714 |
$id3v2->write_tag; |
| 12715 |
close(PIC); |
| 12716 |
$mp3->close; |
| 12717 |
return; |
| 12718 |
} |
| 12719 |
######################################################################## |
| 12720 |
# |
| 12721 |
# Write special tags to mp3 files. |
| 12722 |
# |
| 12723 |
sub mp3_tags { |
| 12724 |
my($snd_file) = shift; |
| 12725 |
my $mp3 = MP3::Tag->new($snd_file); |
| 12726 |
$mp3->get_tags; |
| 12727 |
my $id3v2 = exists $mp3->{'ID3v2'} |
| 12728 |
? $mp3->{'ID3v2'} |
| 12729 |
: $mp3->new_tag('ID3v2'); |
| 12730 |
foreach (@mp3tags) { |
| 12731 |
my ($frame, $content) = split(/=/, $_); |
| 12732 |
if($frame =~ /^\wXXX$/) { |
| 12733 |
my($string, @content) = split(/\]/, $content); |
| 12734 |
$string =~ s/\[//; |
| 12735 |
$content = join(']', @content); |
| 12736 |
$content = tag_eval($string, $content); |
| 12737 |
if(defined $content && $content ne "") { |
| 12738 |
$id3v2->add_frame($frame, $string, $content); |
| 12739 |
my $msg = "\nAdding $frame=$string $content to $snd_file."; |
| 12740 |
enc_print($msg, 3); |
| 12741 |
log_info("$msg"); |
| 12742 |
} |
| 12743 |
else { |
| 12744 |
my $msg = "\nFrame $frame with description " . |
| 12745 |
"$string not added as no content given."; |
| 12746 |
enc_print($msg, 3); |
| 12747 |
log_info("$msg"); |
| 12748 |
} |
| 12749 |
} |
| 12750 |
else { |
| 12751 |
# TODO: maybe back_encoding is needed for special frames... |
| 12752 |
# But for TPE2 it has already been done. |
| 12753 |
$id3v2->add_frame($frame, $content); |
| 12754 |
my $msg = "\nAdding $frame=$content to $snd_file."; |
| 12755 |
enc_print($msg, 3); |
| 12756 |
log_info("$msg"); |
| 12757 |
} |
| 12758 |
} |
| 12759 |
$id3v2->write_tag; |
| 12760 |
$mp3->close; |
| 12761 |
return; |
| 12762 |
} |
| 12763 |
######################################################################## |
| 12764 |
# |
| 12765 |
# Write coverart to ogg files. |
| 12766 |
# |
| 12767 |
sub ogg_cover { |
| 12768 |
use MIME::Base64 qw(encode_base64); |
| 12769 |
my($snd_file, $coverpath) = @_; |
| 12770 |
my $type = $coverpath; |
| 12771 |
$type =~ s/.*\.(gif|jpg|png)$/$1/; |
| 12772 |
|
| 12773 |
open(PIC, "$coverpath") |
| 12774 |
or print "Cannot open file $coverpath: $!\n\n"; |
| 12775 |
my $data = do { local($/); encode_base64(<PIC>, '') }; |
| 12776 |
close(PIC); |
| 12777 |
|
| 12778 |
my $temp_cov = "/tmp/ripit-ogg-cov-$$"; |
| 12779 |
open(TMP, "> $temp_cov") or print "$temp_cov $!"; |
| 12780 |
print TMP "COVERART=$data"; |
| 12781 |
close(TMP); |
| 12782 |
|
| 12783 |
my $msg = "\nAdding a $type to $snd_file."; |
| 12784 |
enc_print($msg, 3); |
| 12785 |
log_info("$msg"); |
| 12786 |
if(-s "$coverpath" < 60000) { |
| 12787 |
log_system("vorbiscomment -a \"$snd_file\" -t COVERARTMIME=image/$type -t COVERART=$data"); |
| 12788 |
} |
| 12789 |
else { |
| 12790 |
log_system("vorbiscomment -a \"$snd_file\" -t COVERARTMIME=image/$type"); |
| 12791 |
# This command will never end, the encoder process will stop here. |
| 12792 |
# open(OGG, "|vorbiscomment -a \"$snd_file\""); |
| 12793 |
# print OGG $temp_cov; |
| 12794 |
# close OGG; |
| 12795 |
# This command will never end, the encoder process will stop here. |
| 12796 |
# exec("vorbiscomment -a \"$snd_file\" < $temp_cov"); |
| 12797 |
# Why does it work with back ticks? |
| 12798 |
log_info("\nExecuting vorbiscomment to add the cover in base64.\n"); |
| 12799 |
`vorbiscomment -a \"$snd_file\" < $temp_cov`; |
| 12800 |
} |
| 12801 |
unlink("$temp_cov"); |
| 12802 |
return; |
| 12803 |
} |
| 12804 |
######################################################################## |
| 12805 |
# |
| 12806 |
# Write special tag frames to ogg files. |
| 12807 |
# |
| 12808 |
sub ogg_tags { |
| 12809 |
my($snd_file) = @_; |
| 12810 |
|
| 12811 |
foreach (@oggtags) { |
| 12812 |
my ($frame, $content) = split(/=/, $_); |
| 12813 |
$content = tag_eval($frame, $content); |
| 12814 |
if(defined $content and $content ne "" |
| 12815 |
and $frame =~ /ASIN|BARCODE|CATALOG|CATALOGNUMBER|CDDBID|DGID|DISCID|MBREID|MUSICBRAINZ_ALBUMID|MUSICBRAINZ_DISCID/) { |
| 12816 |
my $msg = "\nAdding $frame=$content to $snd_file."; |
| 12817 |
enc_print($msg, 3); |
| 12818 |
log_info("$msg"); |
| 12819 |
log_system("vorbiscomment -a \"$snd_file\" -t \'$frame=$content\'"); |
| 12820 |
} |
| 12821 |
elsif(defined $content) { |
| 12822 |
my $msg = "\nThe frame=$frame with content=$content has not " . |
| 12823 |
"been added to\n$snd_file"; |
| 12824 |
enc_print($msg, 3); |
| 12825 |
} |
| 12826 |
else { |
| 12827 |
my $msg = "\nThe frame=$frame has not been added to\n$snd_file"; |
| 12828 |
enc_print($msg, 3); |
| 12829 |
} |
| 12830 |
} |
| 12831 |
return; |
| 12832 |
} |
| 12833 |
######################################################################## |
| 12834 |
# |
| 12835 |
# Evaluate special tags to be added (check for mp3, vorbis etc.). |
| 12836 |
# |
| 12837 |
sub tag_eval { |
| 12838 |
my($frame, $content) = @_; |
| 12839 |
return unless(defined $frame); |
| 12840 |
chomp $content; |
| 12841 |
return $cd{asin} if($frame eq "ASIN" and $content eq "asin"); |
| 12842 |
return $cd{barcode} if($frame eq "BARCODE" and $content eq "barcode"); |
| 12843 |
return $cd{catalog} if($frame eq "CATALOG" and $content eq "catalog"); |
| 12844 |
return $cd{catalog} if($frame eq "CATALOGNUMBER" and $content eq "catalog"); |
| 12845 |
return $cddbid if($frame eq "CDDBID" and $content eq "cddbid"); |
| 12846 |
return $cd{dgid} if($frame eq "DGID" and $content eq "dgid"); |
| 12847 |
return $cd{discid} if($frame eq "DISCID" and $content eq "discid"); |
| 12848 |
return $cd{discid} if($frame eq "MUSICBRAINZ_DISCID" and $content eq "discid"); |
| 12849 |
return $cd{discid} if($frame eq "MusicBrainz Disc Id" and $content eq "discid"); |
| 12850 |
return $cd{mbreid} if($frame eq "MBREID" and $content eq "mbreid"); |
| 12851 |
return $cd{mbreid} if($frame eq "MUSICBRAINZ_ALBUMID" and $content eq "mbreid"); |
| 12852 |
return $cd{mbreid} if($frame eq "MusicBrainz Album Id" and $content eq "mbreid"); |
| 12853 |
} |
| 12854 |
|
| 12855 |
######################################################################## |
| 12856 |
# |
| 12857 |
# Write the CDDB entry to ~/.cddb/category if there is not already |
| 12858 |
# an entry present. |
| 12859 |
# |
| 12860 |
sub write_cddb { |
| 12861 |
chomp($categ = $cd{cat}); |
| 12862 |
log_system("mkdir -m 0755 -p $homedir/.cddb/$categ/") |
| 12863 |
or print "Can not create directory $homedir/.cddb/$categ: $!\n"; |
| 12864 |
$cddbid =~ s/,.*$// if($cddbid =~ /,/); |
| 12865 |
if(! -f "$homedir/.cddb/$categ/$cddbid") { |
| 12866 |
open(TOC, "> $homedir/.cddb/$categ/$cddbid") |
| 12867 |
or print "Can not write to $homedir/.cddb/$categ/$cddbid: $!\n"; |
| 12868 |
foreach(@{$cd{raw}}) { |
| 12869 |
print TOC $_; |
| 12870 |
} |
| 12871 |
} |
| 12872 |
else { |
| 12873 |
print "\nA local archive entry exists in $homedir/.cddb/$categ/", |
| 12874 |
"$cddbid, nothing over written.\n" if($verbose > 4); |
| 12875 |
} |
| 12876 |
close TOC; |
| 12877 |
$archive = 0; |
| 12878 |
} |
| 12879 |
######################################################################## |
| 12880 |
# |
| 12881 |
# Merge the wav files if $cdcue == 1. |
| 12882 |
# |
| 12883 |
sub merge_wav { |
| 12884 |
my ($trn, $chunkbyte, $album) = @_; |
| 12885 |
open(IN, "< $wavdir/$trn.rip") or |
| 12886 |
print "Can't open $trn.rip: $!\n"; |
| 12887 |
binmode(IN); |
| 12888 |
# Only skip the header in case the base file already exists. |
| 12889 |
if(-r "$wavdir/$album.wav") { |
| 12890 |
seek(IN, 44, 0) or |
| 12891 |
print "\nCould not seek beyond header in file IN: $!\n"; |
| 12892 |
} |
| 12893 |
open(OUT, ">> $wavdir/$album.wav"); |
| 12894 |
binmode(OUT); |
| 12895 |
|
| 12896 |
# I don't know if it is good to read so many bytes a time, but it |
| 12897 |
# is faster than reading byte by byte. |
| 12898 |
while(read(IN, my $bindata, $chunkbyte)) { |
| 12899 |
print OUT $bindata; |
| 12900 |
} |
| 12901 |
close(IN); |
| 12902 |
close(OUT); |
| 12903 |
|
| 12904 |
# Rewrite the header of the merged file $album.wav. |
| 12905 |
write_wavhead("$wavdir/$album.wav"); |
| 12906 |
|
| 12907 |
return; |
| 12908 |
} |
| 12909 |
######################################################################## |
| 12910 |
# |
| 12911 |
# Rewrite the wav header. |
| 12912 |
# |
| 12913 |
sub write_wavhead { |
| 12914 |
my $file = shift; |
| 12915 |
if(!sysopen(WAV, $file, O_RDWR | O_CREAT, 0755)) { |
| 12916 |
print "\nCan not to open $file: $!\n"; |
| 12917 |
return; |
| 12918 |
} |
| 12919 |
my $buffer; |
| 12920 |
my $nread = sysread(WAV, $buffer, 44); |
| 12921 |
if($nread != 44 || length($buffer) != 44) { |
| 12922 |
print "\nWAV-header length problem in file $file.\n"; |
| 12923 |
close(WAV); |
| 12924 |
return; |
| 12925 |
} |
| 12926 |
|
| 12927 |
my $main_template = "a4 V a4 a4 V a16 a4 V"; |
| 12928 |
my($riff_header, $file_size_8, $wav_header, $fmt_header, |
| 12929 |
$fmt_length, $fmt_data,$data_header,$data_size) = |
| 12930 |
unpack($main_template, $buffer); |
| 12931 |
if($verbose > 5) { |
| 12932 |
print "RIFF chunk descriptor is: $riff_header\n", |
| 12933 |
"RIFF chunk length is: $file_size_8\n", |
| 12934 |
"WAVE format is: $wav_header\n", |
| 12935 |
"FMT subchunk is: $fmt_header\n", |
| 12936 |
"FMT subchunk length is: $fmt_length\n"; |
| 12937 |
} |
| 12938 |
my $file_length = -s "$file"; |
| 12939 |
$file_size_8 = $file_length - 8; |
| 12940 |
$data_size = $file_length - 44; |
| 12941 |
$buffer = pack($main_template, $riff_header, $file_size_8, |
| 12942 |
$wav_header, $fmt_header, $fmt_length, $fmt_data, |
| 12943 |
$data_header, $data_size); |
| 12944 |
sysseek(WAV, 0, 0); |
| 12945 |
syswrite(WAV, $buffer, length($buffer)); |
| 12946 |
close(WAV); |
| 12947 |
return; |
| 12948 |
} |
| 12949 |
######################################################################## |
| 12950 |
# |
| 12951 |
# Check all tracks for VA-style. |
| 12952 |
# |
| 12953 |
sub check_va { |
| 12954 |
my $prt_msg = shift; |
| 12955 |
my $delim = ""; |
| 12956 |
my $delim_colon = 0; |
| 12957 |
my $delim_hyphen = 0; |
| 12958 |
my $delim_slash = 0; |
| 12959 |
my $delim_parenthesis = 0; |
| 12960 |
my $n = 0; |
| 12961 |
# Don't use @tracktags because operator might not want to rip the |
| 12962 |
# whole CD. VA-style detection will fail if number of selected tracks |
| 12963 |
# are compared to the total number of tracks! |
| 12964 |
# There are problems in case operator wants to re-encode, @seltrack |
| 12965 |
# must be available, but remained empty. In this case use array |
| 12966 |
# tracklist instead. |
| 12967 |
my @tracks = @seltrack; |
| 12968 |
@tracks = (1 .. $#tracklist) if($vatag > 0 && !defined $seltrack[0]); |
| 12969 |
foreach (@tracks) { |
| 12970 |
my $tn = $_ - 1; |
| 12971 |
$delim_colon++ if($tracktags[$tn] =~ /:/); |
| 12972 |
$delim_hyphen++ if($tracktags[$tn] =~ /-/); |
| 12973 |
$delim_slash++ if($tracktags[$tn] =~ /\//); |
| 12974 |
$delim_parenthesis++ if($tracktags[$tn] =~ /\(.*\)/); |
| 12975 |
$n++; |
| 12976 |
} |
| 12977 |
|
| 12978 |
$n = -1 if($n == 0 and $rip == 0); # Prevent false msg. |
| 12979 |
|
| 12980 |
my $artist = clean_all($cd{artist}); |
| 12981 |
|
| 12982 |
if($vatag > 0 and $artist =~ /$vastring/i and |
| 12983 |
($delim_colon == $n or $delim_hyphen == $n or |
| 12984 |
$delim_slash == $n or $delim_parenthesis == $n)) { |
| 12985 |
$va_flag = 1; |
| 12986 |
print "\nVarious Artists CDDB detected, track artist will be ", |
| 12987 |
"used for each track tag.\n" |
| 12988 |
if($verbose > 2 and $prt_msg == 1); |
| 12989 |
} |
| 12990 |
elsif($vatag > 0 and $artist =~ /$vastring/i and |
| 12991 |
($delim_colon > 0 or $delim_hyphen > 0 or $delim_slash > 0 or |
| 12992 |
$delim_parenthesis > 0)) { |
| 12993 |
$va_flag = 1; |
| 12994 |
print "\nVarious Artists CDDB detected, track artist will be ", |
| 12995 |
"used for some track tags.\n" |
| 12996 |
if($verbose > 2 and $prt_msg == 1); |
| 12997 |
} |
| 12998 |
elsif($vatag > 0 and |
| 12999 |
($delim_colon == $n or $delim_hyphen == $n or |
| 13000 |
$delim_slash == $n or $delim_parenthesis == $n)) { |
| 13001 |
$va_flag = 1; |
| 13002 |
print "\nMultiple artists data detected, track artist will be", |
| 13003 |
" used for each track tag.\n" |
| 13004 |
if($verbose > 2 and $prt_msg == 1); |
| 13005 |
} |
| 13006 |
elsif($vatag > 0 and |
| 13007 |
($delim_colon > 0 or $delim_hyphen > 0 or $delim_slash > 0 or |
| 13008 |
$delim_parenthesis > 0)) { |
| 13009 |
$va_flag = 1; |
| 13010 |
print "\nMultiple artists data detected, track artist will be", |
| 13011 |
" used for some track tags.\n" |
| 13012 |
if($verbose > 2 and $prt_msg == 1); |
| 13013 |
} |
| 13014 |
else { |
| 13015 |
$va_flag = 0 unless($va_flag == 2); |
| 13016 |
print "\nNo Various Artists DB detected, album artist will be", |
| 13017 |
" used for each track tag.\n" |
| 13018 |
if($verbose > 2 and $va_flag == 0 and $prt_msg == 1); |
| 13019 |
} |
| 13020 |
print "\n" if($verbose > 2 and $prt_msg == 1); |
| 13021 |
return($delim) if($va_flag == 0); |
| 13022 |
|
| 13023 |
my $delim_cn = 0; |
| 13024 |
if($va_flag == 2) { |
| 13025 |
$va_flag = 1; |
| 13026 |
$delim = "/"; |
| 13027 |
$delim_cn = $delim_slash; |
| 13028 |
} |
| 13029 |
# Give slashes highest priority and set default to slashes too. |
| 13030 |
if($delim_slash >= $delim_colon and |
| 13031 |
$delim_slash >= $delim_hyphen and |
| 13032 |
$delim_slash >= $delim_parenthesis) { |
| 13033 |
$delim = "/"; |
| 13034 |
$delim_cn = $delim_slash; |
| 13035 |
} |
| 13036 |
elsif($delim_colon >= $delim_hyphen and |
| 13037 |
$delim_colon >= $delim_parenthesis and |
| 13038 |
$delim_colon >= $delim_slash) { |
| 13039 |
$delim = ":"; |
| 13040 |
$delim_cn = $delim_colon; |
| 13041 |
} |
| 13042 |
elsif($delim_hyphen >= $delim_colon and |
| 13043 |
$delim_hyphen >= $delim_slash and |
| 13044 |
$delim_hyphen >= $delim_parenthesis) { |
| 13045 |
$delim = "-"; |
| 13046 |
$delim_cn = $delim_hyphen; |
| 13047 |
} |
| 13048 |
elsif($delim_parenthesis >= $delim_colon and |
| 13049 |
$delim_parenthesis >= $delim_slash and |
| 13050 |
$delim_parenthesis >= $delim_hyphen) { |
| 13051 |
$delim = "("; |
| 13052 |
$delim_cn = $delim_parenthesis; |
| 13053 |
} |
| 13054 |
else { |
| 13055 |
$delim = "/"; |
| 13056 |
$delim_cn = $delim_slash; |
| 13057 |
} |
| 13058 |
return($delim, $delim_cn); |
| 13059 |
} |
| 13060 |
######################################################################## |
| 13061 |
# |
| 13062 |
# Copy image file from destination path to directories of encoded sound |
| 13063 |
# files. Prevent copying to itself. |
| 13064 |
# |
| 13065 |
sub copy_cover { |
| 13066 |
for(my $c=0; $c<=$#coder; $c++) { |
| 13067 |
my $basepath = $copycover; |
| 13068 |
my @basepath = split(/\//, $basepath); |
| 13069 |
pop(@basepath); |
| 13070 |
$basepath = join('/', @basepath); |
| 13071 |
next if("$basepath" eq "$sepdir[$c]"); |
| 13072 |
log_system("cp \"$copycover\" \"$sepdir[$c]\"") |
| 13073 |
or print "Copying file to $sepdir[$c] failed: $!\n"; |
| 13074 |
} |
| 13075 |
} |
| 13076 |
######################################################################## |
| 13077 |
# |
| 13078 |
# Check album cover in path variable copycover. |
| 13079 |
# |
| 13080 |
sub check_copy { |
| 13081 |
my $copycover = shift; |
| 13082 |
my $msg = shift; |
| 13083 |
if($copycover =~ /^".*"$/) { |
| 13084 |
print "Operator did quote too many times!\n" if($verbose > 5); |
| 13085 |
$copycover =~ s/^"(.*)"$/$1/; |
| 13086 |
} |
| 13087 |
check_cover($copycover, $msg); |
| 13088 |
} |
| 13089 |
######################################################################## |
| 13090 |
# |
| 13091 |
# Check album cover in path variable copycover or coverpath. |
| 13092 |
# |
| 13093 |
sub check_cover { |
| 13094 |
my $copycover = shift; |
| 13095 |
my $msg = shift; |
| 13096 |
my $ans; |
| 13097 |
if(-f "$copycover") { |
| 13098 |
print "File $copycover found\n" if($verbose > 4); |
| 13099 |
} |
| 13100 |
else { |
| 13101 |
while($copycover !~ /^[yn]$/i) { |
| 13102 |
print "$msg\nImage file $copycover is not a valid file. ", |
| 13103 |
"Continue? [y/n] (y) "; |
| 13104 |
$ans = <STDIN>; |
| 13105 |
chomp $ans; |
| 13106 |
$ans = "y" if($ans eq ""); |
| 13107 |
last if($ans =~ /y/i); |
| 13108 |
die "Aborting.\n\n" if($ans =~ /n/i); |
| 13109 |
} |
| 13110 |
} |
| 13111 |
} |
| 13112 |
######################################################################## |
| 13113 |
# |
| 13114 |
# Resize album cover to given format. |
| 13115 |
# |
| 13116 |
sub resize_cover { |
| 13117 |
my $coverpath = shift; |
| 13118 |
my $orig_coverpath = $coverpath; |
| 13119 |
my $orig_fmt = ""; |
| 13120 |
if(-f "$coverpath" && -s "$coverpath") { |
| 13121 |
open(FMT, "identify -format \"%[fx:w]x%[fx:h]\" \"$coverpath\" |") |
| 13122 |
or print "\nFailed to run ImageMagicks identify command: $!\n"; |
| 13123 |
while(<FMT>) { |
| 13124 |
chomp; |
| 13125 |
$orig_fmt = $_ if(/\d+x\d+/); |
| 13126 |
} |
| 13127 |
close(FMT); |
| 13128 |
if($orig_fmt =~ /\d+x\d+/) { |
| 13129 |
if($orig_coverpath =~ /\.[A-Za-z]{3,4}$/) { |
| 13130 |
$orig_coverpath =~ s/(\.[A-Za-z]+)$/_$orig_fmt$1/; |
| 13131 |
} |
| 13132 |
else{ |
| 13133 |
$orig_coverpath .= "_$orig_fmt"; |
| 13134 |
} |
| 13135 |
} |
| 13136 |
else{ |
| 13137 |
print "\nProblem with format detection of $coverpath: ", |
| 13138 |
"$orig_fmt\n" if($verbose > 3); |
| 13139 |
} |
| 13140 |
my ($orig_width, $orig_height) = split(/x/, $orig_fmt); |
| 13141 |
my ($width, $height) = split(/x/, $coversize); |
| 13142 |
$height = 0 unless(defined $height); |
| 13143 |
# Do not alter image if sizes are smaller. |
| 13144 |
if($orig_width <= $width || $orig_height <= $height) { |
| 13145 |
print "\nCoversize is equal or larger than sizes of provided ", |
| 13146 |
"coverart, no changes will happen.\n" if($verbose > 1); |
| 13147 |
return; |
| 13148 |
} |
| 13149 |
if($coverpath ne $orig_coverpath) { |
| 13150 |
log_info("rename(\"$coverpath\", \"$orig_coverpath\")"); |
| 13151 |
rename("$coverpath", "$orig_coverpath") ; |
| 13152 |
log_system("convert -resize $coversize \"$orig_coverpath\" \"$coverpath\""); |
| 13153 |
print "Renamed cover to $orig_coverpath and resized the ", |
| 13154 |
"$coverpath\n" if($verbose > 4); |
| 13155 |
} |
| 13156 |
else { |
| 13157 |
print "\nProblem while creating a backup of $coverpath ", |
| 13158 |
"renamed to $orig_coverpath\n" if($verbose > 3); |
| 13159 |
} |
| 13160 |
} |
| 13161 |
else { |
| 13162 |
print "File $coverpath not found\n" if($verbose > 3); |
| 13163 |
} |
| 13164 |
return; |
| 13165 |
} |
| 13166 |
######################################################################## |
| 13167 |
# |
| 13168 |
# Read in ISRCs using Icedax and submit them if detected using code from |
| 13169 |
# Nicholas Humfrey <[email protected]>. |
| 13170 |
# |
| 13171 |
sub get_isrcs { |
| 13172 |
print "\nReading ISRC..." if($verbose > 2); |
| 13173 |
my $icedax = `which icedax`; |
| 13174 |
chomp($icedax); |
| 13175 |
if($mbname ne "" and $mbpass ne "" and $icedax ne "") { |
| 13176 |
my $mcn = undef; |
| 13177 |
@isrcs = (); |
| 13178 |
open(ICEDAX, "icedax -D $scsi_cddev -g -H -J -Q -v trackid 2>&1 |") |
| 13179 |
or print "\nFailed to run icedax command: $!\n"; |
| 13180 |
while(<ICEDAX>) { |
| 13181 |
chomp; |
| 13182 |
if(/T:\s+(\d+)\s+ISRC:\s+([A-Z]{2}-?\w{3}-?\d{2}-?\d{5})$/) { |
| 13183 |
my ($num, $isrc) = ($1-1, uc($2)); |
| 13184 |
$isrc =~ s/\W//g; |
| 13185 |
$isrcs[$num] = $isrc; |
| 13186 |
} |
| 13187 |
elsif(/Media catalog number: (.+)/i) { |
| 13188 |
$mcn = $1; |
| 13189 |
} |
| 13190 |
} |
| 13191 |
close(ICEDAX); |
| 13192 |
|
| 13193 |
my $diflag = 1; # Suppose all ISRCs found are different. |
| 13194 |
# Now preparing ISRC data array to post to MB server. |
| 13195 |
my @isrcdata = (); |
| 13196 |
print "MCN: " . $mcn . "\n" if($mcn && $verbose > 3); |
| 13197 |
for(my $i = 0; $i < scalar(@isrcs); $i++) { |
| 13198 |
my $isrcno = $isrcs[$i]; |
| 13199 |
my $trackid = $idata[$i]; |
| 13200 |
next unless($trackid); |
| 13201 |
if(defined $isrcno && $isrcno ne '' && $isrcno !~ /^0+$/) { |
| 13202 |
printf("\nTrack %2.2d: %s %s", $i + 1, $isrcno || '', $trackid) |
| 13203 |
if($verbose >= 3); |
| 13204 |
push(@isrcdata, "isrc=" . $trackid . '%20' . $isrcno); |
| 13205 |
} |
| 13206 |
# Test if subsequent (all) ISRCs are different. |
| 13207 |
if($i > 0) { |
| 13208 |
$isrcno = $i unless($isrcno); |
| 13209 |
$diflag = 0 if($isrcs[$i-1] && $isrcno eq $isrcs[$i-1]); |
| 13210 |
} |
| 13211 |
} |
| 13212 |
print "\n\n" if($verbose > 3); |
| 13213 |
|
| 13214 |
# Check that we have something to submit |
| 13215 |
if(scalar(@isrcdata) < 1) { |
| 13216 |
print "\nNo valid ISRCs to submit." if($verbose > 2); |
| 13217 |
sleep 1; |
| 13218 |
} |
| 13219 |
elsif($diflag == 0) { |
| 13220 |
print "\nIdentical ISRCs for different tracks detected.", |
| 13221 |
"\nNo submission in this case.\n" if($verbose > 2); |
| 13222 |
sleep 1; |
| 13223 |
} |
| 13224 |
else { |
| 13225 |
# Send to Musicbrainz. |
| 13226 |
if($mbname ne "" and $mbpass ne "") { |
| 13227 |
print "\n@isrcdata" if($verbose > 4); |
| 13228 |
my $isrc_sub = -1; |
| 13229 |
if($interaction > 0) { |
| 13230 |
while($isrc_sub < 0 || $isrc_sub > 1) { |
| 13231 |
print "\n\nSubmission of ISRCs to MB? [y/n] (n) "; |
| 13232 |
$isrc_sub = <STDIN>; |
| 13233 |
chomp $isrc_sub; |
| 13234 |
$isrc_sub = 0 if($isrc_sub eq "" or $isrc_sub eq "n"); |
| 13235 |
$isrc_sub = 1 if($isrc_sub eq "y"); |
| 13236 |
$isrc_sub = -1 unless($isrc_sub =~ /^0|1$/); |
| 13237 |
print "\n"; |
| 13238 |
} |
| 13239 |
} |
| 13240 |
else { |
| 13241 |
$isrc_sub = 1; |
| 13242 |
} |
| 13243 |
if($isrc_sub == 1) { |
| 13244 |
my $ua = LWP::UserAgent->new; |
| 13245 |
$ua->timeout(10); |
| 13246 |
$ua->env_proxy; |
| 13247 |
$ua->credentials( 'musicbrainz.org:80', |
| 13248 |
'musicbrainz.org', |
| 13249 |
"$mbname", "$mbpass" ); |
| 13250 |
|
| 13251 |
my $request = HTTP::Request->new( |
| 13252 |
'POST', 'http://musicbrainz.org/ws/1/track/' ); |
| 13253 |
$request->content(join('&', @isrcdata)); |
| 13254 |
$request->content_type( |
| 13255 |
'application/x-www-form-urlencoded'); |
| 13256 |
|
| 13257 |
my $re = $ua->request($request); |
| 13258 |
print "\nISRC submission to MB " . $re->status_line. "\n" |
| 13259 |
if($verbose > 2); |
| 13260 |
} |
| 13261 |
else { |
| 13262 |
print "\nNo ISRC submission to MB.\n" if($verbose > 2); |
| 13263 |
} |
| 13264 |
} |
| 13265 |
} |
| 13266 |
} |
| 13267 |
return; |
| 13268 |
} |
| 13269 |
######################################################################## |
| 13270 |
# |
| 13271 |
# Detect a discID somewhere in log or cue files, or maybe even in the |
| 13272 |
# comment tag of the sound files. |
| 13273 |
# |
| 13274 |
sub get_cdid { |
| 13275 |
my ($album, $artist, $trackno, $title, $reldate); |
| 13276 |
|
| 13277 |
# Read the inputdir folder. |
| 13278 |
opendir (DIR, "$inputdir") or |
| 13279 |
print "Can't read inputdir $inputdir $!\n"; |
| 13280 |
my @dirfiles = readdir(DIR); |
| 13281 |
closedir(DIR); |
| 13282 |
@dirfiles = sort(@dirfiles); |
| 13283 |
my @cntfiles = grep { /\.cue$|\.inf$|\.log$|\.m3u$|\.toc$/ } @dirfiles; |
| 13284 |
my @sndfiles = grep { /\.flac$/ } @dirfiles; |
| 13285 |
my @wavfiles = grep { /\.wav$/ } @dirfiles; |
| 13286 |
if(!$sndfiles[0] && !$wavfiles[0]) { |
| 13287 |
die "\nQuitting, inputdir \"$inputdir\" has no flac or wav", |
| 13288 |
" files.\n\n"; |
| 13289 |
} |
| 13290 |
|
| 13291 |
# Add one snd file (flac) to the list of files to be checked for ids. |
| 13292 |
if($sndfiles[0]) { |
| 13293 |
push(@cntfiles, $sndfiles[0]) |
| 13294 |
} |
| 13295 |
|
| 13296 |
# Read the potential files with content: |
| 13297 |
foreach my $cntfile (@cntfiles) { |
| 13298 |
# Introduced to track down Morituri bug writing hidden cue sheets |
| 13299 |
# and playlist files; but actually does not solve the problem. |
| 13300 |
next unless(-r "$inputdir/$cntfile"); |
| 13301 |
open(CONF, "$inputdir/$cntfile") || |
| 13302 |
print "Can not read $cntfile file!\n"; |
| 13303 |
my @conflines = <CONF>; |
| 13304 |
close(CONF); |
| 13305 |
if($cntfile =~ /\.m3u$/) { |
| 13306 |
print "Analyzing playlist file.\n" if($verbose > 4); |
| 13307 |
# First non regular tags in header of m3u file. |
| 13308 |
# TODO: what happens if playlist file in an multi disc release |
| 13309 |
# contains all discids, i.e. more than one... |
| 13310 |
my @cdid = grep(s/^\s*#CDDBID=//, @conflines); |
| 13311 |
if(defined $cdid[0] && $#cdid < 1 or $interaction == 0) { |
| 13312 |
chomp($cdid = $cdid[0]) |
| 13313 |
unless($pcdid =~ /[0-9a-f]/ && length($pcdid) == 8); |
| 13314 |
} |
| 13315 |
elsif(defined $cdid[0]) { |
| 13316 |
print "More than one CDDBID found:\n"; |
| 13317 |
my ($i, $j) = (0, 0); |
| 13318 |
while($i > $#cdid+2 || $i == 0) { |
| 13319 |
foreach my $id (@cdid) { |
| 13320 |
$j++; |
| 13321 |
chomp($id); |
| 13322 |
my $tno = substr($id, 6); |
| 13323 |
$tno = hex($tno); |
| 13324 |
printf(" %2d: $id for a $tno track CD\n", $j); |
| 13325 |
} |
| 13326 |
print "\nChoose [1-$j]: "; |
| 13327 |
$i = <STDIN>; |
| 13328 |
chomp $i; |
| 13329 |
$j = 0; |
| 13330 |
} |
| 13331 |
chomp($cdid = $cdid[$i-1]); |
| 13332 |
print "\n"; |
| 13333 |
} |
| 13334 |
my @discid = grep(s:^#DISCID=::, @conflines); |
| 13335 |
if(defined $discid[0] && $#discid < 1 or $interaction == 0) { |
| 13336 |
chomp($discid = $discid[0]) |
| 13337 |
unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13338 |
} |
| 13339 |
elsif(defined $discid[0]) { |
| 13340 |
print "More than one discid found:\n"; |
| 13341 |
my ($i, $j) = (0, 0); |
| 13342 |
while($i > $#discid+2 || $i == 0) { |
| 13343 |
foreach my $id (@discid) { |
| 13344 |
$j++; |
| 13345 |
chomp($id); |
| 13346 |
printf(" %2d: $id\n", $j); |
| 13347 |
} |
| 13348 |
print "\nChoose [1-$j]: "; |
| 13349 |
$i = <STDIN>; |
| 13350 |
chomp $i; |
| 13351 |
$i = 0 unless($i =~ /^\d+$/); |
| 13352 |
$j = 0; |
| 13353 |
} |
| 13354 |
chomp($discid = $discid[$i-1]); |
| 13355 |
} |
| 13356 |
} |
| 13357 |
elsif($cntfile =~ /\.cue$/) { |
| 13358 |
print "Analyzing cue sheet.\n" if($verbose > 4); |
| 13359 |
# First non regular tags in header of toc file. |
| 13360 |
chomp($cdid = join('', grep(s:^//CDDBID=|REM\sDISCID\s::, @conflines))) |
| 13361 |
unless($pcdid =~ /[0-9a-f]/ && length($pcdid) == 8); |
| 13362 |
chomp($discid = join('', grep(s:^//DISCID=::, @conflines))) |
| 13363 |
unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13364 |
# Regular entry in toc file. |
| 13365 |
if($cdid eq "") { |
| 13366 |
chomp($cdid = join('', grep(s:DISC_ID\s*"::, @conflines))); |
| 13367 |
chop($cdid) if($cdid); |
| 13368 |
} |
| 13369 |
$cdid =~ s/\s//g; |
| 13370 |
} |
| 13371 |
elsif($cntfile =~ /\.toc$/) { |
| 13372 |
print "Analyzing toc file.\n" if($verbose > 4); |
| 13373 |
# First non regular tags in header of toc file. |
| 13374 |
chomp($cdid = join('', grep(s:^//CDDBID=::, @conflines))) |
| 13375 |
unless($pcdid =~ /[0-9a-f]/ && length($pcdid) == 8); |
| 13376 |
chomp($discid = join('', grep(s:^//DISCID=::, @conflines))) |
| 13377 |
unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13378 |
# Regular entry in toc file. |
| 13379 |
if($cdid eq "") { |
| 13380 |
chomp($cdid = join('', grep(s:DISC_ID\s*"::, @conflines))); |
| 13381 |
chop($cdid) if($cdid); |
| 13382 |
} |
| 13383 |
$cdid =~ s/\s//g; |
| 13384 |
} |
| 13385 |
elsif($cntfile =~ /\.inf$/) { |
| 13386 |
print "Analyzing inf files.\n" if($verbose > 4); |
| 13387 |
# First non regular tags in header of a inf file. |
| 13388 |
chomp($discid = join('', grep(s:^DISCID=\t::, @conflines))) |
| 13389 |
unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13390 |
# Regular entry in inf file. |
| 13391 |
if($cdid eq "") { |
| 13392 |
chomp($cdid = join('', grep(s:^CDINDEX_DISCID=\t::, @conflines))) |
| 13393 |
unless($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13394 |
chomp($cdid = join('', grep(s:^CDDB_DISCID=\t::, @conflines))) |
| 13395 |
unless($pcdid =~ /[0-9a-f]/ && length($cdid) == 8); |
| 13396 |
} |
| 13397 |
} |
| 13398 |
elsif($cntfile =~ /\.flac$/) { |
| 13399 |
print "Analyzing flac files.\n" if($verbose > 4); |
| 13400 |
# Read out the comment-tag. |
| 13401 |
my $tagfile = $cntfile; |
| 13402 |
$tagfile =~ s/\.flac$//; |
| 13403 |
|
| 13404 |
open(DISCID, "metaflac --export-tags-to=- \"$inputdir/$cntfile\"|"); |
| 13405 |
my @response = <DISCID>; |
| 13406 |
close(DISCID); |
| 13407 |
|
| 13408 |
chomp($cdid = join("", grep(s/^CDID=\s*//, @response))) |
| 13409 |
unless($pcdid =~ /[0-9a-f]/ && length($cdid) == 8); |
| 13410 |
chomp($discid = join("", grep(s/^DESCRIPTION=\s*//, @response))) |
| 13411 |
unless($discid =~ /\-$/ && length($discid) == 28); |
| 13412 |
} |
| 13413 |
# Final clean-up of IDs. We should incorporate passed ids here. |
| 13414 |
if(defined $cdid && $cdid =~ /[0-9a-f]/ && length($cdid) == 8) { |
| 13415 |
$cddbid = $cdid; |
| 13416 |
$cd{id} = $cddbid; |
| 13417 |
} |
| 13418 |
else{ |
| 13419 |
$cdid = "" unless($pcdid =~ /[0-9a-f]/ && length($cdid) == 8); |
| 13420 |
} |
| 13421 |
$discid = "" unless($discid =~ /\-$/ && length($discid) == 28); |
| 13422 |
$discid = $pcdid if($pcdid =~ /\-$/ && length($pcdid) == 28); |
| 13423 |
$cd{discid} = $discid if($discid ne ""); |
| 13424 |
last if($cdid ne "" and $discid ne ""); |
| 13425 |
} |
| 13426 |
# Read the potential flac files: |
| 13427 |
my @vartists = (); |
| 13428 |
my $ghostflag = 0; |
| 13429 |
@sndfiles = sort(@sndfiles); |
| 13430 |
foreach my $sndfile (@sndfiles) { |
| 13431 |
log_info("metaflac --export-tags-to=- \"$inputdir/$sndfile\"|"); |
| 13432 |
open(SND, "metaflac --export-tags-to=- \"$inputdir/$sndfile\"|"); |
| 13433 |
my @response = <SND>; |
| 13434 |
close(SND); |
| 13435 |
# Read out the meta data: |
| 13436 |
chomp($title = join('', grep(s/^TITLE=//i, @response))); |
| 13437 |
chomp($artist = join('', grep(s/^ARTIST=//i, @response))); |
| 13438 |
chomp($album = join('', grep(s/^ALBUM=//i, @response))); |
| 13439 |
chomp($categ = join('', grep(s/^CATEGORY=//i, @response))); |
| 13440 |
chomp($genre = join('', grep(s/^GENRE=//i, @response))); |
| 13441 |
chomp($reldate = join('', grep(s/^DATE=//i, @response))); |
| 13442 |
chomp($trackno = join('', grep(s/^TRACKNUMBER=//i, @response))); |
| 13443 |
|
| 13444 |
$album_utf8 = $album; |
| 13445 |
$artist_utf8 = $artist; |
| 13446 |
|
| 13447 |
my $year = $reldate; |
| 13448 |
$year =~ s/.*(\d{4}).*/$1/; |
| 13449 |
|
| 13450 |
# What if meta data is in VA style? First artist might not be the |
| 13451 |
# album artist and each artist tag from each track should be |
| 13452 |
# merged into the track title with VA option switched on ... |
| 13453 |
push(@vartists, $artist); |
| 13454 |
$cd{artist} = $artist; |
| 13455 |
$cd{title} = $album; |
| 13456 |
$cd{cat} = $categ; |
| 13457 |
$cd{genre} = $genre; |
| 13458 |
$cd{year} = $year; |
| 13459 |
|
| 13460 |
my $j = $trackno - 1; |
| 13461 |
$j = $trackno if($hiddenflag == 1); |
| 13462 |
if($trackno <= 0 or $trackno eq "00") { |
| 13463 |
$j = 0; |
| 13464 |
$hiddenflag = 1; |
| 13465 |
} |
| 13466 |
$ghostflag = 1 if($sndfile =~ /Ghost.Song/i); |
| 13467 |
# Ghost song in the middle means that more than one track will |
| 13468 |
# hold the same tracknumber if it comes from an original rip |
| 13469 |
# (done by Ripit). For the moment: increase track counter in each |
| 13470 |
# case a track has already been used. |
| 13471 |
while(defined $cd{track}[$j]) { |
| 13472 |
$j++; |
| 13473 |
last if($j > 100); |
| 13474 |
} |
| 13475 |
$cd{track}[$j] = $title; |
| 13476 |
# Fill the tracksel array here... or not? |
| 13477 |
# But as we do not use $trackno make sure to count the right way. |
| 13478 |
# Do not care about ghost songs anymore, they will be renamed. |
| 13479 |
push(@tracksel, $j+1); |
| 13480 |
} |
| 13481 |
if($vatag > 0) { |
| 13482 |
my $j = 0; |
| 13483 |
my $vaflag = 0; |
| 13484 |
|
| 13485 |
# Check if different artists are given. |
| 13486 |
foreach(@vartists) { |
| 13487 |
$vaflag = 1 if($_ ne $cd{artist}); |
| 13488 |
last if($vaflag == 1); |
| 13489 |
} |
| 13490 |
# In case VA style has been detected, ask for true artist name |
| 13491 |
# and recombine the track names with track artist. |
| 13492 |
if($vaflag > 0) { |
| 13493 |
if($interaction > 0) { |
| 13494 |
print "\nEnter album artist (Various Artists): "; |
| 13495 |
$cd{artist} = <STDIN>; |
| 13496 |
chomp($cd{artist}); |
| 13497 |
$cd{artist} = "Various Artists" if($cd{artist} eq ""); |
| 13498 |
} |
| 13499 |
else { |
| 13500 |
$cd{artist} = "Various Artists"; |
| 13501 |
} |
| 13502 |
$artist_utf8 = $artist; |
| 13503 |
foreach(@vartists) { |
| 13504 |
$cd{track}[$j] = $cd{track}[$j] . " / " . $_ |
| 13505 |
if($vatag % 2 == 0); |
| 13506 |
$cd{track}[$j] = $_ . " / " . $cd{track}[$j] |
| 13507 |
if($vatag % 2 == 1); |
| 13508 |
$j++; |
| 13509 |
} |
| 13510 |
} |
| 13511 |
} |
| 13512 |
} |
| 13513 |
######################################################################## |
| 13514 |
# |
| 13515 |
# Decode existing flac and create list of track names to be re-encoded. |
| 13516 |
# |
| 13517 |
sub decode_tracks { |
| 13518 |
# Check if wav are present in inputdir. |
| 13519 |
# Read the inputdir folder. |
| 13520 |
opendir (DIR, "$inputdir") or |
| 13521 |
print "Can't read inputdir $inputdir $!\n"; |
| 13522 |
my @dirfiles = readdir(DIR); |
| 13523 |
closedir(DIR); |
| 13524 |
@dirfiles = sort(@dirfiles); |
| 13525 |
my @wavfiles = grep { /\.wav$/ } @dirfiles; |
| 13526 |
my @sndfiles = grep { /\.flac$/ } @dirfiles; |
| 13527 |
# Decode flac to wav if flac directory has no wav in. We suppose: |
| 13528 |
# existing flac means no existing wav. Should operator decide on type |
| 13529 |
# of source in case both exist in $inputdir? |
| 13530 |
# Other problem: if inputdir does not correspond to the dirtemplate |
| 13531 |
# according to a wavdir has been created... While decoding use |
| 13532 |
# wavdir for output for encoder to find the file names. |
| 13533 |
# More problems: if operator changed wording, ripit still uses the |
| 13534 |
# original names here, but encoder expects wav with new wording... |
| 13535 |
if(@sndfiles) { |
| 13536 |
my $trcn = 0; |
| 13537 |
@tracklist_modif = @tracklist; |
| 13538 |
@tracklist = (); |
| 13539 |
foreach my $sndfile (@sndfiles) { |
| 13540 |
$trcn++; |
| 13541 |
my $wavfile = $sndfile; |
| 13542 |
$wavfile =~ s/\.flac$/.wav/; |
| 13543 |
if($verbose > 2) { |
| 13544 |
if(-f "$wavdir/$wavfile") { |
| 13545 |
print "No decoding of flac, WAV $wavfile exists under\n$wavdir\n"; |
| 13546 |
} |
| 13547 |
else { |
| 13548 |
print "Decoding $sndfile into $wavdir.\n" |
| 13549 |
} |
| 13550 |
} |
| 13551 |
log_system("flac $flacdecopt -d \"$inputdir/$sndfile\" -o \"$wavdir/$wavfile\"") |
| 13552 |
unless(-f "$wavdir/$wavfile"); |
| 13553 |
# Copy file to ensure track name according to look-up or |
| 13554 |
# actual archive data. |
| 13555 |
if(!-f "$wavdir/$wavfile" && $sndfile =~ /\.wav$/) { |
| 13556 |
print "WAV $wavfile is not present in $wavdir, going ", |
| 13557 |
"to copy the wav $sndfile to $wavdir.\n" |
| 13558 |
if($verbose > 2); |
| 13559 |
log_system("cp \"$inputdir/$sndfile\" \"$wavdir/$wavfile\""); |
| 13560 |
} |
| 13561 |
# These are the flac files we have in @tracksel, we use them as |
| 13562 |
# sources for re-encoding. |
| 13563 |
$wavfile =~ s/\.wav$//; |
| 13564 |
# In any case, fill the @tracklist array, even if decoder |
| 13565 |
# failed. |
| 13566 |
push(@tracklist, "$wavfile"); |
| 13567 |
if(!-f "$wavdir/$wavfile.wav") { |
| 13568 |
open(ERO,">>$wavdir/error.log") |
| 13569 |
or print "Can not append to file ", |
| 13570 |
"\"$wavdir/error.log\"!\n"; |
| 13571 |
print ERO "Track $trcn on CD $cd{artist} - $cd{title} ", |
| 13572 |
"failed!\n"; |
| 13573 |
close(ERO); |
| 13574 |
print "Warning: decoding $sndfile failed.\n" |
| 13575 |
if($verbose > 0); |
| 13576 |
log_info("Warning: decoding $sndfile failed"); |
| 13577 |
} |
| 13578 |
} |
| 13579 |
} |
| 13580 |
else { |
| 13581 |
my $tracksel_flag = 1; |
| 13582 |
$tracksel_flag = 0 if(defined $tracksel[0] && $tracksel[0] =~ /\d/); |
| 13583 |
foreach my $wavfile (@wavfiles) { |
| 13584 |
push(@tracksel, $tracksel_flag) if($tracksel_flag > 0); |
| 13585 |
$wavfile =~ s/\.wav$//; |
| 13586 |
push(@tracklist, $wavfile); |
| 13587 |
$tracksel_flag++ if($tracksel_flag > 0); |
| 13588 |
$wavdir =~ s/\/$// if($wavdir =~ /\//); |
| 13589 |
$inputdir =~ s/\/$// if($inputdir =~ /\//); |
| 13590 |
if($wavdir ne $inputdir) { |
| 13591 |
print "Copying $wavfile from $inputdir to $wavdir.\n\n" |
| 13592 |
if($verbose > 2); |
| 13593 |
log_system("cp \"$inputdir/$wavfile.wav\" \"$wavdir/$wavfile.wav\""); |
| 13594 |
} |
| 13595 |
} |
| 13596 |
} |
| 13597 |
# Question: do we really need framelist here? We already have one if |
| 13598 |
# we used MB to update tags needed to query freedb.org. Of course, |
| 13599 |
# this frame list has the "true" track length according to DB and not |
| 13600 |
# according to existing files; true means @ low precision as ripit |
| 13601 |
# did not retrieve sectors from MB but track lengths in seconds... |
| 13602 |
@framelist = 0; |
| 13603 |
my $prevtracklen = 0; |
| 13604 |
my $trcn = 0; |
| 13605 |
@secondlist = (); |
| 13606 |
foreach my $wavfile (@tracklist) { |
| 13607 |
$trcn++; |
| 13608 |
# Don't alter @tracklist. |
| 13609 |
my $trn = $wavfile; |
| 13610 |
$trn =~ s/$/.wav/; |
| 13611 |
# The location is now $wavdir, not $inputdir, see above. |
| 13612 |
my $tracklen = 0; |
| 13613 |
if(-f "$wavdir/$trn") { |
| 13614 |
$tracklen = -s "$wavdir/$trn"; |
| 13615 |
$tracklen = int(($tracklen - 44) / 2352 / 75); |
| 13616 |
} |
| 13617 |
else { |
| 13618 |
$tracklen = int(($framelist_orig[$trcn] - $framelist_orig[$trcn - 1]) / 75) if(defined $framelist_orig[$trcn]); |
| 13619 |
} |
| 13620 |
push(@framelist, int(($tracklen + $prevtracklen) * 75)); |
| 13621 |
push(@secondlist, $tracklen); |
| 13622 |
$prevtracklen = $tracklen; |
| 13623 |
} |
| 13624 |
} |
| 13625 |
######################################################################## |
| 13626 |
# |
| 13627 |
# Create a toc AoH usually read out of the disc in case of re-encoding |
| 13628 |
# used to retrieve freeDB data (genre) when using MB. |
| 13629 |
# |
| 13630 |
sub create_toc { |
| 13631 |
my @frames = @_; |
| 13632 |
my @r = (); |
| 13633 |
foreach my $i (@frames) { |
| 13634 |
my $sec = int($i / 75); |
| 13635 |
my $frame = $i % 75 if($sec > 0); |
| 13636 |
my $min = int($sec / 60); |
| 13637 |
$sec = $sec % 60 if($min > 0); |
| 13638 |
|
| 13639 |
my %cdtoc = (); |
| 13640 |
$cdtoc{min} = $min; |
| 13641 |
$cdtoc{sec} = $sec; |
| 13642 |
$cdtoc{frame} = $frame; |
| 13643 |
$cdtoc{frames} = $i; |
| 13644 |
|
| 13645 |
push(@r, \%cdtoc); |
| 13646 |
} |
| 13647 |
return @r; |
| 13648 |
} |
| 13649 |
######################################################################## |
| 13650 |
# |
| 13651 |
# Create a toc AoH usually read out of the disc in case of re-encoding |
| 13652 |
# used to retrieve freeDB data (genre) when using MB. |
| 13653 |
# |
| 13654 |
sub enc_report { |
| 13655 |
my $encline = shift; |
| 13656 |
my $trackcn = shift; |
| 13657 |
open(ENCLOG, "< $wavdir/enc.log"); |
| 13658 |
my @loglines = <ENCLOG>; |
| 13659 |
close(ENCLOG); |
| 13660 |
my $lincn = 0; |
| 13661 |
my @outlines = (); |
| 13662 |
foreach (@loglines) { |
| 13663 |
if($verbose >= 3) { |
| 13664 |
push(@outlines, $_) |
| 13665 |
if($lincn >= $encline && $_ !~ /^\n/); |
| 13666 |
} |
| 13667 |
elsif($verbose == 1 || $verbose == 2) { |
| 13668 |
print $_ if($lincn >= $encline && $_ =~ /complete\./); |
| 13669 |
} |
| 13670 |
$lincn++; |
| 13671 |
} |
| 13672 |
# Compact output. |
| 13673 |
$encline = $lincn; |
| 13674 |
if($outlines[0] && $verbose >= 1) { |
| 13675 |
if($trackcn <= $#tracksel || $accuracy == 1) { |
| 13676 |
push(@outlines, "*" x 47, "\n") if($verbose >= 3); |
| 13677 |
unshift(@outlines, "\n", "*" x 15, " Encoder reports ", |
| 13678 |
"*" x 15, "\n") if($verbose >= 3); |
| 13679 |
} |
| 13680 |
else { |
| 13681 |
print "\n", "*" x 47, "\nWaiting for encoder to finish...\n\n"; |
| 13682 |
} |
| 13683 |
print @outlines if($verbose >= 2); |
| 13684 |
} |
| 13685 |
return($encline); |
| 13686 |
} |
| 13687 |
######################################################################## |
| 13688 |
# |
| 13689 |
# Fill the error.log with encoder msgs. |
| 13690 |
# |
| 13691 |
sub enc_print { |
| 13692 |
my $string = shift; |
| 13693 |
my $inter = shift; |
| 13694 |
my $ripmsg = "The audio CD ripper reports: all done!"; |
| 13695 |
my $ripcomplete = 0; |
| 13696 |
if(-r "$wavdir/error.log") { |
| 13697 |
open(ERR, "$wavdir/error.log") |
| 13698 |
or print "Can not open file error.log!\n"; |
| 13699 |
my @errlines = <ERR>; |
| 13700 |
close(ERR); |
| 13701 |
my @ripcomplete = grep(/^$ripmsg/, @errlines); |
| 13702 |
$ripcomplete = 1 if(@ripcomplete); |
| 13703 |
if(-r "$wavdir/enc.log" && $ripcomplete == 0) { |
| 13704 |
open(ENCLOG, ">>$wavdir/enc.log"); |
| 13705 |
print ENCLOG "\n$string\n\n"; |
| 13706 |
close(ENCLOG); |
| 13707 |
} |
| 13708 |
else { |
| 13709 |
print "$string\n" if($verbose > $inter); |
| 13710 |
} |
| 13711 |
} |
| 13712 |
else { |
| 13713 |
print "$string\n" if($verbose > $inter); |
| 13714 |
} |
| 13715 |
} |
| 13716 |
######################################################################## |
| 13717 |
# |
| 13718 |
# Download coverart from coverartarchive.org |
| 13719 |
# |
| 13720 |
sub get_cover { |
| 13721 |
my $mbreid = $cd{mbreid} if($cd{mbreid}); |
| 13722 |
if(-f "$coverpath" and $overwrite ne "y") { |
| 13723 |
print "File $coverpath exists\nand option overwrite is not set ", |
| 13724 |
"to \"y\", no cover will be retrieved.\n\n" |
| 13725 |
if($verbose > 2); |
| 13726 |
return; |
| 13727 |
} |
| 13728 |
|
| 13729 |
if(defined $mbreid and $mbreid ne "" and $coverpath ne "") { |
| 13730 |
print "Retrieving coverart from coverartarchive.org.\n" |
| 13731 |
if($verbose > 2); |
| 13732 |
|
| 13733 |
# wget http://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd |
| 13734 |
# wget http://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/829521842.jpg |
| 13735 |
# wget http://coverartarchive.org/release/755c96ed-4c6e-4919-9542-8d78efa90244/3415268642-500.jpg |
| 13736 |
|
| 13737 |
eval { |
| 13738 |
my $ua = LWP::UserAgent->new(); |
| 13739 |
$ua->env_proxy(); |
| 13740 |
$ua->agent("ripit/$version"); |
| 13741 |
my $url = "http://coverartarchive.org/release/$mbreid/front"; |
| 13742 |
print "Request on $url.\n" if($verbose > 4); |
| 13743 |
my $response = $ua->get($url); |
| 13744 |
if ($response->is_error()) { |
| 13745 |
printf "%s\n", $response->status_line; |
| 13746 |
} |
| 13747 |
else { |
| 13748 |
my $content = $response->content(); |
| 13749 |
$response = $ua->get( |
| 13750 |
$url, |
| 13751 |
':content_file' => "$coverpath"); |
| 13752 |
} |
| 13753 |
} |
| 13754 |
} |
| 13755 |
elsif($coverpath eq "") { |
| 13756 |
print "No coverpath stated to retrieve coverart to.\n" |
| 13757 |
if($verbose > 2); |
| 13758 |
} |
| 13759 |
else { |
| 13760 |
print "No MB-release ID (MBREID) found to retrieve coverart ", |
| 13761 |
"from coverartarchive.org.\n" if($verbose > 2); |
| 13762 |
} |
| 13763 |
if(defined $cd{dgid} and $cd{dgid} =~ /\d+/) { |
| 13764 |
print "Retrieving coverart from discogs.com.\n" |
| 13765 |
if($verbose > 2); |
| 13766 |
my $dgid = $cd{dgid}; |
| 13767 |
chomp $dgid; |
| 13768 |
|
| 13769 |
my $dgcoverpath = $coverpath; |
| 13770 |
if(-f "$coverpath" && $coverpath =~ /jpeg/) { |
| 13771 |
$dgcoverpath =~ s/\.jpeg/-$dgid.jpeg/; |
| 13772 |
} |
| 13773 |
elsif(-f "$coverpath" && $coverpath =~ /jpg/) { |
| 13774 |
$dgcoverpath =~ s/\.jpg/-$dgid.jpg/; |
| 13775 |
} |
| 13776 |
elsif(-f "$coverpath" && $coverpath =~ /png/) { |
| 13777 |
$dgcoverpath =~ s/\.png/-$dgid.png/; |
| 13778 |
} |
| 13779 |
elsif(-f "$coverpath") { |
| 13780 |
$dgcoverpath =~ s/$/-$dgid/; |
| 13781 |
} |
| 13782 |
|
| 13783 |
eval { |
| 13784 |
my $ua = LWP::UserAgent->new(); |
| 13785 |
$ua->env_proxy(); |
| 13786 |
$ua->agent("ripit/$version"); |
| 13787 |
my $base_url = "http://www.discogs.com/viewimages?release=$dgid"; |
| 13788 |
my @pics = (); |
| 13789 |
print "Request on $base_url.\n" if($verbose > 3); |
| 13790 |
my $response = $ua->get($base_url); |
| 13791 |
if ($response->is_error()) { |
| 13792 |
printf "%s\n", $response->status_line; |
| 13793 |
} |
| 13794 |
else { |
| 13795 |
my $content = $response->content(); |
| 13796 |
my @content = split(/\n/, $content); |
| 13797 |
my @url = grep(/http:\/\/s.pixogs.com\/image\/R-$dgid/, @content); |
| 13798 |
foreach(@url) { |
| 13799 |
s;.?img src="http://s.pixogs;http://s.pixogs;; |
| 13800 |
push(@pics, split(/"\s+\/><\/span><\/p>/, $_)); |
| 13801 |
} |
| 13802 |
foreach(@pics) { |
| 13803 |
s;.*?http://s.pixogs;http://s.pixogs;; |
| 13804 |
s;".*$;;; |
| 13805 |
} |
| 13806 |
} |
| 13807 |
print "Request on $pics[0].\n" if($verbose > 3); |
| 13808 |
$response = $ua->get($pics[0], Referer => $base_url); |
| 13809 |
if ($response->is_error()) { |
| 13810 |
printf "%s\n", $response->status_line; |
| 13811 |
} |
| 13812 |
else { |
| 13813 |
my $content = $response->content(); |
| 13814 |
$response = $ua->get( |
| 13815 |
$pics[0], |
| 13816 |
':content_file' => "$dgcoverpath"); |
| 13817 |
} |
| 13818 |
# Sometimes the artwork downloaded is a gif instead of an |
| 13819 |
# expected jpeg. |
| 13820 |
if(defined $pics[0] && $pics[0] =~ /\.gif$/) { |
| 13821 |
# Convert the gif to a jpg using the same file name. |
| 13822 |
log_system("convert \"$dgcoverpath\" \"$dgcoverpath\""); |
| 13823 |
} |
| 13824 |
} |
| 13825 |
} |
| 13826 |
} |
| 13827 |
######################################################################## |
| 13828 |
# |
| 13829 |
# Split the tracktag into its artist part and track part if |
| 13830 |
# VA style is used. |
| 13831 |
sub split_tags { |
| 13832 |
my $tracktag = shift; |
| 13833 |
my $delim = shift; |
| 13834 |
|
| 13835 |
my $artistag = ""; |
| 13836 |
if($vatag % 2 == 1) { |
| 13837 |
($artistag, $tracktag) = split(/$delim/, $tracktag); |
| 13838 |
$tracktag =~ s/\)// if($delim =~ /\(/); |
| 13839 |
$tracktag =~ s/^\s*//; |
| 13840 |
$artistag =~ s/\s*$//; |
| 13841 |
# If artistag got all info, rather use it as tracktag... |
| 13842 |
if($tracktag eq "") { |
| 13843 |
$tracktag = $artistag; |
| 13844 |
$artistag = ""; |
| 13845 |
} |
| 13846 |
} |
| 13847 |
else { |
| 13848 |
($tracktag, $artistag) = split(/$delim/, $tracktag); |
| 13849 |
$artistag =~ s/\)// if($delim =~ /\(/); |
| 13850 |
$artistag =~ s/^\s*//; |
| 13851 |
$tracktag =~ s/\s*$//; |
| 13852 |
} |
| 13853 |
|
| 13854 |
return($artistag, $tracktag); |
| 13855 |
} |
| 13856 |
######################################################################## |
| 13857 |
# |
| 13858 |
# Delete lock files in case utftag is used and the encoding command |
| 13859 |
# can not hold the clean-up parts. |
| 13860 |
sub del_lock { |
| 13861 |
my $wavdir = shift; |
| 13862 |
my $lockfile = shift; |
| 13863 |
my $ret = 2; |
| 13864 |
open(LOCK, "$wavdir/$lockfile"); |
| 13865 |
my @locklines = <LOCK>; |
| 13866 |
close(LOCK); |
| 13867 |
|
| 13868 |
my @shorts = grep(s/^short-in:\s//, @locklines); |
| 13869 |
my @full = grep(s/^full-out:\s//, @locklines); |
| 13870 |
chomp(my $shortname = $shorts[0]) if(defined $shorts[0]); |
| 13871 |
chomp(my $ripnam = $full[0]) if(defined $full[0]); |
| 13872 |
if(defined $shortname && -r "$shortname") { |
| 13873 |
log_system("mv \"$shortname\" \"$ripnam\" &"); |
| 13874 |
unlink("$wavdir/$lockfile"); |
| 13875 |
$ret = 0; |
| 13876 |
} |
| 13877 |
return($ret); |
| 13878 |
} |
| 13879 |
######################################################################## |
| 13880 |
# |
| 13881 |
sub check_audio { |
| 13882 |
if($ripper == 2) { |
| 13883 |
my $mcn = undef; |
| 13884 |
push(@audio, ' '); |
| 13885 |
# open(ICEDAX, "icedax -D $scsi_cddev -g -H -J -Q -v trackid 2>&1 |") |
| 13886 |
open(ICEDAX, "icedax -D $scsi_cddev -g -H -J -Q -v toc 2>&1 |") |
| 13887 |
or print "\nFailed to run icedax command: $!\n"; |
| 13888 |
while(<ICEDAX>) { |
| 13889 |
chomp; |
| 13890 |
# Example output: |
| 13891 |
# T15: 146378 41:31.48 audio linear copydenied stereo title '' from '' |
| 13892 |
# T16: 333251 2:21.54 data uninterrupted copydenied N/A |
| 13893 |
# T17: 343880 0:00.31 audio linear copydenied stereo title '' from '' |
| 13894 |
if(/T(\d+):\s+\d+\s+\d+:\d{2}\.\d{2}\s([a-z]*)\s.*$/) { |
| 13895 |
my ($num, $typ) = ($1, $2); |
| 13896 |
$typ = ($typ eq "data" ? '*' : ' '); |
| 13897 |
$audio[$num] = $typ; |
| 13898 |
} |
| 13899 |
elsif(/Media catalog number: (.+)/i) { |
| 13900 |
$mcn = $1; |
| 13901 |
} |
| 13902 |
} |
| 13903 |
close(ICEDAX); |
| 13904 |
} |
| 13905 |
else { |
| 13906 |
my $tcn = 0; |
| 13907 |
# cdparanoia -Q |& grep \"^\\s*[[:digit:]]\" | wc -l |
| 13908 |
open(CDPARA, "cdparanoia -d $scsi_cddev -Q 2>&1 |") |
| 13909 |
or print "\nFailed to run cdparanoia command: $!\n"; |
| 13910 |
while(<CDPARA>) { |
| 13911 |
chomp; |
| 13912 |
if(/^\s+(\d+)\.\s+(\d+).*/) { |
| 13913 |
my ($num, $ff) = ($1, $2); |
| 13914 |
while($tcn < $num) { |
| 13915 |
$audio[$tcn] = '*'; |
| 13916 |
$tcn++; |
| 13917 |
} |
| 13918 |
$audio[$num] = ' '; |
| 13919 |
$tcn++; |
| 13920 |
} |
| 13921 |
} |
| 13922 |
close(CDPARA); |
| 13923 |
$audio[0] = ' '; |
| 13924 |
} |
| 13925 |
} |