I’ve finally been able to convert the playlists getting full metadata, included albumart.
This version makes two conversions: first converts Windows playlists to simple, temporary Volumio ones. REST commands are used to do everything from CLI. Entries only have the uri of the files. This ones are played with a curl shell command for short time. Second, the queue with the current playlist is converted to complete Volumio one.
Assumptions are the same as above versions except for point 6. A backup of converted lists is also made in the script folder. Lists can’t have spaces in their names unless one converts spaces to some other character and later does the opposite
#!/bin/bash
# Set your Windows PC music folder path
win_path='E:\\Data\\Music\\'
# Set your Volumio music folder path
vol_path='USB\/disk_label\/Data\/Music\/'
# Remove BOM
find . -type f \( -name "*.m3u8" \) -exec sed -i '1s/^\xEF\xBB\xBF//' {} +
# Convert Windows CRLF To Unix LF line endings
sed -i 's/\r$//' *.m3u8
# Replace Windows music folder with Volumio music folder path
sed -i "s%$win_path%$vol_path%g" *.m3u8
# Replace remaining \ with /
sed -i 's/\\/\//g' *.m3u8
# Remove first line (containing #)
sed -i '1d' *.m3u8
# Prepend {"service":"mpd","uri":" to each line
sed -i 's/^/{"service":"mpd","uri":"/' *.m3u8
# Append "}, to each line
sed -i 's/$/"},/' *.m3u8
# Append "]" to last line of file
sed -i '$s/$/]/' *.m3u8
# Replace },] with },] in last line of file
sed -i 's/},]/}]/' *.m3u8
# Prepend [ in the beginning of file
sed -i '1 i\[' *.m3u8
# Create temporary file
TMPFILE=$(mktemp /dev/shm/win2qvol.XXXXXX)
# Loop in current folder and convert queue to playlist
for i in *.m3u8
do
# Copy ready *.m3u8 playlists to /data/playlist
cp "$i" /data/playlist/"$i"
# Clear queue
curl localhost:3000/api/v1/commands/?cmd=clearQueue
# Play playlist for short time (NO SPACES ALLOWED IN PLAYLISTS NAME).
# One can delete "sleep 2" or change the time (tested witho no sleep too)
curl localhost:3000/api/v1/commands/?cmd="playplaylist&name="$i""
sleep 2
# Stop playing
curl localhost:3000/api/v1/commands/?cmd=stop
# Copy queue to temporary file
cp /data/queue "$TMPFILE"
# Cut single space
sed -i 's|"uri": |"uri":|g' "$TMPFILE"
sed -i 's|"service": |"service":|g' "$TMPFILE"
sed -i 's|"artist": |"artist":|g' "$TMPFILE"
sed -i 's|"albumart": |"albumart":|g' "$TMPFILE"
sed -i 's|"album": |"album":|g' "$TMPFILE"
# Rename name to title and cut single space
sed -i 's|"name": |"title":|g' "$TMPFILE"
# Delete non relevant lines
sed -i '/"type": "track",/d' "$TMPFILE"
sed -i '/"tracknumber": 0,/d' "$TMPFILE"
sed -i '/"duration":/d' "$TMPFILE"
sed -i '/"trackType":.*/d' "$TMPFILE"
sed -i '/"samplerate":.*/d' "$TMPFILE"
sed -i '/"bitdepth":.*/d' "$TMPFILE"
sed -i '/"channels".*/d' "$TMPFILE"
# Cut leading double and quadruple spaces
sed -i 's| ||g' "$TMPFILE"
sed -i 's| ||g' "$TMPFILE"
# Swap uri and service lines
sed -r -i '$!N;s/^(\s*"uri":"mnt.*)\n(\s*"service".*)/\2\n\1/;P;D' "$TMPFILE"
# Crop , in albumart line
sed -ri 's/^"albumart(.*)",/"albumart\1"/g' "$TMPFILE"
# Copy $TMPFILE to playlists directory and back it up in current folder.
# My playlist directory is called conversion. Change as you like
cp "$TMPFILE" /data/playlist/"$i"
cp "$TMPFILE" /data/INTERNAL/conversion/"$i"
# Crop extension in backups
mv "$i" "${i%.m3u8}"
# Delete content of "$TMPFILE"
> "$TMPFILE"
done
# Loop in /data/playlist directory to crop extension
for i in /data/playlist/*.m3u8
do
mv "$i" "${i%.m3u8}"
done
# Remove temporary file
rm "$TMPFILE"