mirror of
https://github.com/beetbox/beets.git
synced 2026-02-24 08:12:54 +01:00
importer now walks directories in sorted order
This commit is contained in:
parent
967e875d04
commit
d422f7423b
1 changed files with 27 additions and 1 deletions
|
|
@ -71,13 +71,39 @@ def _first_n(it, n):
|
|||
break
|
||||
yield v
|
||||
|
||||
def _sorted_walk(path):
|
||||
"""Like os.walk, but yields things in sorted, breadth-first
|
||||
order.
|
||||
"""
|
||||
# Get all the directories and files at this level.
|
||||
dirs = []
|
||||
files = []
|
||||
for base in os.listdir(path):
|
||||
cur = os.path.join(path, base)
|
||||
if os.path.isdir(cur):
|
||||
dirs.append(base)
|
||||
else:
|
||||
files.append(base)
|
||||
|
||||
# Sort lists and yield the current level.
|
||||
dirs.sort()
|
||||
files.sort()
|
||||
yield (path, dirs, files)
|
||||
|
||||
# Recurse into directories.
|
||||
for base in dirs:
|
||||
cur = os.path.join(path, base)
|
||||
# yield from _sorted_walk(cur)
|
||||
for res in _sorted_walk(cur):
|
||||
yield res
|
||||
|
||||
def albums_in_dir(path):
|
||||
"""Recursively searches the given directory and returns an iterable
|
||||
of lists of items where each list is probably an album.
|
||||
Specifically, any folder containing any media files is an album.
|
||||
"""
|
||||
path = library._unicode_path(path)
|
||||
for root, dirs, files in os.walk(path):
|
||||
for root, dirs, files in _sorted_walk(path):
|
||||
# Get a list of items in the directory.
|
||||
items = []
|
||||
for filename in files:
|
||||
|
|
|
|||
Loading…
Reference in a new issue