diff --git a/beetsplug/xtractor/command.py b/beetsplug/xtractor/command.py index 0594375..c49dca2 100644 --- a/beetsplug/xtractor/command.py +++ b/beetsplug/xtractor/command.py @@ -3,6 +3,7 @@ # Author: Adam Jakab # Created: 3/13/20, 12:17 AM # License: See LICENSE.txt + import hashlib import json import logging @@ -14,12 +15,11 @@ import yaml from beets import dbcore -from beets.dbcore import types from beets.library import Library, Item, parse_query_string from beets.ui import Subcommand, decargs from confuse import Subview -from beetsplug.xtractor import helper as bpmHelper +from beetsplug.xtractor import helper # Module methods log = logging.getLogger('beets.xtractor') @@ -225,7 +225,7 @@ def _run_analysis_high_level(self, item): try: target_map = self.config["high_level_targets"] - audiodata = bpmHelper.extract_from_output(output_path, target_map) + audiodata = helper.extract_from_output(output_path, target_map) log.debug("Audiodata(High): {}".format(audiodata)) except FileNotFoundError as e: self._say("File not found: {0}".format(e)) @@ -258,7 +258,7 @@ def _run_analysis_low_level(self, item): try: target_map = self.config["low_level_targets"] - audiodata = bpmHelper.extract_from_output(output_path, target_map) + audiodata = helper.extract_from_output(output_path, target_map) log.debug("Audiodata(Low): {}".format(audiodata)) except FileNotFoundError as e: self._say("File not found: {0}".format(e)) @@ -287,6 +287,9 @@ def _run_essentia_extractor(self, extractor_path, input_path, output_path, profi log.debug("Process stdout: {0}".format(stdout.decode())) log.debug("Process stderr: {0}".format(stderr.decode())) + # Make sure file is encoded correctly (sometimes media files have funky tags) + helper.asciify_file_content(output_path) + def _execute_on_each_items(self, items, func): total = len(items) finished = 0 diff --git a/beetsplug/xtractor/helper.py b/beetsplug/xtractor/helper.py index 12f883a..8d0d87d 100644 --- a/beetsplug/xtractor/helper.py +++ b/beetsplug/xtractor/helper.py @@ -7,38 +7,7 @@ import json import os -from confuse import Subview - -_module_path = os.path.dirname(__file__) - -"""Checklist from Acousticbrainz plugin: -ITEM -bpm OK -initial_key X ??? - -ATTRIBUTE: -average_loudness OK -beets_count OK (extra) -chords_changes_rate X -chords_key X -chords_number_rate X -chords_scale X -danceable OK -danceability OK (extra) -gender OK (!!!) -genre_rosamerica OK -key_strength X -mood_acoustic OK -mood_aggressive OK -mood_electronic OK -mood_happy OK -mood_party OK -mood_relaxed OK -mood_sad OK -rhythm X -tonal X -voice_instrumental OK -""" +from beets.util.confit import Subview def extract_from_output(output_path, target_map: Subview): @@ -81,3 +50,14 @@ def extract_value_from_audiodata(audiodata, target_map_item: Subview): value = audiodata return value + + +def asciify_file_content(file_path): + if os.path.isfile(file_path): + with open(file_path, 'r', encoding="utf-8") as content_file: + content_orig = content_file.read() + + content_enc = content_orig.encode('ascii', 'ignore').decode('ascii') + if content_orig != content_enc: + with open(file_path, 'w', encoding="ascii") as content_file: + content_file.write(content_enc) diff --git a/beetsplug/xtractor/version.py b/beetsplug/xtractor/version.py index ae88e4f..e8bb6d4 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.2.1' +__version__ = '0.2.2'