Last active
July 21, 2025 11:43
-
-
Save bonnebulle/d12109bd07eb7d570fdc9a201106a633 to your computer and use it in GitHub Desktop.
loop find mp3 in sub-folders, bypass when ok (already done), add BPM to etag (bypass if already)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| ## DEBIAN https://www.ryananddebi.com/2023/12/09/linux-adding-bpm-to-id3-tags/ | |
| # Directory containing music files | |
| MUSIC_DIR="$1" | |
| echo $MUSIC_DIR | |
| sleep 1 | |
| if [[ $2 == "--force" ]];then | |
| BYPASS_IF_OK_EXISTE="false" | |
| else | |
| BYPASS_IF_OK_EXISTE="true" # true == if .ok existe, bypass | |
| fi | |
| if [[ $2 == "--ls" ]];then | |
| ls -lha "$MUSIC_DIR" | |
| exit 0 | |
| fi | |
| if [[ $2 == "--rm" ]];then | |
| rm "$MUSIC_DIR/.ok" | |
| ls -lha "$MUSIC_DIR" | |
| exit 0 | |
| fi | |
| # Loop through each file in the directory | |
| # Chercher tous les sous-dossiers ne contenant pas le fichier .ok | |
| find "$MUSIC_DIR" -type d -print | while read -r dir; do | |
| echo | |
| echo "BYPASS_IF_OK_EXISTE == $BYPASS_IF_OK_EXISTE" | |
| # Vérifie si le fichier .ok existe déjà | |
| if [[ (-e "$dir/.ok") && ($BYPASS_IF_OK_EXISTE == "true") ]]; then | |
| echo "_________" | |
| echo "_________" | |
| echo "Le fichier .ok existe déjà dans..." | |
| echo $dir | |
| echo "_________" | |
| echo "_________" | |
| echo | |
| else | |
| echo | |
| echo | |
| echo "Traitement du dossier : " | |
| echo "----- $dir" | |
| mp3_total=$(find "$dir" -maxdepth 1 -type f \( -name "*.mp3" -o -name "*.flac" \) | wc -l) | |
| mp3_count=0 | |
| bpm_exists=0 | |
| # /// FIND IN SUB FOLDERS | |
| find "$dir" -maxdepth 1 -type f \( -name "*.mp3" -o -name "*.flac" \) | while read -r file; do | |
| mp3_count=$((mp3_count+1)) | |
| filename=$(basename "$file") | |
| sleep 0.1 | |
| echo | |
| echo | |
| echo | |
| echo "------------------------" | |
| echo $dir | |
| echo " ------ : $filename" | |
| # /// CHECK IF BPM ALREADY EXISTS | |
| BPM_PRESENT=$(eyeD3 "$file" | grep -i 'bpm:' | awk '{print $2}') | |
| if [ -n "$BPM_PRESENT" ]; then | |
| echo "---OK BPM déjà présent ( $BPM_PRESENT ), on saute ce fichier." | |
| bpm_exists=$((bpm_exists+1)) | |
| else | |
| BPM=$(bpm-tag -f "$file") | |
| echo "---- GO - Calculated BPM: ( $BPM )" | |
| echo | |
| fi | |
| # SI LA TOUT TRAITE (todo -- less restrictiv, if just 1 is done (so, the folder is checked)) | |
| # if [ $mp3_total = $mp3_count ]; then | |
| if [ $mp3_count -gt 0 ]; then | |
| touch "$dir/.ok" | |
| echo | |
| echo "_________" | |
| echo "_________" | |
| echo "_________" | |
| echo "_________" | |
| echo "Fichier .ok créé dans $dir" | |
| echo "_________" | |
| echo "_________" | |
| echo "_________" | |
| echo "_________" | |
| echo | |
| sleep 1 | |
| else | |
| echo $mp3_count | |
| echo "---- OOO" | |
| sleep 0 | |
| fi | |
| echo | |
| done | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment