initial commit

This commit is contained in:
Sebastian Hugentobler 2023-06-22 09:50:12 +02:00
commit e88a2dde6e
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0
3 changed files with 75 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*~
.DS_Store
*.pkg.tar.zst
*.pkg.tar.zst.sig

20
PKGBUILD Normal file
View File

@ -0,0 +1,20 @@
# Maintainer: Sebastian Hugentobler <shu@vanwa.ch>
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"
}

51
split-audacity-labels Executable file
View File

@ -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 <original_track> <track_list>")
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()