Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created March 17, 2023 13:38
Show Gist options
  • Save ryanfb/c36b8c82a5dbcd9a6b9610c5fc03c828 to your computer and use it in GitHub Desktop.
Save ryanfb/c36b8c82a5dbcd9a6b9610c5fc03c828 to your computer and use it in GitHub Desktop.
Undo accidentally running id3tag on an M4A or M4B audio file. Assumes GNU grep and head are available at ggrep and ghead respectively (`brew install coreutils` on macOS).
#!/bin/bash
OFFSET=$(ggrep --only-matching --byte-offset --max-count=1 --binary --text --perl-regexp "\x00\x00\x00\x1c" "$1" | head -1 | cut -d':' -f1)
tail -c +$(( $OFFSET + 1 )) "$1" | ghead -c -128 > untagged.m4b
if ffprobe -loglevel quiet untagged.m4b ; then
echo "Untagging succeeded for: $1"
mv untagged.m4b "$1"
else
echo "Untagging failed for: $1"
fi
rm -f untagged.m4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment