sanitize_tl.pl 886 B

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