MusicPlayerDaemon / MPD

Music Player Daemon
https://www.musicpd.org/
GNU General Public License v2.0
2.12k stars 340 forks source link

m3u relative path of music file is relative to music_directory, not the playlist #200

Closed gamescom15 closed 6 years ago

gamescom15 commented 6 years ago

Given that you have a structure like this:

Music
├─ Genre1
├─Genre2
├─etc...
└─Playlists

or like this:

.
├─ Playlists
│   ├─ Playlist1
│   └─ Playlist2
└─ Music
    ├ Genre1
    ├ Genre2
    └ etc ...

with "Music" as the music_directory. Even though there is no official standard, most music players, for example VLC, implement it so that the relative filepaths in the m3u-playlist should be relative to the playlist. This is the correct way, according to Wikipedia (source). However, in MPD the filenames have to be relative to the music_directory. This means that you can't use a folder structure like this across multiple different music players and operating systems with MPD.

MaxKellermann commented 6 years ago

Hmmm:

$ mpc -q clear; mpc load bugs/200/foo.m3u
loading: bugs/200/foo.m3u
$ mpc playlist -f '%file%'
bugs/200/bar.mp3
$ echo listplaylistinfo bugs/200/foo.m3u |nc localhost 6601
OK MPD 0.20.0
file: bugs/200/bar.mp3
Last-Modified: 2018-01-18T20:48:33Z
Artist: Deftones
Title: Feiticeira
Album: White Pony
Track: 1
Time: 190
duration: 189.944
OK
^C
$ cat ~/mpd/music/bugs/200/foo.m3u
bar.mp3

This very much looks like MPD already does what you want it to do, doesn't it?

gamescom15 commented 6 years ago

@MaxKellermann I meant if the file is not in the same folder as the playlist, sorry i wasn't specific enough. Folder structure:

Music
├── playlists
│   ├── to_musicdir.m3u
│   └── to_playlist.m3u
└── songs
    └── bar.mp3
sudo egrep '^music_directory|^playlist_directory' /etc/mpd.conf
music_directory         "~/Music"
playlist_directory      "~/Music/playlists"
$ mpc -q clear; mpc load to_musicdir
loading: to_musicdir
l$ mpc playlist -f '%file%'
songs/bar.mp3
$ mpc -q clear; mpc load to_playlist
loading: to_playlist
$ mpc playlist -f '%file%'
$ tail playlists/*
==> playlists/to_musicdir.m3u <==
songs/bar.mp3

==> playlists/to_playlist.m3u <==
../songs/bar.mp3

The playlist that contains the path relative to the music_directory loads fine, the one that contains the path relative to the playlist itself does not.

MaxKellermann commented 6 years ago

The format of playlist files in the playlist_directory should be opaque to you. You should not read or write them directly, only through the MPD protocol. So what you want is change MPD internals, but for reasons that violate the design. You can have playlist files anywhere within the music_directory and use the load command to use them. These files have the semantics you requested.

gamescom15 commented 6 years ago

@MaxKellermann After putting the mpd playlist folder back to the default (restarted mpd after, updated the database just in case) and trying to load them from file, neither option worked. Is there a different syntax? man mpc shows that it should be right, am i missing something?

$ sudo egrep '^music_directory|^playlist_directory' /etc/mpd.conf
music_directory     "~/Music"
playlist_directory      "~/.mpd/playlists"
~/Music$ mpc -q clear; mpc load playlists/to_playlist.m3u
loading: playlists/to_playlist.m3u
~/Music$ mpc playlist -f '%file%'
~/Music$ mpc -q clear; mpc load playlists/to_musicdir.m3u
loading: playlists/to_musicdir.m3u
~/Music$ mpc playlist -f '%file%'
~/Music$
MaxKellermann commented 6 years ago

Read my post again.

gamescom15 commented 6 years ago

@MaxKellermann Edited my post for clarity. The playlists i am trying to load are in the music_directory (/home/username/Music) in the subfolder playlists, not in the playlist_directory (/home/username/.mpd/playlists)

MaxKellermann commented 6 years ago

Then check the log.

gamescom15 commented 6 years ago

@MaxKellermann trying to load it with mpc only gave

Jan 19 11:52 : client: process command "load "playlists/to_musicdir.m3u""
Jan 19 11:52 : client: command returned 0

so i tried opening the playlist with ncmpcpp, and there it finally said something useful Jan 19 12:01 : db: No such song: playlists/../songs/bar.mp3

My guess is that it seems to have a problem converting a relative path to an absulute path, cause

~/Music$ readlink playlists/../songs/bar.mp3 --canonicalize
/home/username/DiffentFolder/Music/songs/bar.mp3

works. /home/username/Music is a symlink to DifferentFolder/Music, so it might also be related to that

MartyLake commented 4 years ago

For posterity. I have been looking for a solution that store actively its playlist files as relative files, so that my whole music library is portable and can be synced via any cloud provider (I use dropbox).

If you want mpd to create valid mp3 files, just configure the library and the playlist folders to be the same ! For example:

music_directory "C:/Users/Marty/Dropbox/Music/"
playlist_directory "C:/Users/Marty/Dropbox/Music/"

Thanks for using a portable format as internal representation, I hope it won't change anytime soon =)

smithjd15 commented 4 years ago

I have a similar issue with similar requirements, with xspf playlists with relative paths in a subfolder in the directory specified as music_directory and music in subfolders at the same level as the playlists folder.

I have a daemon acting as a master for a remote daemon with smb and the proxy db. The error for trying to play back a track from a playlist loaded from a file in M.A.L.P. for both differ. mpc won't load any tracks into the playlist (via mpc load playlists/xxxx.xspf) on either daemon.

The log for local playback with M.A.L.P.: xxx xx xx:xx : client: [15] opened from xxxx.xxx.x.xx:xxxxx xxx xx xx:xx : exception: No such directory xxx xx xx:xx : exception: No such directory xxx xx xx:xx : exception: No such directory xxx xx xx:xx : exception: No such directory xxx xx xx:xx : client: [15] closed

The log for remote playback with M.A.L.P.: xxx xx xx:xx : client: [11] opened from xxxx.xxx.x.xx:xxxxx xxx xx xx:xx : exception: Bad URI xxx xx xx:xx : exception: Bad URI xxx xx xx:xx : exception: Bad URI xxx xx xx:xx : client: [11] closed

The log for both with mpc: xxx xx xx:xx : client: [63] opened from local xxx xx xx:xx : client: [63] closed

The playlists have been verified to otherwise work.

You can have playlist files anywhere within the music_directory and use the load command to use them. These files have the semantics you requested.

Since this issue (still) applies to xspf as well, it should be retitled and reopened.

smithjd15 commented 4 years ago

Further, I get a "Bad song index" error when trying to play back the entire xspf playlist file from M.A.L.P.. This error occurs on both daemons.