From e88a2dde6e9154b3376ef89e5562bfee471bd0d3 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 22 Jun 2023 09:50:12 +0200 Subject: [PATCH] initial commit --- .gitignore | 4 ++++ PKGBUILD | 20 +++++++++++++++++ split-audacity-labels | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 PKGBUILD create mode 100755 split-audacity-labels diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..765efc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +.DS_Store +*.pkg.tar.zst +*.pkg.tar.zst.sig diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..99436da --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,20 @@ +# Maintainer: Sebastian Hugentobler + +pkgname=split-audacity-labels +pkgver=0.1.0 +pkgrel=1 +pkgdesc="Split an audio file along exported audacity labels." +arch=("any") +url="https://code.vanwa.ch" +license=('MIT') +depends=("ffmpeg" "python3") +source=( + "split-audacity-labels" +) +sha256sums=("afd19f69358908cdbf2cd6048567ed32cd27ae22da1a69962eb6a5d7e30d84bb") + +package() { + cd "$srcdir/" + + install -Dm 755 split-audacity-labels "$pkgdir/usr/bin/split-audacity-labels" +} diff --git a/split-audacity-labels b/split-audacity-labels new file mode 100755 index 0000000..8c2fe17 --- /dev/null +++ b/split-audacity-labels @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import subprocess +import sys + + +def main(): + """split a music track into specified sub-tracks by calling ffmpeg from the shell""" + + # check command line for original file and track list file + if len(sys.argv) != 3: + print("usage: split ") + exit(1) + + # record command line args + original_track = sys.argv[1] + track_list = sys.argv[2] + + # create a template of the ffmpeg call in advance + cmd_string = 'ffmpeg -i "{tr}" -acodec copy -ss {st} -to {en} "{nm}.m4a"' + cmd_end_string = 'ffmpeg -i "{tr}" -acodec copy -ss {st} "{nm}.m4a"' + + # read each line of the track list and split into start, end, name + lines = [] + with open(track_list, "r") as f: + lines = f.readlines() + + for idx, line in enumerate(lines): + next_line = None if idx + 1 == len(lines) else lines[idx + 1] + + # skip comment and empty lines + if line.startswith("#") or len(line) <= 1: + continue + + # create command string for a given track + _, start, name = line.strip().split("\t") + name = "{nr:0>2d} {nm}".format(nr=idx + 1, nm=name) + + command = None + if next_line is not None: + end, _, _ = next_line.strip().split("\t") + command = cmd_string.format(tr=original_track, st=start, en=end, nm=name) + else: + command = cmd_end_string.format(tr=original_track, st=start, nm=name) + + # use subprocess to execute the command in the shell + subprocess.call(command, shell=True) + + +if __name__ == "__main__": + main()