Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Created August 12, 2010 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpavlin/521441 to your computer and use it in GitHub Desktop.
Save dpavlin/521441 to your computer and use it in GitHub Desktop.
Dump labels from Audacity into <li> with formatting
#!/usr/bin/perl
# usage:
# ./audacity-labels.pl 6-nosql-take-3.aup
use warnings;
use strict;
use XML::Simple;
use Data::Dump qw(dump);
sub mm_ss {
my $t = shift;
return sprintf('%d:%02d', $t / 60, $t % 60);
}
my $out;
sub dump_labels {
my $labels = shift;
die "not ARRAY" unless ref $labels eq 'ARRAY';
foreach my $label ( @$labels ) {
warn dump($label);
my $html = $label->{title} || die "no title in ",dump($label);
$html =~ s{^(\w+:\s*)?(.*?\S+)\s*(https?://\S+)\s*$}{$1<a href="$3">$2</a>};
$out .= join('', '<li>'
, mm_ss( $label->{t} ), '-', mm_ss( $label->{t1} )
, " ", $html
, $/
);
}
}
open(my $xclip, '|-', 'xclip -i -selection clipboard') || warn "can't open xclip: $!";
my $hash = XMLin( shift @ARGV );
my $labels = $hash->{labeltrack} || die "can't find labeltrack in ",dump($hash);
if ( exists $labels->{label} ) { # older audacity
dump_labels $labels->{label};
} elsif ( ref $labels eq 'HASH' ) {
foreach my $name ( keys %$labels ) {
warn "# label: $name\n";
dump_labels $labels->{$name}->{label};
}
}
print $out;
print $xclip "<ul>$out</ul>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment