Skip to content

Conversation

@j9ac9k
Copy link

@j9ac9k j9ac9k commented Oct 17, 2025

By overriding the format attribute of the item, beets comes up with a destination path that the user expects.

Description

Fixes #1360

Currently when doing a convert command, when beets determines what the new file path should be, it uses the path to the original file, and changes the extension, but the new format is not referenced at all when determining the new destination path. This PR overrides the format attribute of the item just before the destination path is resolved, thus returning the path that takes the new format in mind.

To Do

This is my first contribution tobeets (and frankly, the first time I've had reason to look at the codebase). There could very well be a relevant class method I missed to better accomplish what I want rather than overriding the format attribute

  • Documentation. (If you've added a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@j9ac9k j9ac9k requested a review from a team as a code owner October 17, 2025 19:30
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@j9ac9k j9ac9k force-pushed the have-convert-plugin-use-new-format-in-pathing branch from 5130e68 to 3e0dc73 Compare October 17, 2025 19:33
By overriding the format attribute of the item, beets comes up with a
destination path that the user expects.
@j9ac9k j9ac9k force-pushed the have-convert-plugin-use-new-format-in-pathing branch from 3e0dc73 to d411a83 Compare October 17, 2025 20:15
@j9ac9k
Copy link
Author

j9ac9k commented Oct 17, 2025

Seeing as there are test failures here, and the tests seem to be checking for (what I would consider to be) the wrong output path, I would love some guidance on how to handle this from a maintainer. Should I change the tests, mark those texts as xfail ?

Copy link
Member

@henry-oberholtzer henry-oberholtzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a feature I'd like to see implemented.

I think right now the logic isn't quite placed where it needs to be - overriding the item's format definitely seems like the quickest way to hack it to the right path, but I think we're seeing a lot of unintended side-effects from it in the amount of tests that are currently failing. I've left a comment indicating what I think might be causing it, and a potential workarounds.

item, original, converted = None, None, None
while True:
item = yield (item, original, converted)
item.format = fmt.upper()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a few side-effects of making this change here, partially as the test failures indicate. Most the tests don't really operate with the item's file type in the path, so they shouldn't fail if a change it made to the way file path behavior is handled.

At line 376, 380, 410, there are calls to should_transcode(item, fmt) -- by overriding the item's format type, I believe it'll now skip conversion as it thinks the incoming file is already the target type.

Adding a line below 359 to restore the item's format to it's original might help this keep the path check logic OK. However, keep_new at 374 will put the original file at the dest path instead, so that's an edge case we'll want to be wary of making this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better perhaps to add a method to the Item class to more thoroughly handle cases where formats are changed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Item class is a bit too close to the core code I think for this plugin to have enough weight to get a new method. It's also a representative of the database structure primarily.

Intercepting the path_formats is probably the best option, and replacing the string that represents the file format and replacing it with the format for the target path destination. Probably good to have it be covered by a config option as well, so as to not unexpectedly change behavior.

@j9ac9k
Copy link
Author

j9ac9k commented Oct 18, 2025

Definitely a feature I'd like to see implemented.

I think right now the logic isn't quite placed where it needs to be - overriding the item's format definitely seems like the quickest way to hack it to the right path, but I think we're seeing a lot of unintended side-effects from it in the amount of tests that are currently failing. I've left a comment indicating what I think might be causing it, and a potential workarounds.

Appreciate the comment, I'm happy to keep working to the point that it's ready to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert: Paths should reflect the new file, not the original file

2 participants