Bash script to convert Volumio playlists to Windows m3u8 ones

Here is a script to convert Volumio playlists to Windows m3u8 ones.
One only needs to copy the code below in a text file, give it a name.sh, make it executable and run it with ./script_name.sh. That’s all.

Assumptions:

  1. the Windows folders structure of one’s music collection will be the same of the Volumio’s one. Example, the hard disk connected to your RPI will be a backup of the Windows’ one (or else you might tweak it to your different needs)
  2. one will need only to customize the variables win_path and vol_path after checking the Windows playlists and the path of music folder in Volumio. Don’t delete slashes and backslashes here!
  3. Converted playlists will be m3u8, same as those made with Foobar2000. These format supports UTF-8
  4. the to be converted playlists will be copied in a subdirectory of the one you are running the script from. It is called “vlpllist” and that’s where you’ll find the converted ones too
#!/bin/bash
                                      
# Set your Windows PC music folder path (don't touch slashes).
# Example:
win_path='E:\\Data\\Music\\'

# Set your Volumio music folder path (don't touch slashes and back-slashes).
# Example:
vol_path='USB\/drive_label\/Data\/Music\/'

# Copy all Volumio playlists to a "volpllist" subfolder
mkdir volpllist
rsync -av --exclude=".*" /data/playlist/ volpllist
cd volpllist

# Rename playlists to *.m3u8
find . -type f  ! -name "*.*" -exec mv {} {}.m3u8 \;

# Crop leading "[" and trailing "]"
sed -i '1s/^.//;s/.$//' *.m3u8

# Insert a break-line after each },
sed -i 's/},/&\n/g' *.m3u8

# Replace Volumio music folder with Windows music folder path
sed -i "s%$vol_path%$win_path%g" *.m3u8

# Replace remaining / with \
sed -i 's/\//\\/g' *.m3u8

# Crop leading {"service":"mpd","uri":"
sed -i 's/{"service":"mpd","uri":"//g' *.m3u8

# Crop trailing text starting from first "
sed -i 's|","title":".*||' *.m3u8

# Add a leading blank line
sed -s -i '1i\\' *.m3u8

# Add a leading "#" in the blank line
sed -i '1s/^/# /' *.m3u8

# Add BOM  (be careful when a file already has a BOM)
sed -i '1s/^/\xef\xbb\xbf/' *.m3u8

# Convert Unix LF To Windows CRLF
sed -i 's/$/\r/' *.m3u8

# Go one level up
cd ..