From a89c7f8529ca6bf66b09c34f7ff669259987bb7b Mon Sep 17 00:00:00 2001 From: Adam Jakab Date: Sat, 14 Mar 2020 19:13:06 +0100 Subject: [PATCH 1/3] upgraded item selection query --- BEETSDIR/config.yaml | 2 +- beetsplug/xtractor/command.py | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/BEETSDIR/config.yaml b/BEETSDIR/config.yaml index dbf8d7d..17abb1e 100644 --- a/BEETSDIR/config.yaml +++ b/BEETSDIR/config.yaml @@ -27,7 +27,7 @@ xtractor: threads: 1 force: no quiet: no - items_per_run: 0 + items_per_run: 1 keep_output: yes keep_profiles: no output_path: /Users/jackisback/Documents/Projects/Python/BeetsPluginXtractor/BEETSDIR/xtraction diff --git a/beetsplug/xtractor/command.py b/beetsplug/xtractor/command.py index c9dc8b0..fac95b4 100644 --- a/beetsplug/xtractor/command.py +++ b/beetsplug/xtractor/command.py @@ -13,7 +13,8 @@ from subprocess import Popen, PIPE import yaml -from beets.library import Library as BeatsLibrary, Item +from beets import dbcore +from beets.library import Library, Item, parse_query_string from beets.ui import Subcommand, decargs from confuse import Subview @@ -111,7 +112,7 @@ def __init__(self, config): aliases=[__PLUGIN_SHORT_NAME__] ) - def func(self, lib: BeatsLibrary, options, arguments): + def func(self, lib: Library, options, arguments): self.cfg_dry_run = options.dryrun self.cfg_write = options.write self.cfg_threads = options.threads @@ -134,18 +135,26 @@ def show_version_information(self): "Xtractor(beets-xtractor) plugin for Beets: v{0}".format(__version__)) def xtract(self): - # Setup the query - query = " ".join(self.query) + # Parse the incoming query + parsed_query, parsed_sort = parse_query_string(" ".join(self.query), Item) + combined_query = parsed_query - # Append one low OR one high level attribute that should be there after xtraction + # Add unprocessed items query = "bpm:0 , gender::^$" if not self.cfg_force: - query = "bpm:0 , gender::^$" + # Set up the query for unprocessed items + unprocessed_items_query = dbcore.query.OrQuery( + [ + dbcore.query.NumericQuery(u'bpm', u'0'), + dbcore.query.MatchQuery(u'gender', u'', fast=False), + dbcore.query.MatchQuery(u'gender', None, fast=False), + ] + ) + combined_query = dbcore.query.AndQuery([parsed_query, unprocessed_items_query]) # Get the library items - library_items = self.lib.items(query) - + library_items = self.lib.items(combined_query, parsed_sort) if len(library_items) == 0: - self._say("No items were found with the specified query: '{}'".format(query)) + self._say("No items to process") return # Limit the number of items per run (0 means no limit) From 21ff6b02355ae10d086f701c176bc9e82a45eb9d Mon Sep 17 00:00:00 2001 From: Adam Jakab Date: Sat, 14 Mar 2020 19:45:26 +0100 Subject: [PATCH 2/3] added count command line option --- BEETSDIR/config.yaml | 12 ++++++------ beetsplug/xtractor/command.py | 36 +++++++++++++++++++++-------------- beetsplug/xtractor/version.py | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/BEETSDIR/config.yaml b/BEETSDIR/config.yaml index 17abb1e..e5302bf 100644 --- a/BEETSDIR/config.yaml +++ b/BEETSDIR/config.yaml @@ -27,18 +27,18 @@ xtractor: threads: 1 force: no quiet: no - items_per_run: 1 - keep_output: yes + items_per_run: 0 + keep_output: no keep_profiles: no output_path: /Users/jackisback/Documents/Projects/Python/BeetsPluginXtractor/BEETSDIR/xtraction low_level_extractor: /Users/jackisback/Documents/Projects/Other/extractors/beta5/essentia_streaming_extractor_music high_level_extractor: /Users/jackisback/Documents/Projects/Other/extractors/beta5/essentia_streaming_extractor_music_svm low_level_profile: - outputFormat: yaml - outputFrames: 0 + outputFormat: yaml + outputFrames: 0 high_level_profile: - outputFormat: json - highlevel: + outputFormat: json + highlevel: compute: 1 svm_models: - /Users/jackisback/Documents/Projects/Other/extractors/svm_models_beta5/danceability.history diff --git a/beetsplug/xtractor/command.py b/beetsplug/xtractor/command.py index fac95b4..125afd2 100644 --- a/beetsplug/xtractor/command.py +++ b/beetsplug/xtractor/command.py @@ -54,6 +54,7 @@ def __init__(self, config): self.cfg_threads = cfg.get("threads") self.cfg_force = cfg.get("force") self.cfg_version = False + self.cfg_count_only = False self.cfg_quiet = cfg.get("quiet") self.cfg_items_per_run = cfg.get("items_per_run") @@ -62,16 +63,14 @@ def __init__(self, config): self.parser.add_option( '-d', '--dry-run', action='store_true', dest='dryrun', default=self.cfg_dry_run, - help=u'[default: {}] display the bpm values but do not update the ' - u'library items'.format( + help=u'[default: {}] display the bpm values but do not update the library items'.format( self.cfg_dry_run) ) self.parser.add_option( '-w', '--write', action='store_true', dest='write', default=self.cfg_write, - help=u'[default: {}] write the bpm values to the media ' - u'files'.format( + help=u'[default: {}] write the bpm values to the media files'.format( self.cfg_write) ) @@ -79,17 +78,20 @@ def __init__(self, config): '-t', '--threads', action='store', dest='threads', type='int', default=self.cfg_threads, - help=u'[default: {}] the number of threads to run in ' - u'parallel'.format( + help=u'[default: {}] the number of threads to run in parallel'.format( self.cfg_threads) ) self.parser.add_option( '-f', '--force', action='store_true', dest='force', default=self.cfg_force, - help=u'[default: {}] force analysis of items with non-zero bpm ' - u'values'.format( - self.cfg_force) + help=u'[default: {}] force analysis of items with non-zero bpm values'.format(self.cfg_force) + ) + + self.parser.add_option( + '-c', '--count-only', + action='store_true', dest='count_only', default=self.cfg_count_only, + help=u'[default: {}] Show the number of items to be processed'.format(self.cfg_count_only) ) self.parser.add_option( @@ -118,6 +120,7 @@ def func(self, lib: Library, options, arguments): self.cfg_threads = options.threads self.cfg_force = options.force self.cfg_version = options.version + self.cfg_count_only = options.count_only self.cfg_quiet = options.quiet self.lib = lib @@ -129,11 +132,6 @@ def func(self, lib: Library, options, arguments): self.xtract() - def show_version_information(self): - from beetsplug.xtractor.version import __version__ - self._say( - "Xtractor(beets-xtractor) plugin for Beets: v{0}".format(__version__)) - def xtract(self): # Parse the incoming query parsed_query, parsed_sort = parse_query_string(" ".join(self.query), Item) @@ -157,6 +155,11 @@ def xtract(self): self._say("No items to process") return + # Count only and exit + if self.cfg_count_only: + self._say("Number of items to be processed: {}".format(len(library_items))) + return + # Limit the number of items per run (0 means no limit) items = [] for item in library_items: @@ -364,6 +367,11 @@ def _get_extractor_path(self, level): return extractor_path + def show_version_information(self): + from beetsplug.xtractor.version import __version__ + self._say( + "Xtractor(beets-{0}) plugin for Beets: v{1}".format(__PLUGIN_NAME__, __version__)) + def _say(self, msg): if not self.cfg_quiet: log.info(msg) diff --git a/beetsplug/xtractor/version.py b/beetsplug/xtractor/version.py index 188ab3f..6e3531e 100644 --- a/beetsplug/xtractor/version.py +++ b/beetsplug/xtractor/version.py @@ -4,4 +4,4 @@ # Created: 3/13/20, 12:17 AM # License: See LICENSE.txt -__version__ = '0.1.1' +__version__ = '0.1.2' From 1d3c0f756199bf8e3b9478b70b7bd330648de6af Mon Sep 17 00:00:00 2001 From: Adam Jakab Date: Sat, 14 Mar 2020 19:50:54 +0100 Subject: [PATCH 3/3] gitignore fix --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 519ce25..56d1b61 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,9 @@ dmypy.json .idea_modules/ .idea/replstate.xml -/.idea/terminal.xml +.idea/terminal.xml +.idea/dataSources.xml + +# OS +.DS_Store +