From f134cd2b35a7290d16c5b6c3394112183576f76a Mon Sep 17 00:00:00 2001 From: will Date: Sat, 18 Feb 2023 02:55:10 -0700 Subject: [PATCH] Add dirtomp3.sh to /stuff/ dirtomp3.sh is a Bash script that recursively converts an entire directory of music to mp3s --- stuff/dirtomp3.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ stuff/index.php | 4 ++++ 2 files changed, 62 insertions(+) create mode 100755 stuff/dirtomp3.sh diff --git a/stuff/dirtomp3.sh b/stuff/dirtomp3.sh new file mode 100755 index 0000000..ac75c20 --- /dev/null +++ b/stuff/dirtomp3.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# This is a simple script I wrote to convert my entire music library to mp3s for putting on my phone. +# You need to have ffmpeg installed with support for all relevant formats for this to work. + +# HOW TO USE: +# Place this script in the directory that your library's root directory is in, i.e. if your music +# library is in ~/Music/Library, this script should be located at ~/Music/dirtomp3.sh +# Set the variable "root" to the name of your library's root directory +# Set "newroot" to the desired root directory of the output. This will be created if it doesn't exist. +# The script should take care of the rest. + +root="Library" +newroot="Library_mp3" +mvcount=0 +tdcount=$(($(find "$root" -type f -not -path '*/.*' | wc -l))) + +printf "\x1b[s" +echo ".00% done ($mvcount/$tdcount files processed)" + +recurse() { + path="$1" + for f in "$path/"*; do + nf=$(echo "$f" | sed "s/^$root/$newroot/;s/\.flac\|\.wav\|\.ogg$/.mp3/") + if [[ "$f" != $root* ]]; then + echo "Script attempted to access item $f outside designated operating area, aborting" + exit + fi + if [[ "$nf" != $newroot* ]]; then + echo "Script attempted to access item $nf outside designated operating area, aborting" + exit + fi + if [[ -d "$f" ]]; then + mkdir -p "$nf" + recurse "$f" + elif [[ -f $f ]]; then + printf "\x1b[2K%s" "$(echo "$f" | head -c $(tput cols))" + if [[ "$f" == *.flac ]] || [[ "$f" == *.wav ]] || [[ "$f" == *.ogg ]]; then + if [[ ! -f $nf ]] || [[ $f -nt $nf ]]; then + ffmpeg -i "$f" "$nf" -loglevel 0 + if [[ $? -gt 0 ]]; then + exit + fi + fi + elif [[ "$f" == *.mp3 ]]; then + cp -u "$f" "$nf" + elif [[ "$f" == *.png ]] || [[ "$f" == *.jpg ]] || [[ "$f" == *.jxl ]] || [[ "$f" == *.gif ]]; then + cp -u "$f" "$nf" + fi + mvcount=$((mvcount+1)) + printf "\x1b[u%s%% done (%d/%g files processed)\n" "$(echo "scale=2; $(echo "$mvcount/$tdcount*100" | bc -l)/1" | bc)" "$mvcount" "$tdcount" + fi + done +} + +mkdir -p $newroot +recurse "$root" +printf "\x1b[2K" diff --git a/stuff/index.php b/stuff/index.php index fb82ada..6b4bc7d 100644 --- a/stuff/index.php +++ b/stuff/index.php @@ -146,6 +146,10 @@ userstyles.world/style/5238
/status-cafe-latte
Stylus theme I made for status.cafe, the site behind the little status widget on my blog. + + dirtomp3.sh + Linux Bash script I wrote to recursively convert my entire music library to mp3s to reduce the amount of space it takes up on my phone. Copies the entire directory structure, keeping images, converting audio if needed, and discarding everything else. Requires ffmpeg. +