From 99ddefeb6b7345258739402e03ce500bf6f4c13d Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 21 Jul 2021 14:56:45 +0530 Subject: [PATCH] Fix audible m4a files Based on https://rentry.co/n4ost --- README.md | 3 ++- audible-strip-drm | 1 + ec | 0 fix-audible-m4a | 30 ++++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) mode change 100644 => 100755 ec create mode 100755 fix-audible-m4a diff --git a/README.md b/README.md index 0dd4d43..0430125 100644 --- a/README.md +++ b/README.md @@ -109,4 +109,5 @@ This lives in my `~/projects/scripts` directory and is added to my `$PATH`. Not | yubilock.sh | Lock my screen when I remove my device. Runs using udev triggers | | ec | script to edit common configuration | | get-nav | Get NAV of a mutual fund from the Kuvera API | -| audiobook2video | Generates a video for a music file, with a background | \ No newline at end of file +| audiobook2video | Generates a video for a music file, with a background | +| fix-audible-m4a | Third-party. Fixes audible m4a fiels with incorrect Audio Object Type Specific Config bit. Source: https://rentry.co/n4ost | \ No newline at end of file diff --git a/audible-strip-drm b/audible-strip-drm index c4bc1f7..eaba955 100755 --- a/audible-strip-drm +++ b/audible-strip-drm @@ -4,3 +4,4 @@ IFS=$'\n\t' # PODMAN FTW! podman run -v $(pwd):/data ryanfb/inaudible@sha256:b66738d235be1007797e3a0a0ead115fa227e81e2ab5b7befb97d43f7712fac5 +for i in "*.m4a"; do fix-audible-m4a "$i";done \ No newline at end of file diff --git a/ec b/ec old mode 100644 new mode 100755 diff --git a/fix-audible-m4a b/fix-audible-m4a new file mode 100755 index 0000000..3af209a --- /dev/null +++ b/fix-audible-m4a @@ -0,0 +1,30 @@ +#!/bin/bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail + +# Source: https://rentry.co/n4ost + +f="$1" +t=$(mktemp) +mp4extract-bento4 moov/trak/mdia/minf/stbl/stsd/mp4a/esds \ + "$f" /dev/stdout | xxd -p | tr -d '\n' > $t + +magic=$(sed -re 's/^.*0580808002(....).*$/\1/' $t) + +if [ "$magic" != "1212" ]; then + echo "no need to fix" + rm "$t" + exit 0 +fi + +t2=`mktemp` +new=$(sed -re 's/05808080021212/05808080021210/' $t | xxd -r -p >$t2) +rm $t +old="${f}.pre-fix" +mv -v "$f" "$old" +mp4edit --replace \ + moov/trak/mdia/minf/stbl/stsd/mp4a/esds:"$t2" \ + "$old" \ + "$f" + +rm "$old" \ No newline at end of file