prevent shuffle loop from getting stuck in folder with no music

This commit is contained in:
iou1name 2018-09-14 11:00:10 -04:00
parent fbec8d886e
commit ade66a4a1b

View File

@ -87,11 +87,16 @@ 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:
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, '')