-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
PICARD-2025: Add file path to metadata view #2552
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,7 @@ def _preserve_times(self, filename, func): | |
|
||
def _save_and_rename(self, old_filename, metadata): | ||
"""Save the metadata.""" | ||
metadata["path_old"] = old_filename | ||
config = get_config() | ||
# Check that file has not been removed since thread was queued | ||
# Also don't save if we are stopping. | ||
|
@@ -412,6 +413,10 @@ def _save_and_rename(self, old_filename, metadata): | |
return new_filename | ||
|
||
def _saving_finished(self, result=None, error=None): | ||
if error is None and result is not None: | ||
new_filename = result | ||
# Add new path info after successful rename | ||
self.metadata["~path_saved"] = new_filename | ||
Comment on lines
+416
to
+419
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must be missing something because it appears that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that Bob has prompted me to think further, it seems to me that we need to know:
To make life easiest for scripters, once a file is loaded and before it is saved we need to decide whether the previous path is set to the current path or left empty / non-existent. And we should decide whether to save the entire path (directory path and filename as a string) or the directory path and the filename separately or possibly both. (Scripters may want directory and filename separate or they may want it together. UI needs them separate.) Motivation: We should try to get this exactly right from the start before we create a backwards compatibility problem for scripters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do we need this? When the file is saved, I think the file variables are automatically updated to the new path and filename, so I'm not sure what the use case would be for the original path and filename.
My suggestion is to keep the path and filename as separate variables for the maximum flexibility of use. In Picard's scripting, it's easier to combine the two than split them out from a combined value. Another consideration is how path separators are displayed and saved. The current file naming script preview displays the drive and path as used for the file system (using a colon and backslashes for windows paths). I think this is fine (and appropriate) for the display in the table in the Metadata pane. It's probably okay for the values stored in the variables as well, but we may need to be careful because of the use of the backslashes in paths on windows systems. I assume they would need to be escaped for the tags/variables, although I really don't know the details of how they are saved in the file metadata (if the user chooses to copy the variable to a tag so it is saved).
I agree, although I don't think we're actually changing any of the existing tags/variables so we shouldn't have any backwards compatibility issues. [Famous last words... 😜] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't personally have a use for this, however this was the initial purpose of this PR.
I agree. Indeed, since we already split out the existing filename and extension, we should probably do that for the proposed filename and extension.
Whilst I agree in principle with this, I think that we need to stick with the way
I was thinking about not creating future backwards compatibility issues if we later find we got this PR wrong. |
||
# Handle file removed before save | ||
# Result is None if save was skipped | ||
if ((self.state == File.REMOVED or self.tagger.stopping) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -561,9 +561,24 @@ def update(self, drop_album_caches=False): | |
|
||
def _update_tags(self, new_selection=True, drop_album_caches=False): | ||
self.selection_mutex.lock() | ||
files = self.files | ||
tracks = self.tracks | ||
self.selection_mutex.unlock() | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you introduced a try block here? What exceptions are you expecting? There is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing that out, I forgot to add the except block but I simply couldn't get it to work on my machine without using a try block. I'll look into it properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Presumably you were getting an exception without the However, please see later comments as you may want to hold off from spending any more time on this code until there is consensus on what is actually needed. |
||
files = self.files | ||
tracks = self.tracks | ||
|
||
if not (files or tracks): | ||
return None | ||
for file in files: | ||
old_path = file.metadata.get('path_old', file.filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing "~". |
||
file.orig_metadata['Path'] = old_path | ||
|
||
new_path = file.metadata.get('~path_saved', file.filename) | ||
file.metadata['Path'] = new_path | ||
Comment on lines
+572
to
+575
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have introduced a new metadata tag here and there are various issues with this:
None of the above are major pieces of work, but they do need to be done. |
||
# Update album cache check | ||
if new_selection or drop_album_caches: | ||
self._single_file_album = len({file.metadata['album'] for file in files}) == 1 | ||
Comment on lines
+577
to
+578
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to have been included in the |
||
|
||
finally: | ||
self.selection_mutex.unlock() | ||
|
||
if not (files or tracks): | ||
return None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"~" missing.