diff options
| -rwxr-xr-x | bin/shuffle | 62 | ||||
| -rwxr-xr-x[-rw-r--r--] | bin/statusbar | 3 |
2 files changed, 35 insertions, 30 deletions
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 <path>, or the current directory if <path> is not passed') -parser.add_argument('-m', - dest='mpv_opts', - default=['--no-video'], - action='append', - help='pass <opts> 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 <path>, or the current directory if <path> is not passed') + parser.add_argument('-m', + dest='mpv_opts', + default=['--no-video'], + action='append', + help='pass <opts> 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 index 8d5dc6f..d628578 100644..100755 --- 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) |
