back

Useful shell scripts

I thought to share some of the scripts in my .local/bin, because why not. I'm sharing these as/is, if your computer has a nuclear meltdown when you run them thats your issue not mine.

I will warn you that these scripts are far from efficient, you might get eye cancer just from looking at them.


1. songdl:

I download YouTube videos as MP3's using yt-dlp with these flags, it sets YT thumbnail as the mp3 cover. One issue is it copies the whole description into the mp3 metadata. This one can be set as an alias.

#!/bin/sh

yt-dlp -x --continue --add-metadata --embed-thumbnail --metadata-from-title "%(title)s" --audio-format mp3 --audio-quality 0 --prefer-ffmpeg -o "%(title)s.%(ext)s"  $1

2. rdir:

I use this to shred large folders, it takes a while because it overwrites the disk with zeros. (use at your own risk)

#!/bin/sh

if [ -z "$1"  ]; then
	echo "no folder specified"
else
        find "$1" -type f -exec shred -uvzn3 {} \;
        rm -rf "$1"
fi

3. mus:

I organise my music playlists in folders, and use this to play them shuffled.

#!/bin/sh

mdir=$HOME/music
cache=$HOME/.cache/mus

if [ -d $mdir/$1 ]; then
	dir=$mdir/"$1"
else
	dir=$mdir/
fi

get_song () {
stat=0
while [ $stat -eq 0 ]; do
	song=$(find $dir -name "*.mp3" -type f | shuf -n 1 )
	[ ! -f  $cache ] && echo $song >> $cache

	# if picked song isn't inside cache  
	if [ ! $(grep "$song" $cache | wc -l) -gt 0 ]; then
		stat=1
		echo "$song" >> $cache
	fi

	# if cache file more than 5 lines remove first line
	if [ $(wc -l <$cache) -gt 5 ]; then
		sed -i 1d $cache 
	fi
done
}

while true; do
	get_song
	mpv --no-audio-display "$song"
	printf "\033c" # clears screen
	sleep 1
done