[Linux Bash command]
Copy a local playlist library to send to your phone so that you don't have to copy everything. Only the items being used in the playlist will be copied. Has update functionality. Absolute lifesaver for a local music collection!
#!/usr/bin/bash
# README
# This script will copy the contents of a playlist and the playlist file itself
# to a set destination while preserving folder structure, ensuring that the playlist file will work.
# Playlists must be made of LOCAL paths -- It is recommended that all playlists are in the same main folder.
# Tested on m3u playlists. Basically the file needs to be plain text with each item being on a new line.
# Has update functionality { V V V }
# You can update your library by running this same command as you did before.
# It checks if files already exist and if there is a newer version it can replace them with.
# However it does not remove files that are no longer present in/used by the playlist.
# INSTRUCITONS
# Open Terminal inside the folder containing the playlists.
# Copy the script below and paste it in the opened Terminal.
# Set the playlist filename. The one you'll be reading the contents of.
# Set the target destination - the main folder where everything will branch off from.
# Press ENTER and look at HACKERMANS SCREEN (you are just copying files..)
filename="Playlist.m3u"
target="/directory/to/copy/to"
while read -r line; do
name="$line"
echo "Reading line from file - $name"
cp --parents -R -u -p "$name" "$target"
done < "$filename"
cp -R -u -p "$filename" "$target"
# EXTRA FUNCTIONALITY OwO
# Replace "illegal" symbols in the playlist file (":", "?").
# This is needed if you are transferring to a file system that doesn't support them.
# Linux by default will replace those symbols with "_" so this is intended to fix the paths in the playlist file.
# The command below will take care of that.
sed -i -e 's/[:?"<>\|*]/_/g' "/path/to/playlist/file/to/fix/Playlist.m3u"
# Both commands combined for easier use.
filename="Playlist.m3u"
target="/directory/to/copy/to"
while read -r line; do
name="$line"
echo "Reading line from file - $name"
cp --parents -R -u -p "$name" "$target"
done < "$filename"
cp -R -u -p "$filename" "$target"
sed -i -e 's/[:?"<>\|*]/_/g' "$target/$filename" My first Linux bash script... (I guess you could call it a script).
I stopped using Spotify and have built a local library of the music I love the most. I like game OSTs so I bought them on Steam and Bandcamp. Some games had theirs as goodies on GOG.
The thing is that if I want to also have them on my phone I can't just copy my entire library to it because it's too big and inconvenient. So I came up with a solution -> This script copies only the music that exists in a playlist so it's the stuff that I listen to the most.
One problem I ran into though was that on my phone, some paths were broken. Folders and files that contain "illegal" characters like ":" and "?" are not supported by the file system on my phone (in Linux file systems only "/" is an illegal character).
So when I copied my stuff over, those symbols were replaced by "_" which breaks a lot of playlist entries. The way I fixed that is by adding another command that replaces all of the illegal characters with "_" INSIDE of the playlist file, correcting for that mishap. Now everything works!
Oh, and it also has update functionality! It checks if the needed songs already exist in the target location and if they do it'll skip copying and overwriting them. It also checks if there is a newer version of the files.
That means I just have to do the same command again to update my portable library :3 (it does not delete music that was later removed from the playlist though).