Skip to content

Instantly share code, notes, and snippets.

@kugland
Created March 13, 2023 05:35
Show Gist options
  • Save kugland/44d74d4a50fac3fafe201fc9d0544bba to your computer and use it in GitHub Desktop.
Save kugland/44d74d4a50fac3fafe201fc9d0544bba to your computer and use it in GitHub Desktop.
Multiply the time values in a CUE file by a factor.
#!/usr/bin/env -S perl -CSDA
# Multiply the time values in a CUE file by a factor.
use strict;
use warnings;
use utf8;
use autodie;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
my $factor;
GetOptions(
"factor|f=f" => \$factor,
) or die "Usage: $0 -f FACTOR < INPUT > OUTPUT\n";
if (!defined($factor)) {
die "Usage: $0 -f FACTOR < INPUT > OUTPUT\n";
}
sub apply_factor {
my ($m, $s, $f) = @_;
my $n = (($m * 60 + $s) * 75 + $f) * $factor;
$f = $n % 75;
$n = int($n / 75);
$s = $n % 60;
$n = int($n / 60);
$m = $n;
return sprintf("%02d:%02d:%02d", $m, $s, $f);
}
for (<>) {
s{
(?<indent>\s*) INDEX
\s+ (?<idx>\d\d)
\s+ (?<m>\d\d):(?<s>\d\d):(?<f>\d\d)
}{
$+{indent} . "INDEX " . $+{idx} . " " . apply_factor($+{m}, $+{s}, $+{f})
}egmsx;
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment