Add plugin for formatting albumtypes - #4048
Conversation
sampsyo
left a comment
There was a problem hiding this comment.
Wow; nice work! This looks awesome so far. I have a few suggestions for the code and some documentation improvements for your consideration.
| super(AlbumTypesPlugin, self).__init__() | ||
| self.album_template_fields['atypes'] = self._atypes | ||
|
|
||
| def _atypes(self, item: Album): |
There was a problem hiding this comment.
Perhaps add a docstring, like "generate a formatted string for an album's types"?
| self.config.add({ | ||
| 'types': [], | ||
| 'ignore_va': [], | ||
| 'brackets': '[]' | ||
| }) |
There was a problem hiding this comment.
This stuff should go in __init__; otherwise, it will try to set the defaults every time we use the $atypes field.
There was a problem hiding this comment.
Good point!
Would it not be better to extract the config values (next lines after this) in __init__() as well, so it's not done every time _atypesis called? I see both approaches in other plugins, so I suppose it's not a big concern, but converting config to those structs isn't exactly free.
There was a problem hiding this comment.
That is less of a big deal, IMO, and it's fine to do it either way. The reason is that config.add(...) actually modifies config: it inserts a new "layer" with the default configuration values. So doing this every time actually adds multiple copies of that data. In contrast, get and as_* calls are read-only, so it doesn't matter as much where they appear.
| is_va = item.mb_albumartistid == VARIOUS_ARTISTS_ID | ||
| for type in types: | ||
| if type[0] in albumtypes and type[1]: | ||
| if not is_va or (not type[0] in ignore_va and is_va): |
There was a problem hiding this comment.
not type[0] in ignore_va is probably more clearly written type[0] not in ignore_va.
| for type in types: | ||
| if type[0] in albumtypes and type[1]: | ||
| if not is_va or (not type[0] in ignore_va and is_va): | ||
| res += bracket_l + type[1] + bracket_r |
There was a problem hiding this comment.
This might be a little easier to read as a PEP 498 format/template string? Like: f'{bracket_l}{type[1]}{bracket_r}'
| such as "Album", "EP", "Single", etc. List of available type can be found | ||
| `here`_. |
There was a problem hiding this comment.
Maybe for this last link, I'd word it as: "For the list of available album types, see the MusicBrainz documentation." (with the last two words linked)
| (see :ref:`using-plugins`). Then, add ``$atypes`` to your path formats as | ||
| desired. |
There was a problem hiding this comment.
"The plugin defines a new field $atypes, which you can use in your path formats or elsewhere."
| - **types**: An ordered list of album type to format mappings. The order of the | ||
| mappings determines their order in the output. If a mapping is missing or | ||
| blank, it will not be in the output. | ||
| Default: ``[]``. |
There was a problem hiding this comment.
Maybe just say "Default: None." ([] implies it's a list, not a mapping.)
But also… should the default be nothing? Does that mean that $atypes will always be empty by default? Perhaps this should come with a default mapping, like the one shown below, so the plugin is useful "out of the box"?
There was a problem hiding this comment.
That's a good idea, I think. I've set the default values to the example config and adjusted the docs accordingly.
| - **ignore_va**: A list of types that should not be output for Various Artists | ||
| albums. Useful for not adding redundant information - various artist albums | ||
| are often compilations. | ||
| Default: ``[]``. |
There was a problem hiding this comment.
Again, perhaps the default here should be what's shown below—i.e., "compilation"? It seems like a sensible default for most people.
| albumtype:soundtrack Various Artists/$album ($year)$atypes)/... | ||
| comp: Various Artists/$album ($year)$atypes/... | ||
|
|
||
| Example outputs:: |
There was a problem hiding this comment.
"This configuration generates paths that look like this, for example::"
| Pink Flow/(1995)(Live) p·u·l·s·e | ||
| Various Artists/20th Century Lullabies (1999) | ||
| Various Artists/Ocean's Eleven (2001)(OST) | ||
|
|
There was a problem hiding this comment.
Probably no need for this extra line.
|
I've done the improvements you mentioned, added sane defaults, etc. The comment about formatting output got me wondering, though: would it not be better to provide Also, still wondering if I should rename the plugin to |
sampsyo
left a comment
There was a problem hiding this comment.
Awesome! This looks great; I think it's basically good to go.
About the additional configuration values: I don't have a strong feeling either way! I definitely can envision people wanting a formatting like [EP, Remix]. But it's also totally fine to merge a minimal version of the plugin that fits your needs and to add more features later, "on demand," as people actually want them. (To philosophize for a moment, that strategy can be higher-overhead but lead to outcomes that more closely match what users want.) May I leave that decision up to you?
I usually have opinions about naming, but I am also finding myself without a strong feeling about the plugin name… I definitely see the argument for naming it the same as the field it creates, but the current name helps describe what it does. So again, I'm perfectly happy either way!
| are often compilations. | ||
| - **bracket**: Defines the brackets to enclose each album type in the output. | ||
|
|
||
| The default configuration looks like this: :: |
There was a problem hiding this comment.
| The default configuration looks like this: :: | |
| The default configuration looks like this:: |
(I believe this is equivalent.)
|
Either way is fine with me, so I'll just leave things as they are currently. I don't personally have a need to do I adjusted the docs based on your comment, so if there's nothing more, it's ready to be merged. :) |
|
Excellent! Nice work on this!! 🎉 🚀 |
Description
Added a plugin to add a configurable album template field
$atypesto formatalbumtypesof an Album (see #4045).Should I rename the plugin to
atypessince that's the field it adds, and to reduce possible confusion with the actual fieldalbumtypes?To Do
docs/to describe it.)docs/changelog.rstnear the top of the document.)