beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.86k stars 1.82k forks source link

smartplaylist: Change base directory for exported paths #2547

Open duckpuppy opened 7 years ago

duckpuppy commented 7 years ago

Problem

I run a Subsonic server on a different machine than the one I use for managing my music library. Both access the same music library, but they differ between machines (in fact, one is a Windows machine sharing a local path and one is Linux mounting that share). Subsonic requires playlists to have absolute paths as well, so I can't just use relative paths. I would like to be able to supply a playlist with a "from" and "to" mapping such that the written path has the "from" string replaced with the "to" string.

ex:

map_from: /mnt/music/
map_to: G:/Music/

would write G:/Music/Artist/Album/01 - track.mp3 into the m3u for a file located at /mnt/music/Artist/Album/01 - track.mp3.

sampsyo commented 7 years ago

Huh, that is an interesting setup. One other solution you could consider would be to do a little bit of post-processing on the generated m3u files—a quick pipe through sed s/\/mnt\/music\//G:\/Music\// would do the trick.

duckpuppy commented 7 years ago

It's not that strange a setup - except maybe the Windows server part for beets users - and a common support request for users of both Subsonic and Logitech Media Server is how to make whatever library manager they're using export proper absolute paths in their playlist. Using sed is certainly possible (and what I do now), but not so automated unless I wrap beets in a shell script. And I'm using beets because it already automates most of what I need for library management.

It's not so out of the ordinary for people using a NAS that's also running Subsonic or Logitech Media Server (which also wants absolute paths in playlists - relative paths are seen as a security concern for both since they could point to files outside the configured music folders) to have the same issue - the path to the files on the NAS where the music server is running will be different from the path they mount the library to for managing with beets.

I've seen this feature in a couple of other library managers that allow exporting a playlist to a file with path replacement, but they're all GUI managers and I live mostly on the command line.

All-in-all, I think this is a low risk feature that also shouldn't be difficult to implement looking at the existing code for the plugin, though python is not one of my go-to languages.

Kraymer commented 7 years ago

@sampsyo would it be possible for the plugin to emit a (new) smartplaylist_written event so the sed command can be plugged to it using the hook mechanism ?

sampsyo commented 7 years ago

OK; thanks for clarifying. I'll mark this as a feature request. What would you think of a slightly simpler version that just replaces the directory from your library configuration value, instead of requiring an explicit map_from?

duckpuppy commented 7 years ago

That would be OK in my case, and I can't think of a use case right now that wouldn't be covered by that. The library path as an implicit "from" sounds great.

Savanta commented 2 months ago

That would be great because now I have to sed my playlists from time to time to be usable with airsonic