sanitize_tl.pl
1	#!/usr/bin/perl
2
3 # Move time codes to end of each line
4 # and clean some other stuff up if needed
5
6 use strict;
7 use warnings;
8
9 if ( ! defined $ARGV[0] ) {
10 print "Need to pass track list\n";
11 exit 1;
12 }
13
14 my $file = shift(@ARGV);
15
16 foreach my $line ( split("\n", `cat $file`) ) {
17 chomp $line;
18 if ( $line =~ m/([0-9]{2}:[0-9]{2}|[0-9]{1,2}:[0-9]{2}:[0-9]{2})/ ) {
19 my $time_code = $1;
20 $line =~ s/ $time_code//g;
21 $line = $line . " " . $time_code;
22 }
23
24 if ( $line !~ m/^[0-9]{1,2}\./ ) {
25 $line =~ s/^([0-9]{1,2})//g;
26 my $track_number = $1;
27 $line = "$track_number" . "." . "$line";
28 }
29
30 my $sanitized_line;
31 open(my $fh, ">>", \$sanitized_line);
32 my @line_chars = split("",$line);
33 foreach my $char ( @line_chars ) {
34 if ( $char !~ m/[a-zA-Z0-9:\s\.-]/ ) {
35 $char = "";
36 print $fh "$char";
37 } else {
38 print $fh "$char";
39 }
40 }
41
42 close $fh;
43 print "$sanitized_line\n";
44
45 }
46