prevent shuffle loop from getting stuck in folder with no music
This commit is contained in:
parent
fbec8d886e
commit
ade66a4a1b
11
musik.py
11
musik.py
|
@ -87,12 +87,17 @@ def shuffle():
|
||||||
"""Returns a randomly selected song from the library."""
|
"""Returns a randomly selected song from the library."""
|
||||||
item = random.choice(os.listdir(MUSIC_DIR))
|
item = random.choice(os.listdir(MUSIC_DIR))
|
||||||
path = os.path.join(MUSIC_DIR, item)
|
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))
|
item = random.choice(os.listdir(path))
|
||||||
if os.path.isdir(os.path.join(path, item)):
|
if os.path.isdir(os.path.join(path, item)):
|
||||||
path = os.path.join(path, item)
|
path = os.path.join(path, item)
|
||||||
if item.rpartition('.')[2] in MUSIC_EXT:
|
if n == 5:
|
||||||
path = os.path.join(path, item)
|
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, '')
|
return path.replace(MUSIC_DIR, '')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user