From ade66a4a1b9f426f76595b30b4d7abfe9c698a13 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 14 Sep 2018 11:00:10 -0400 Subject: [PATCH] prevent shuffle loop from getting stuck in folder with no music --- musik.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/musik.py b/musik.py index c4de89c..dd241d4 100755 --- a/musik.py +++ b/musik.py @@ -87,12 +87,17 @@ def shuffle(): """Returns a randomly selected song from the library.""" item = random.choice(os.listdir(MUSIC_DIR)) path = os.path.join(MUSIC_DIR, item) - while not path.rpartition('.')[2] in MUSIC_EXT: + n = 0 + while not item.rpartition('.')[2] in MUSIC_EXT: + n += 1 item = random.choice(os.listdir(path)) if os.path.isdir(os.path.join(path, item)): path = os.path.join(path, item) - if item.rpartition('.')[2] in MUSIC_EXT: - path = os.path.join(path, item) + if n == 5: + item = random.choice(os.listdir(MUSIC_DIR)) + path = os.path.join(MUSIC_DIR, item) + n = 0 + path = os.path.join(path, item) return path.replace(MUSIC_DIR, '')