From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH] add dtas-2splitfx script
Date: Mon, 3 Jul 2023 00:43:05 +0000 [thread overview]
Message-ID: <20230703004305.928254-1-e@80x24.org> (raw)
This generates a dtas-splitfx-compatible YAML snippet based
on a sorted list of audio tracks:
dtas-2splitfx 1.flac 2.flac ... >tracks.yml
---
GNUmakefile | 2 +-
script/dtas-2splitfx | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
create mode 100755 script/dtas-2splitfx
diff --git a/GNUmakefile b/GNUmakefile
index 084a2d8..9019b31 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -82,7 +82,7 @@ bindir = $(prefix)/bin
symlink-install :
mkdir -p $(bindir)
dtas=$(CURDIR)/dtas.sh && cd $(bindir) && \
- for x in $(CURDIR)/bin/*; do \
+ for x in $(CURDIR)/bin/* $(CURDIR)/script/*; do \
ln -sf "$$dtas" $$(basename "$$x"); \
done
diff --git a/script/dtas-2splitfx b/script/dtas-2splitfx
new file mode 100755
index 0000000..afa761d
--- /dev/null
+++ b/script/dtas-2splitfx
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+# Copyright (C) all contributors <dtas-all@nongnu.org>
+# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
+# parse soxi output and generates a dtas-splitfx-compatible YAML snippet
+# usage: dtas-2splitfx 1.flac 2.flac ... >tracks.yml
+use v5.12;
+use POSIX qw(strftime);
+open my $fh, '-|', 'soxi', @ARGV or die $!;
+my $title = '';
+my $off = 0;
+my $sec = 0;
+
+my $flush = sub {
+ my ($start) = @_;
+ my $frac = $start =~ s/\.([0-9]+)\z// ? $1 : 0;
+ $start = strftime('%H:%M:%S', gmtime($start));
+ $start .= ".$frac" if $frac;
+ $start;
+};
+
+while (<$fh>) {
+ if (/^Duration\s*:\s*([0-9:\.]+)/) {
+ my $t = $1;
+ $sec = $t =~ s/\.([0-9]+)\z// ? "0.$1" : 0;
+ my @t = split(/:/, $t); # HH:MM:SS
+ my $mult = 1;
+ while (defined(my $part = pop @t)) {
+ $sec += $part * $mult;
+ $mult *= 60;
+ }
+ } elsif (s/^title=//i) {
+ chomp;
+ $title = $_;
+ $title =~ tr!"!'!;
+ } elsif (/^\s*\z/s && $sec) {
+ my $start = $flush->($off);
+ say qq(- t $start "), , $title, '"';
+ $off += $sec;
+ $sec = 0;
+ $title = '';
+ }
+}
+close $fh or die "soxi failed: \$?=$?";
+say qq(- stop ), $flush->($off);
reply other threads:[~2023-07-03 0:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/dtas/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230703004305.928254-1-e@80x24.org \
--to=e@80x24.org \
--cc=dtas-all@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).