Fix import of multidisc releases with subdirectories
Don't stop collapsing paths when iterating over subdirectories of
already collapsed paths.
Fixes
@@ -1469,6 +1469,16 @@ MULTIDISC_MARKERS = (br'dis[ck]', br'cd')
MULTIDISC_PAT_FMT = br'^(.*%s[\W_]*)\d'
+def is_subdir_of_any_in_list(path, dirs):
+ """Returns True if path os a subdirectory of any directory in dirs
+ (a list). In other case, returns False.
+ """
+ for d in dirs:
+ if path.startswith(d + b'/'):
+ return True
+ return False
+
+
def albums_in_dir(path):
"""Recursively searches the given directory and returns an iterable
of (paths, items) where paths is a list of directories and items is
@@ -1490,7 +1500,8 @@ def albums_in_dir(path):
if collapse_paths:
if (not collapse_pat and collapse_paths[0] in ancestry(root)) or \
(collapse_pat and
- collapse_pat.match(os.path.basename(root))):
+ collapse_pat.match(os.path.basename(root))) or \
+ is_subdir_of_any_in_list(root, collapse_paths):
# Still collapsing.
collapse_paths.append(root)
collapse_items += items
