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
Edit plugin #1706
Edit plugin #1706
Conversation
added yamleditor(a new plugin) entry
polishing
more polishing
polishing
polishing
polishing
polishing
polishing
polishing
polishing
change name from yamleditor to edit
added the edit plugin
@jmwatte, I'm interested in trimming down the initial version of this plugin to the bare minimum. We can add more flexibility later, but I'm really interested in getting something as simple as possible for the first iteration. Would it be OK with you if I removed some of the indirection that supports multiple methods? For now, I'll hard-wire this to be YAML-only for readability's sake. |
I'm also not 100% sure about including your (rather clever) logic for reducing the display of fields with the same value (the |
sadly there are two more things:
|
Not just the built-in fields.
Thanks for trying this out!
Yep, this was an oversight. I just changed the option to work for any field. I also changed the name from |
This is another good point—the plugin is just trusting the YAML type of each value, rather than using the beets logic for parsing strings (as the This will, unfortunately, be a little bit difficult to fix. The problem is that the YAML parser sees the values not as strings but as a whole bouquet of different types. We'll need to resort to some sort of hack to let beets do the value parsing instead of the YAML library. Or we could switch away from YAML as the serialization format. |
An observation on the scenario presented by @pkess, which I'm unsure if it is the expected behaviour: if the user-specified extra field ( |
As for the problem of yaml auto-magically performing type conversion, looks like a nontrivial issue indeed! However, I'm wondering if it could be alleviated to some extent by trying to make use of Flexible fields and
An informal and dirty hack (by appending
|
Yes, I was thinking the same thing. The only trick with that change is that we'll need the "round trip" to stay correct: if you leave the field empty in the editor, beets shouldn't add it to the item. It's not quite clear to me how to distinguish that from adding the field with an empty value. |
Excellent idea! 😃 http://docs.beets.io/en/v1.3.15/plugins/types.html
Yes, now that you mention that, it could be as easy as just dumping everything to a string and then loading it back from a string. The only problem is if someone comes along and sees:
which is a string value and changes it to:
in an attempt to flip the Boolean. Then YAML will parse this not as the string "false" but as the Boolean value |
Well, that's embarrassing 😓. I did some greping and peek at the issues to find out if that was already in place, but seems it got past my not so deep research! Maybe we should preliminary add some comments on the documentation of the plugin, cautioning about the potential issues with custom fields? |
Here's another way to make things safe: let's dump everything to strings, as planned, and then reject modifications like the example I showed (where the user inputs a non-string type). Over time, we can make this more tolerant by accepting, for example, the Boolean |
All editable values are now strings and are parsed from strings. This closely matches the behavior of the `modify` command, for example.
We need a sequence of dictionaries back; validate this assumption.
I hadn't quite realized before that the user could also change the *keys* to be non-strings too! This also prevents against that by just reinterpreting everything as strings.
OK, here's an implementation of that idea that I'm reasonably happy with. If the user messes things up and uses a non-string value, we currently just try stringifying the value and then parsing it. This could be a little smarter, but I think this should work for most cases (and should solve the original problem). One trick here is that we need to be sure that all data types can "round-trip" for ergonomic editing. One problem I ran into immediately was with the bitrate field: it gets formatted as "128kbps" (for example), but the parser just sees this as the number 128 instead of 128000. This is problematic because there is actually some data lost here---the low bits of the bitrate number. |
One way to cope with the above problem would be to special-case some types that we know are safe for YAML editing, like the numeric types or booleans. These would somehow bypass the formatting when printed. If they come back as the same type as they were written out, then they also bypass parsing; if the user changes to a different type, then we can stringify and parse as a fallback. |
This avoids some round-tripping problems with types (such as ScaledInt) that are not represented in strings with 100% fidelity. It also makes the syntax nicer when editing numbers and booleans: they no longer appear to be needlessly surrounded by quotes in the YAML.
OK, sorry for all the noise but this latest revision should do it. Most values are stringified and parsed again, but certain "safe" types get a pass. They are still validated to ensure nothing crazy happens, though, and parsed as strings if necessary. |
Looking good! I'm wondering if it would be a good time to include some more tests focused on specific functions on the plugin, or perhaps it's better to hold off until it is included on the main branch? |
Awesome! More tests are always better, but I don't have a strong opinion about whether they should come before or after merge. If it's looking reasonably complete, I think we can merge at will! |
Hi, i just merged master into this branch because i experienced errors with this branch and the badfiles plugin because of unicode characters |
Thanks for updating the PR, @pkess. I think this is ready enough for inclusion in the next point release. There are still more things we could do, of course, but no need to hold it back any more. Merging now. |
Successor to #1687. This is @jmwatte's interactive editor plugin.