diff --git a/hosts/nyarlathotep/configuration.nix b/hosts/nyarlathotep/configuration.nix index 9456b69e..56b79acf 100644 --- a/hosts/nyarlathotep/configuration.nix +++ b/hosts/nyarlathotep/configuration.nix @@ -363,7 +363,7 @@ in enable = true; description = "Automatically tag new podcast files"; wantedBy = [ "multi-user.target" ]; - path = with pkgs; [ inotifyTools id3v2 ]; + path = with pkgs; [ ffmpeg inotifyTools id3v2 ]; unitConfig.RequiresMountsFor = "/mnt/nas"; serviceConfig = { WorkingDirectory = "/mnt/nas/music/Podcasts/"; diff --git a/hosts/nyarlathotep/jobs/tag-podcasts.sh b/hosts/nyarlathotep/jobs/tag-podcasts.sh index 16d15c39..359b02c6 100644 --- a/hosts/nyarlathotep/jobs/tag-podcasts.sh +++ b/hosts/nyarlathotep/jobs/tag-podcasts.sh @@ -4,6 +4,18 @@ set -e sleep 60 +for m4afile in */in/*.m4a; do + if [[ ! -f "$m4afile" ]]; then + break + fi + + bitrate=$(ffprobe -v quiet -of flat=s=_ -show_entries format=bit_rate "${m4afile}" | sed 's/[^0-9]*//g') + destination="$(echo "$m4afile" | sed 's:m4a$:mp3:')" + echo "m4a: ${m4afile} -> ${destination}" >&2 + ffmpeg -y -i "$m4afile" -codec:a libmp3lame -b:a "$bitrate" -q:a 2 "$destination" + rm "$m4afile" +done + for mp3file in */in/*.mp3; do if [[ ! -f "$mp3file" ]]; then break