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, '')