From e2f8339d5a0543100dd5b382d9f5fe292491e212 Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Mon, 10 Jul 2023 21:55:33 -0400 Subject: bin: small fixes --- bin/shuffle | 62 +++++++++++++++++++++++++++++++---------------------------- bin/statusbar | 3 ++- 2 files changed, 35 insertions(+), 30 deletions(-) mode change 100644 => 100755 bin/statusbar diff --git a/bin/shuffle b/bin/shuffle index a8bfdc4..103b95c 100755 --- a/bin/shuffle +++ b/bin/shuffle @@ -5,38 +5,42 @@ import random import os import subprocess -parser = argparse.ArgumentParser( - prog='shuffle', - description='play audio files in a directory in random order') -parser.add_argument( - 'path', - default='.', - nargs='?', - help= - 'play files in , or the current directory if is not passed') -parser.add_argument('-m', - dest='mpv_opts', - default=['--no-video'], - action='append', - help='pass to mpv') -args = parser.parse_args() +def main(): + parser = argparse.ArgumentParser( + prog='shuffle', + description='play audio files in a directory in random order') + parser.add_argument( + 'path', + default='.', + nargs='?', + help= + 'play files in , or the current directory if is not passed') + parser.add_argument('-m', + dest='mpv_opts', + default=['--no-video'], + action='append', + help='pass to mpv') + args = parser.parse_args() -prev = [] + # Keep track of the last few files we played and avoid playing them again + prev = [] -while True: - files = [ - os.path.join(root, file) for root, _, files in os.walk(args.path) - for file in files - ] - file = random.choice(files) - while file in prev: + while True: + files = [ + os.path.join(root, file) for root, _, files in os.walk(args.path) + for file in files + ] + for f in prev: + files.remove(f) file = random.choice(files) - prev.append(file) - if len(prev) > 2: - del prev[:len(prev) - 3] + prev.append(file) + del prev[:len(prev) - 2] - print('Playing', file) - try: + print('Playing', file) subprocess.run(['mpv', *args.mpv_opts, file]) + +if __name__ == "__main__": + try: + main() except KeyboardInterrupt: - break + pass diff --git a/bin/statusbar b/bin/statusbar old mode 100644 new mode 100755 index 8d5dc6f..d628578 --- a/bin/statusbar +++ b/bin/statusbar @@ -2,6 +2,7 @@ import subprocess import time +import traceback import re @@ -70,5 +71,5 @@ while True: subprocess.run(['somebar', '-c', 'status', status]) prev = status except Exception as e: - print(e) + print(''.join(traceback.format_exception(None, e, e.__traceback__))) time.sleep(1 - time.time() % 1) -- cgit v1.2.3