Skip to content
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

Support for track migration inside library #1173

Open
ChibyX opened this issue Nov 5, 2024 · 2 comments
Open

Support for track migration inside library #1173

ChibyX opened this issue Nov 5, 2024 · 2 comments
Labels

Comments

@ChibyX
Copy link

ChibyX commented Nov 5, 2024

Let's say, I moved track1.mp3 from /Music to /Music/Favourites. Currently, if I do that, I would need to re-add this track to all playlists it was placed in. But maybe it's possible to implement feature: if after regular scan system found that track1.mp3 is no longer in its' place but there's file with same name in different subfolder, it edits path to this track in playlists. Probably there could be UI for user to allow/deny such migrations to prevent situations when track was actually replaced with same-named file.

@2br-2b
Copy link

2br-2b commented Nov 5, 2024

In theory, you could use some hashing algorithm to track the same song, even if you don't hash the metadata (so that can be updated separately)

@paulijar paulijar added the Bug label Nov 6, 2024
@paulijar
Copy link
Collaborator

paulijar commented Nov 6, 2024

There is actually an oversight on my behalf when I implemented the file move/rename handling some seven years ago: In case a file is moved or renamed within the user's cloud using the intended mechanisms like the web UI or the PC sync, the host cloud fires preRename and postRename hooks which are listened by the Music app. These hooks are currently handled the same way as if the file was first deleted from the old location/name and then recreated with with the new location/name. This works otherwise well, keeping the library intact with no dangling references or anything but it has the problem reported in the OP: When we recreate the library object associated with the file, the object gets a new ID and we lose track of any playlists where the song might have belonged to.

It shouldn't be too difficult to change this so that we wouldn't recreate the library object on this case but just update the existing one. We then just need to handle separately the case where the song is moved off the configured music library path, because in that case, we actually need to handle the moving the same way as if the file was deleted.

paulijar added a commit that referenced this issue Nov 13, 2024
Our previous FileHooks implementation was such that moving a scanned audio
file from on folder within the library to another folder within the library
caused the track object matching the said file to be deleted and the
recreated. Hence, the track got a new ID and it got removed from any
playlists where it belonged to.

Now we handle file moving separately and differently than a file deletion
followed by file recreation, and the track gets updated "in place", without
changing the ID or removing it from existing playlists.

If, on the other hand, an entire folder full of scanned audio files gets
moved, then we do one of two things:
1) In case there's 30 or less audio files contained, we handle each file
separately the same way as if those 30 files were moved individually
2) In case there are more than 30 audio files contained, we remove them all
from the library and the user needs to rescan the files.

The second case is suboptimal but we can't handle any number of files
one-by-one during the moving because that could slow down the moving
operation too much. In the best case this would annoy the user and in the
worst case it would cause a time-out and break the entire operation.

This is a partial fix for #1173.
paulijar added a commit that referenced this issue Nov 23, 2024
- If the user's library contains any files potentially needing rescanning,
  this is now prompted to the user upon app loading, similarly as any new
  files to scan

- The rescanning of modified files, both with the new prompt and using
  `occ music:scan --rescan-modified`, can now also remove files from the
  library if the modified file turns out to be within an excluded folder

- When moving folder within the music library, and that folder contains more
  than 15 audio files, those files are now marked as "dirty" to trigger the
  mechanism described above. Previously, up to 30 files were rescanned
  immediately and over 30 files were removed from the library, which was
  sub-optimal.

- This completes the fix for #1173
  which was started with the commit 9c43c9c. This also provides a partial
  fix for the old issue #706.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants