Nextcloud server playlist import

I really like the Nextcloud Music app. Previously I had complained that music playlist import by hand is more complicated than I would like. But today I found that Nextcloud Music has a server-side playlist import feature. Neat!

When I reset my music collection in Nextcloud (because I was messing with ID3 tags or such), I lose my playlists in the web interface. There is a nice import function to fix this – but it has a catch.

sudo -u www-data php occ music:playlist-import me --overwrite --file "Music/playlists/the_elder_scrolls.m3u"

I would try this inside the server, and it would report zero tracks imported.

Turns out this is no good for my m3u file contents:

A Chance Meeting.mp3
Ancient Stones.mp3
Aurora.mp3
Awake.mp3
A Winter's Tale.mp3
Before the Storm.mp3
Beneath the Ice.mp3
Blood and Steel.mp3
Caught off Guard.mp3
Dawn.mp3
Death or Sovngarde.mp3
Distant Horizons.mp3
Dragonborn.mp3
Dragonsreach.mp3
Far Horizons.mp3

The m3u file needed to have this:

../A Chance Meeting.mp3
../Ancient Stones.mp3
../Aurora.mp3
../Awake.mp3
../A Winter's Tale.mp3
../Before the Storm.mp3
../Beneath the Ice.mp3
../Blood and Steel.mp3
../Caught off Guard.mp3
../Dawn.mp3
../Death or Sovngarde.mp3
../Distant Horizons.mp3
../Dragonborn.mp3
../Dragonsreach.mp3
../Far Horizons.mp3


I think this is because most people organize their music collections to keep their files in subdirectories based on either album or artist. I throw everything into one subdirectory because I rely on the Nextcloud Music app to find the ID3 tags and organize it that way.

I’ve written a Perl script to read the same m3u file, and to pull a random file from it and throw that at Music Player Demon when the current track list gets too low. But the file paths on the server are different from what inside Nextcloud knows, so I was keeping the m3u file super simple and letting Perl figure out how to tell MPD where the file could be found.