-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchname
executable file
·108 lines (90 loc) · 2.36 KB
/
batchname
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl -w
use strict;
use diagnostics;
if ($#ARGV != 0)
{
&printusage;
}
# Check and make sure there are args before doing
# anything with them
my @args=@ARGV;
&main;
sub main
{
my $arg="$args[0]";
my $counter=0;
my $line;
my $artist;
my $title;
my @move;
my $number;
my $filename;
my $origname;
my @list;
my ($help,$qmark)=($arg,$arg);
$help=~/help/;
$qmark=~/\?/; # ? needs to be escaped in TCSH and shit....
if (($help eq "help") || ($qmark eq "?"))
{
&printusage;
}
else
{
open (NAMES, "$arg") || die "Can't open file $arg.\n";
while ($line=<NAMES>)
{
if ($counter == 0)
{
$artist=$line;
chomp($artist);
$artist=&correctname($artist);
++$counter;
}
else
{
$title=$line;
chomp($title);
$title=&correctname($title);
@list=("$counter");
if ($counter < 10)
{
$origname="track0".$counter.".cdda.mp3";
$filename="$artist-0".$counter."-$title.mp3";
}
else
{
$origname="track".$counter.".cdda.mp3";
$filename="$artist-".$counter."-$title.mp3";
}
rename ($origname,$filename);
++$counter;
}
}
}
close NAMES;
}
sub printusage
{
print "Usage is batchname namefile\n";
print "Where name file is a text file in this form:\n";
print "Artist Name\n";
print "Song 1\n";
print "Song 2\n";
print "etc..\n";
exit(0);
}
sub correctname
{
my ( $arg2 ) = @_;
$arg2 =~ s/\'//g; #replace ' with nothing
$arg2 =~ s/[^\w\.\-]/_/g; #replace non-word or . or - with _
$arg2 =~ s/\_+\-/\-/g; #replace _- with -
$arg2 =~ s/\-\_+/\-/g; #replace -_ with -
$arg2 =~ s/\_+/\_/g; #replace __ with _
$arg2 =~ s/^\_+//; #remove leading __'s
$arg2 =~ s/\_+$//; #remove trailing __'s
$arg2 =~ s/\.+/\./g; #replace .. with .
$arg2 =~ s/\_+\./\./g; #replace _. with .
$arg2 =~ s/\.\_+/\./g; #replace ._ with .
return $arg2;
}