nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

commit 7bf641722814c68fe639d3fe960cd6b3953f8965
parent 9635505a884c821fcb97a4cbaa1eb54e86357691
Author: mtmn <miro@haravara.org>
Date:   Sun, 28 Jun 2026 18:22:24 +0200

audio: add f2opus script, etc.

Diffstat:
Mhosts/void/overlays/config/magdalena/config.json.nix | 0
Amodules/mixins/dotfiles/bin/f2opus | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/mixins/dotfiles/config/newsraft/feeds | 1+
3 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/hosts/void/overlays/config/magdalena/config.json.nix b/hosts/void/overlays/config/magdalena/config.json.nix Binary files differ. diff --git a/modules/mixins/dotfiles/bin/f2opus b/modules/mixins/dotfiles/bin/f2opus @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +import argparse +import concurrent.futures +import os +import subprocess +from itertools import count +from pathlib import Path + +FFMPEG_IN = ( + "ffmpeg", + "-hide_banner", + "-loglevel", + "error", + "-nostdin", + "-threads", + "1", +) +FFMPEG_OUT = ( + "-c:a", + "libopus", + "-b:a", + "160k", + "-vbr", + "on", + "-map_metadata", + "0", + "-f", + "opus", + "-y", +) + + +def convert(in_path, out_path, total, counter): + tmp = out_path.with_name(out_path.name + ".part") + if out_path.exists() and out_path.stat().st_size > 0: + tmp.unlink(missing_ok=True) + in_path.unlink() + i = next(counter) + print(f"[{i}/{total}] SKIP {in_path}") + return True + + tmp.unlink(missing_ok=True) + result = subprocess.run( + [*FFMPEG_IN, "-i", str(in_path), *FFMPEG_OUT, str(tmp)], + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE, + ) + i = next(counter) + if result.returncode == 0 and tmp.exists() and tmp.stat().st_size > 0: + os.replace(tmp, out_path) + in_path.unlink() + print(f"[{i}/{total}] OK {in_path}") + return True + + tmp.unlink(missing_ok=True) + print(f"[{i}/{total}] FAIL {in_path}") + if result.stderr: + print(f" {result.stderr.decode().strip().splitlines()[-1]}") + return False + + +def main(): + parser = argparse.ArgumentParser( + description="Convert FLAC files to Opus in using ffmpeg" + ) + parser.add_argument( + "root", nargs="?", default=".", help="directory to search for FLAC files" + ) + parser.add_argument( + "workers", + nargs="?", + type=int, + default=2 * (os.cpu_count() or 1), + help="ffmpeg workers count", + ) + args = parser.parse_args() + + root = Path(args.root).resolve() + jobs = sorted( + (p.resolve(), p.with_suffix(".opus").resolve()) for p in root.rglob("*.flac") + ) + total = len(jobs) + if total == 0: + print("No FLAC files found") + return + + print(f"Found {total} FLAC files in {root}") + print(f"Workers: {args.workers}\n") + + counter = count(1) + failed = [] + + with concurrent.futures.ThreadPoolExecutor(max_workers=args.workers) as ex: + future_to_in = { + ex.submit(convert, in_path, out_path, total, counter): in_path + for in_path, out_path in jobs + } + for future in concurrent.futures.as_completed(future_to_in): + if not future.result(): + failed.append(future_to_in[future]) + + print(f"\nDone: {total - len(failed)}/{total} converted") + if failed: + print(f"{len(failed)} failed:") + for f in failed: + print(f" {f}") + + +if __name__ == "__main__": + main() diff --git a/modules/mixins/dotfiles/config/newsraft/feeds b/modules/mixins/dotfiles/config/newsraft/feeds @@ -249,3 +249,4 @@ https://www.youtube.com/feeds/videos.xml?channel_id=UCqJ-Xo29CKyLTjn6z2XwYAw GMT https://www.youtube.com/feeds/videos.xml?channel_id=UC1ydE9gDHTdvbNVIgEKIKzw VWestlife https://www.youtube.com/feeds/videos.xml?channel_id=UCpOJZSocCYp9ufh9qF5W5vQ Cursed Controls https://www.youtube.com/feeds/videos.xml?channel_id=UC7Jwj9fkrf1adN4fMmTkpug DankPods +https://www.youtube.com/feeds/videos.xml?channel_id=UC_n6DdR6FClpCbWnNM7Zp6A SpaceRex