From b05432aed03bd7d9a0d3f949efca479ff2896604 Mon Sep 17 00:00:00 2001 From: Jay DesLauriers Date: Sun, 3 Oct 2021 00:51:06 +0000 Subject: [PATCH] feat(unimported): support excluding subdirectories --- beetsplug/unimported.py | 22 ++++++++++++++++------ docs/changelog.rst | 2 ++ docs/plugins/unimported.rst | 7 ++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py index 6c8cb6897..7714ec833 100644 --- a/beetsplug/unimported.py +++ b/beetsplug/unimported.py @@ -38,13 +38,23 @@ class Unimported(BeetsPlugin): def commands(self): def print_unimported(lib, opts, args): - ignore_exts = [('.' + x).encode() for x - in self.config['ignore_extensions'].as_str_seq()] + ignore_exts = [ + ('.' + x).encode() + for x in self.config["ignore_extensions"].as_str_seq() + ] + ignore_dirs = [ + os.path.join(lib.directory, x.encode()) + for x in self.config["ignore_subdirectories"].as_str_seq() + ] in_folder = { - os.path.join(r, file) for r, d, f in os.walk(lib.directory) - for file in f if not any( - [file.endswith(extension) for extension in - ignore_exts])} + os.path.join(r, file) + for r, d, f in os.walk(lib.directory) + for file in f + if not any( + [file.endswith(ext) for ext in ignore_exts] + + [r in ignore_dirs] + ) + } in_library = {x.path for x in lib.items()} art_files = {x.artpath for x in lib.albums()} for f in in_folder - in_library - art_files: diff --git a/docs/changelog.rst b/docs/changelog.rst index 8bad04728..f6a927349 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,6 +33,8 @@ Major new features: Other new things: * Permissions plugin now sets cover art permissions to the file permissions. +* :doc:`/plugins/unimported`: Support excluding specific + subdirectories in library. Bug fixes: diff --git a/docs/plugins/unimported.rst b/docs/plugins/unimported.rst index 447c4ec8c..80ee8004b 100644 --- a/docs/plugins/unimported.rst +++ b/docs/plugins/unimported.rst @@ -1,7 +1,7 @@ Unimported Plugin ================= -The ``unimported`` plugin allows to list all files in the library folder which are not listed in the beets library database, including art files. +The ``unimported`` plugin allows one to list all files in the library folder which are not listed in the beets library database, including art files. Command Line Usage ------------------ @@ -9,9 +9,10 @@ Command Line Usage To use the ``unimported`` plugin, enable it in your configuration (see :ref:`using-plugins`). Then use it by invoking the ``beet unimported`` command. The command will list all files in the library folder which are not imported. You can -exclude file extensions using the configuration file:: +exclude file extensions or entire subdirectories using the configuration file:: unimported: ignore_extensions: jpg png + ignore_subdirectories: NonMusic data temp -The default configuration list all unimported files, ignoring no extensions. \ No newline at end of file +The default configuration lists all unimported files, ignoring no extensions.