beets: On Windows under Python 3, Colorama's ANSI color replacement doesn't work in cmd.exe
Problem
When running beets in a Windows 10 command-line terminal (cmd.exe) the output is wrong. It seems like there’s a character encoding error. This is what it looks like (look at the last line where beets prompts for Skipping, Replace, etc) : https://imgur.com/a/b9K9x
E:\Music\_trier>beet -vv
user configuration: C:\Users\Arnaud\AppData\Roaming\beets\config.yaml
data directory: C:\Users\Arnaud\AppData\Roaming\beets
plugin paths:
Sending event: pluginload
inline: adding item field initial
inline: adding item field disc_and_track
library database: C:\Users\Arnaud\AppData\Roaming\beets\library.db
library directory: E:\Music
Sending event: library_opened
Usage:
beet COMMAND [ARGS...]
beet help COMMAND
Options:
--format-item=FORMAT_ITEM
print with custom format
--format-album=FORMAT_ALBUM
print with custom format
-l LIBRARY, --library=LIBRARY
library database file to use
-d DIRECTORY, --directory=DIRECTORY
destination music directory
-v, --verbose log more details (use twice for even more)
-c CONFIG, --config=CONFIG
path to configuration file
-h, --help show this help message and exit
Commands:
acousticbrainz fetch metadata from AcousticBrainz
clearart remove images from file metadata
config show or edit the user configuration
embedart embed image files into file metadata
extractart extract an image from file metadata
fetchart download album art
fields show fields available for queries and format strings
fingerprint generate fingerprints for items without them
ftintitle move featured artists to the title field
help (?) give detailed help on a specific sub-command
import (imp, im) import new music
lastgenre fetch genres
list (ls) query the library
modify (mod) change metadata fields
move (mv) move or copy items
remove (rm) remove matching items from the library
replaygain analyze for ReplayGain
stats show statistics about the library or a query
submit submit Acoustid fingerprints
update (upd, up) update the library
version output version information
write write tag information to files
Sending event: cli_exit
Setup
- OS: Windows 10 Professional
- Python version: 3.6.1
- beets version: 1.4.5
- Turning off plugins made problem go away (yes/no): no
My configuration (output of beet config
) is:
E:\Music\_trier>beet config
directory: E:\Music
plugins: inline acousticbrainz chroma embedart fetchart lastgenre replaygain ftintitle
threaded: yes
autotag: yes
art_filename: cover
asciify_paths: yes
clutter:
- .jpg
- .jpeg
- .png
- .sfv
- .nfo
- .m3u
- .m3u8
- Thumbs.DB
- .DS_Store
original_date: yes
format_item: $artist - $album - $title ($genre)
match:
strong_rec_thresh: 0.04
preferred:
countries: [US, GB|UK, FR]
media: [CD, Digital Media|File]
original_year: yes
item_fields:
initial: albumartist[0].upper() + u'.'
disc_and_track: u'%02i-%02i' % (disc, track) if disctotal > 1 else u'%02i' % (track)
paths:
albumtype:soundtrack: ost/$album/$disc_and_track. $title
savedir:arthur: _arthur/$album/$disc_and_track. $title
savedir:radionova: nova/$album/$disc_and_track. $artist - $title
savedir:world: world/$albumartist/$year - $album/$disc_and_track. $title
savedir:electro: electro/$albumartist/$year - $album/$disc_and_track. $title
savedir:classical: classical/$artist/$album/$disc_and_track. $title
savedir:alt_rock: alt_rock/$albumartist/$year - $album/$disc_and_track. $title
savedir:rock: rock/$albumartist/$year - $album/$disc_and_track. $title
savedir:jazz: jazz/$albumartist/$year - $album/$disc_and_track. $title
savedir:blues: blues/$albumartist/$year - $album/$disc_and_track. $title
savedir:metal: metal/$albumartist/$year - $album/$disc_and_track. $title
savedir:rap: rap/$albumartist/$year - $album/$disc_and_track. $title
savedir:pop: pop/$albumartist/$year - $album/$disc_and_track. $title
savedir:techno: techno/$albumartist/$year - $album/$disc_and_track. $title
default: _trier/$albumartist/$year - $album/$disc_and_track. $title
comp: $genre/$album/$track. $title
ui:
color: yes
colors:
text_success: green
text_warning: yellow
text_error: red
text_highlight: red
text_highlight_minor: lightgray
action_default: turquoise
action: blue
import:
write: yes
copy: yes
move: yes
resume: ask
ftintitle:
auto: yes
drop: no
format: feat. {0}
acousticbrainz:
auto: yes
force: no
chroma:
auto: no
acoustid:
apikey: REDACTED
embedart:
auto: yes
ifempty: yes
maxwidth: 0
compare_threshold: 0
remove_art_file: no
fetchart:
auto: yes
cover_names: cover front art album folder
sources: filesystem coverart itunes amazon albumart fanarttv
minwidth: 0
maxwidth: 0
enforce_ratio: no
cautious: no
google_key: REDACTED
google_engine: 001442825323518660753:hrh5ch1gjzm
fanarttv_key: REDACTED
store_source: no
lastgenre:
auto: yes
whitelist: yes
min_weight: 10
count: 1
fallback:
canonical: no
source: album
force: yes
separator: ', '
prefer_specific: no
lastfm:
user: redacted
replaygain:
backend: bs1770gain
auto: yes
overwrite: no
targetlevel: 89
r128: [Opus]
chunk_at: 5000
method: replaygain
copyartifacts:
extensions: .cue .log
print_ignored: yes
pathfields: {}
album_fields: {}
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 4
- Comments: 30 (14 by maintainers)
I resolved this issue by enabling ANSI Terminal Control in the registry. I used Glenn Slayden solution. https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling
You can fix this issue in cmd.exe using ANSICON. Still doesn’t fix the issue in powershell though.
http://softkube.com/blog/ansi-command-line-colors-under-windows
The problem seems to be in the
print_
function that is beeing used to avoid exceptions by the defaultprint
function.On windows we rely on colorama to convert ANSI color codes to win32 calls during encoding. Encoding the string directly seems to bypass that and break colorized output.
simply writing the text to stdout or even just passing it to the default print function would fix colors on windows however that would also throw encoding errors and break the encoding overwrite described in that function.