-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to check for existence of a metadata plugin tag in item_fields section of the inline plugin ? #2406
Comments
The inline plugin sets all the values as Python local variables. So you can use any technique to check whether a given variable name exists in scope, like so: http://stackoverflow.com/questions/843277/how-do-i-check-if-a-variable-exists |
well I tried 3 things, none behave like the ifdef
should the variable be de-registered somewhat or is it something I should take care of in my custom item_fields ?
format_item: $my_format %ifdef{tonal,$tonal,'no'} $my_acousticbrainz $my_abz_local $my_abz_global
item_fields:
my_acousticbrainz: |
try:
return u'--{}--'.format(tonal)
except NameError:
return u'exception'
my_abz_local: |
if 'tonal' in locals():
return u'--{}--'.format(tonal)
else:
return u'locals?'
my_abz_global: |
if 'tonal' in globals():
return u'--{}--'.format(tonal)
else:
return u'globals?'
my_format: u'{:02d}/{:02d}--{:-<20.20}--{:-<10.10}--{:-<20.20}--{:-<10.10}\n-------{:3.0f} bpm--'.format(track, tracktotal, album, albumartist, title, genre, bpm) |
Sorry, I don't understand from that output what's going on here. Maybe you can cook up instructions to reproduce the problem from scratch locally? |
I'm aware of the Given that, the following format item displays the tonal with the ifdef and each of the 3 subsequent custom formats I wrote ($my_acousticbrainz $my_abz_local $my_abz_global) is an attempt to "replicate" ifdef using python code in the spirit of your comment
The correct custom format output should be "equal" to the ifdef output format_item: $track/$tracktotal $album - $albumartist %ifdef{tonal,$tonal,'no'} $my_acousticbrainz $my_abz_local $my_abz_global
item_fields:
my_acousticbrainz: |
try:
tonal
except NameError:
return u'exception'
else:
return u'--{}--'.format(tonal)
my_abz_local: |
if 'tonal' in locals():
return u'--{}--'.format(tonal)
else:
return u'no locals'
my_abz_global: |
if 'tonal' in globals():
return u'--{}--'.format(tonal)
else:
return u'no globals' Now I have 2 Ennio Morricone albums, one has the tonal infos for its tracks, the other has none. The output is the following
Looking at that output :
the Is it an expected behaviour ? |
As detailed here: #2406 (comment) In a *function-style* definition, we didn't properly *un-define* the values for a given item after each function invocation. So when a field wasn't defined, it would get the value for the previously-formatted object instead. It now properly throws a NameError.
Problem
I want to use acousticbrains tags, tonal in particular, in a custom format with the inline plugin, but I fail at checking if the tag exists.
So when the tonal field exists it's ok:
now issue is when it doesn't
I'm aware of the
%ifdef{$tonal,$tonal,'no'}
that works well in my config snippet below if I put it straight into theformat_item
(the commentedformat_item
line below)Now I'd wish to test for that existence in the
item_fields:
section of the inline plugin to format it to my needs, this is where I fail, any idea if that's possible ?Setup
My configuration (output of
beet config
) is:The text was updated successfully, but these errors were encountered: