Skip to content

Commit

Permalink
Merge pull request #2 from adamjakab/devel
Browse files Browse the repository at this point in the history
Better item selection query and count option
  • Loading branch information
adamjakab committed Mar 14, 2020
2 parents 9cca5b5 + 1d3c0f7 commit 061a86e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -160,4 +160,9 @@ dmypy.json

.idea_modules/
.idea/replstate.xml
/.idea/terminal.xml
.idea/terminal.xml
.idea/dataSources.xml

# OS
.DS_Store

10 changes: 5 additions & 5 deletions BEETSDIR/config.yaml
Expand Up @@ -28,17 +28,17 @@ xtractor:
force: no
quiet: no
items_per_run: 0
keep_output: yes
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
Expand Down
63 changes: 40 additions & 23 deletions beetsplug/xtractor/command.py
Expand Up @@ -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

Expand Down Expand Up @@ -53,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")

Expand All @@ -61,34 +63,35 @@ 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)
)

self.parser.add_option(
'-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(
Expand All @@ -111,12 +114,13 @@ 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
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
Expand All @@ -128,24 +132,32 @@ def func(self, lib: BeatsLibrary, 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):
# 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

# 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)
Expand Down Expand Up @@ -355,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)
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/xtractor/version.py
Expand Up @@ -4,4 +4,4 @@
# Created: 3/13/20, 12:17 AM
# License: See LICENSE.txt

__version__ = '0.1.1'
__version__ = '0.1.2'

0 comments on commit 061a86e

Please sign in to comment.