From b6588edac5c5f67d535f4b2f770c0882f6a03505 Mon Sep 17 00:00:00 2001 From: MrNuggelz Date: Tue, 15 Oct 2019 12:04:04 +0200 Subject: [PATCH 1/6] unimported files plugin --- beetsplug/unimported.py | 36 ++++++++++++++++++++++++++++++++++++ docs/changelog.rst | 1 + docs/plugins/index.rst | 1 + docs/plugins/unimported.rst | 18 ++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 beetsplug/unimported.py create mode 100644 docs/plugins/unimported.rst diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py new file mode 100644 index 000000000..5a9f4d82b --- /dev/null +++ b/beetsplug/unimported.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +import os + +from beets.plugins import BeetsPlugin +from beets.ui import Subcommand + + +class Unimported(BeetsPlugin): + + def __init__(self): + super(Unimported, self).__init__() + self.config.add( + { + 'ignore_extensions': '[]' + } + ) + + def commands(self): + def print_unimported(lib, opts, args): + in_library = set( + (os.path.join(r, file) for r, d, f in os.walk(lib.directory) + for file in f if not any( + [file.endswith(extension.encode()) for extension in + self.config['ignore_extensions'].get()]))) + test = set((x.path for x in lib.items())) + for f in in_library - test: + print(f.decode('utf-8')) + + unimported = Subcommand( + 'unimported', + help='list files in library which have not been imported') + unimported.func = print_unimported + return [unimported] diff --git a/docs/changelog.rst b/docs/changelog.rst index 963863ae8..122e88499 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,7 @@ Changelog New features: +* :doc:`/plugins/unimported`: Added `unimported` plugin. * We now fetch information about `works`_ from MusicBrainz. MusicBrainz matches provide the fields ``work`` (the title), ``mb_workid`` (the MBID), and ``work_disambig`` (the disambiguation string). diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 56864b2e0..066d6ec22 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -119,6 +119,7 @@ following to your configuration:: the thumbnails types + unimported web zero diff --git a/docs/plugins/unimported.rst b/docs/plugins/unimported.rst new file mode 100644 index 000000000..908636a30 --- /dev/null +++ b/docs/plugins/unimported.rst @@ -0,0 +1,18 @@ +Play Plugin +=========== + +The ``unimported`` plugin allows to list all files in the library folder which are not imported. + +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:: + + unimported: + ignore_extensions: [jpg,png] # default [] + + + From c7e81d8b81ff41a1ebb9907ca22066c0be59b9c5 Mon Sep 17 00:00:00 2001 From: MrNuggelz Date: Tue, 15 Oct 2019 15:32:50 +0200 Subject: [PATCH 2/6] improvements from review --- beetsplug/unimported.py | 21 +++++++++++---------- docs/plugins/unimported.rst | 10 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py index 5a9f4d82b..c31ab5702 100644 --- a/beetsplug/unimported.py +++ b/beetsplug/unimported.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function +from __future__ import absolute_import, division, print_function import os +from beets import util from beets.plugins import BeetsPlugin from beets.ui import Subcommand @@ -14,23 +13,25 @@ class Unimported(BeetsPlugin): super(Unimported, self).__init__() self.config.add( { - 'ignore_extensions': '[]' + 'ignore_extensions': [] } ) def commands(self): def print_unimported(lib, opts, args): - in_library = set( + exts_to_ignore = self.config['ignore_extensions'].as_str_seq() + in_folder = set( (os.path.join(r, file) for r, d, f in os.walk(lib.directory) for file in f if not any( [file.endswith(extension.encode()) for extension in - self.config['ignore_extensions'].get()]))) - test = set((x.path for x in lib.items())) - for f in in_library - test: - print(f.decode('utf-8')) + exts_to_ignore]))) + in_library = set(x.path for x in lib.items()) + for f in in_folder - in_library: + print(util.displayable_path(f)) unimported = Subcommand( 'unimported', - help='list files in library which have not been imported') + help='list all files in the library folder which are not listed' + ' in the beets library database') unimported.func = print_unimported return [unimported] diff --git a/docs/plugins/unimported.rst b/docs/plugins/unimported.rst index 908636a30..6fe23eb16 100644 --- a/docs/plugins/unimported.rst +++ b/docs/plugins/unimported.rst @@ -1,7 +1,7 @@ -Play Plugin +Unimported Plugin =========== -The ``unimported`` plugin allows to list all files in the library folder which are not imported. +The ``unimported`` plugin allows to list all files in the library folder which are not listed in the beets library database. Command Line Usage ------------------ @@ -12,7 +12,7 @@ The command will list all files in the library folder which are not imported. Yo exclude file extensions using the configuration file:: unimported: - ignore_extensions: [jpg,png] # default [] - - + ignore_extensions: jpg png +The default configuration moves all English articles to the end of the string, +but you can override these defaults to make more complex changes. \ No newline at end of file From 712b4b8bdf4dcf38c23a696209f179cf76037ac0 Mon Sep 17 00:00:00 2001 From: MrNuggelz Date: Tue, 15 Oct 2019 15:49:44 +0200 Subject: [PATCH 3/6] corrected to short underline in documentation --- docs/plugins/unimported.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/unimported.rst b/docs/plugins/unimported.rst index 6fe23eb16..2f26ecb67 100644 --- a/docs/plugins/unimported.rst +++ b/docs/plugins/unimported.rst @@ -1,5 +1,5 @@ Unimported Plugin -=========== +================= The ``unimported`` plugin allows to list all files in the library folder which are not listed in the beets library database. From 6be6ded02202e1163baea0e74b0d1701f9764455 Mon Sep 17 00:00:00 2001 From: MrNuggelz Date: Tue, 15 Oct 2019 16:03:12 +0200 Subject: [PATCH 4/6] don't list album art paths as unimported --- beetsplug/unimported.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py index c31ab5702..584e41b5c 100644 --- a/beetsplug/unimported.py +++ b/beetsplug/unimported.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function import os -from beets import util +from beets import util, config from beets.plugins import BeetsPlugin from beets.ui import Subcommand @@ -26,7 +26,8 @@ class Unimported(BeetsPlugin): [file.endswith(extension.encode()) for extension in exts_to_ignore]))) in_library = set(x.path for x in lib.items()) - for f in in_folder - in_library: + art_files = set(x.artpath for x in lib.albums()) + for f in in_folder - in_library - art_files: print(util.displayable_path(f)) unimported = Subcommand( From 3d15eaff2e0261d8446ff85450bb4f74487723a5 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 15 Oct 2019 16:35:21 +0200 Subject: [PATCH 5/6] Removed unused import --- beetsplug/unimported.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py index 584e41b5c..e9b7d0186 100644 --- a/beetsplug/unimported.py +++ b/beetsplug/unimported.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function import os -from beets import util, config +from beets import util from beets.plugins import BeetsPlugin from beets.ui import Subcommand From d11e14b1a08cdfadc1eb2a4249ac0a93cd03efec Mon Sep 17 00:00:00 2001 From: MrNuggelz Date: Tue, 15 Oct 2019 21:54:35 +0200 Subject: [PATCH 6/6] improvements from review #2 --- beetsplug/unimported.py | 32 +++++++++++++++++++++++++++----- docs/changelog.rst | 2 +- docs/plugins/unimported.rst | 5 ++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/beetsplug/unimported.py b/beetsplug/unimported.py index e9b7d0186..544e9de46 100644 --- a/beetsplug/unimported.py +++ b/beetsplug/unimported.py @@ -1,10 +1,31 @@ # -*- coding: utf-8 -*- +# This file is part of beets. +# Copyright 2019, Joris Jensen +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +""" +List all files in the library folder which are not listed in the + beets library database, including art files +""" + from __future__ import absolute_import, division, print_function import os from beets import util from beets.plugins import BeetsPlugin -from beets.ui import Subcommand +from beets.ui import Subcommand, print_ + +__author__ = 'https://github.com/MrNuggelz' class Unimported(BeetsPlugin): @@ -19,16 +40,17 @@ class Unimported(BeetsPlugin): def commands(self): def print_unimported(lib, opts, args): - exts_to_ignore = self.config['ignore_extensions'].as_str_seq() + ignore_exts = [('.' + x).encode() for x + in self.config['ignore_extensions'].as_str_seq()] in_folder = set( (os.path.join(r, file) for r, d, f in os.walk(lib.directory) for file in f if not any( - [file.endswith(extension.encode()) for extension in - exts_to_ignore]))) + [file.endswith(extension) for extension in + ignore_exts]))) in_library = set(x.path for x in lib.items()) art_files = set(x.artpath for x in lib.albums()) for f in in_folder - in_library - art_files: - print(util.displayable_path(f)) + print_(util.displayable_path(f)) unimported = Subcommand( 'unimported', diff --git a/docs/changelog.rst b/docs/changelog.rst index 122e88499..29ad9b6eb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,7 +6,7 @@ Changelog New features: -* :doc:`/plugins/unimported`: Added `unimported` plugin. +* :doc:`/plugins/unimported`: lets you find untracked files in your library directory. * We now fetch information about `works`_ from MusicBrainz. MusicBrainz matches provide the fields ``work`` (the title), ``mb_workid`` (the MBID), and ``work_disambig`` (the disambiguation string). diff --git a/docs/plugins/unimported.rst b/docs/plugins/unimported.rst index 2f26ecb67..447c4ec8c 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. +The ``unimported`` plugin allows to list all files in the library folder which are not listed in the beets library database, including art files. Command Line Usage ------------------ @@ -14,5 +14,4 @@ exclude file extensions using the configuration file:: unimported: ignore_extensions: jpg png -The default configuration moves all English articles to the end of the string, -but you can override these defaults to make more complex changes. \ No newline at end of file +The default configuration list all unimported files, ignoring no extensions. \ No newline at end of file