#!/usr/bin/perl
# ----------------------------------------------------------------
#
# MusicBank.pm
#
# A tool from the MusicBank system
#
# Copyright (C) 2005 Josef C. Grosch (jgrosch@mooseriver.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
#
# Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# ----------------------------------------------------------------
#
# $Id: mbpm.html,v 1.1 2008/07/23 01:18:45 jgrosch Exp $
#
package MusicBank;
use English;
use Exporter;
use Digest::MD5;
use DBI;
use Time::Local;
use Time::JulianDay;
use strict;
use vars qw($VERSION @ISA @EXPORT @EPORT_OK %EXPORT_TAGS $YES $NO $music_base
$stage_base $alpha_stage $music_location $alpha_base
@BaseDirs @InitDirs);
@ISA = qw(Exporter);
@EXPORT = qw($YES $NO $music_base $stage_base $alpha_stage &GetTmpDir
&Md5File &createMandatoryDirs $music_location $alpha_base
&normalizeArtistName @BaseDirs @InitDirs);
$VERSION = 1.0;
$YES = 1;
$NO = 0;
$music_base = "/usr3/Music";
$alpha_base = "$music_base/Alpha";
$stage_base = "$music_base/Rip/Stage";
$alpha_stage = "$music_base/Rip/AlphaStage/";
$music_location = "$music_base/Data/music_location.db";
@BaseDirs = qw (LiveRecording Misc Notes PlayLists CD-Covers);
@InitDirs = qw(0-9 A B C D E F G H I J K L M N O
P Q R S T U V W X Y Z);
# ----------------------------------------------------------------
# The TMPDIR problem
# ----------------------------------------------------------------
sub GetTmpDir {
my $tmpdir = $ENV{"TMPDIR"};
if ($tmpdir eq "") {
$tmpdir = "/usr/tmp" unless ! -e "/usr/tmp";
if ($tmpdir eq "") {
$tmpdir = "/var/tmp" unless ! -e "/var/tmp";
if ($tmpdir eq "") {
$tmpdir = "/tmp" unless ! -e "/tmp";
}
}
}
$tmpdir;
} # End of GetTmpDir
# ----------------------------------------------------------------
# Md5File
# ----------------------------------------------------------------
sub Md5File {
my ($file_name) = @_;
no strict 'subs';
my $ctx = Digest::MD5->new;
open IMAGE, "<$file_name" or die "Can't open $file_name\n";
$ctx->addfile(IMAGE);
my $md5 = $ctx->hexdigest;
close IMAGE;
$ctx->reset;
$md5;
} # End of Md5File
# ----------------------------------------------------------------
# createMandatoryDirs
# ----------------------------------------------------------------
sub createMandatoryDirs {
my ($base) = @_;
my ($dir, $str);
foreach $dir (@BaseDirs) {
$str = sprintf("%s/%s", $base, $dir);
`mkdir -p $str`;
} # End of foreach loop
} #End of createMandatoryDirs
# -----------------------------------------------------
# normalizeArtistName
# -----------------------------------------------------
sub normalizeArtistName {
my ($line) = @_;
my (@bits, $part, $part_save, $bit, $uc_bit, $bit_save);
my (@parts);
$line =~ tr/A-Z/a-z/;
$line =~ tr/-/_/;
@parts = split /\//, $line;
foreach $part (@parts) {
$part_save = $part;
@bits = split /\_/, $part;
foreach $bit (@bits) {
$uc_bit = ucfirst $bit;
$part =~ s/$bit/$uc_bit/;
} # end of foreach $bit
$part =~ tr/_/-/;
$line =~ s/$part_save/$part/;
} # End of foreach $part
return $line;
} # End of normalizeArtistName
# --------------------------------------------------
# MUST BE LAST !!!!
# --------------------------------------------------
$YES;