|
@echo off |
|
setlocal enableextensions |
|
chcp 65001 |
|
set input=%1 |
|
set device=%2 |
|
set loglevel=quiet |
|
for %%i in ("%~f1") do set dirname=%%~dpi |
|
for %%i in ("%~f1") do set extension=%%~xi |
|
|
|
set tempfile=%dirname%%RANDOM%-temp.m4a |
|
set tempimage=%dirname%%RANDOM%-temp.png |
|
|
|
if /i "%1" EQU "" (echo Usage: %0 ^<filename^> ^<device^> & goto :eof) |
|
if /i "%extension%" NEQ ".aax" (echo Not an AAX file! & goto :eof) |
|
if /i "%2" EQU "" set device=0 |
|
if /i "%3" EQU "debug" set loglevel=info |
|
where /q ffmpeg || (echo Please install ffmpeg! & goto :eof) |
|
where /q jq || (echo Please install jq! & goto :eof) |
|
|
|
echo. |
|
rem http://stackoverflow.com/a/12730022/2710739 |
|
for /f "tokens=2*" %%a in ('reg.exe query "HKLM\SOFTWARE\WOW6432Node\Audible\SWGIDMAP" /v "%device%"') do set bytes=%%b |
|
set activation_bytes=%bytes:~6,2%%bytes:~4,2%%bytes:~2,2%%bytes:~0,2% |
|
if /i "%bytes%" EQU "" echo Device %device% does not exist! & goto :eof |
|
if /i "%activation_bytes%" EQU "FFFFFFFF" echo Device %device% is not activated! & goto :eof |
|
echo Using Device %device% (Activation Bytes: %activation_bytes%) |
|
|
|
echo. |
|
echo Reading audiobook information ... |
|
for /f "tokens=*" %%i in ('ffprobe "%input%" -v %loglevel% -print_format json -show_format ^| jq -r ".format.tags.artist"') do set artist=%%i |
|
for /f "tokens=*" %%i in ('ffprobe "%input%" -v %loglevel% -print_format json -show_format ^| jq -r ".format.tags.title"') do set title=%%i |
|
for /f "tokens=*" %%i in ('ffprobe "%input%" -v %loglevel% -print_format json -show_format ^| jq -r ".format.tags.date"') do set year=%%i |
|
for /f "tokens=*" %%i in ('ffprobe "%input%" -v %loglevel% -print_format json -show_format ^| jq -r """\(.format.duration|(tonumber/60/60)|floor)h\(.format.duration|(tonumber%%60))m"""') do set duration=%%i |
|
set filename=%artist% - %title% [%year%].m4a |
|
set filename=%filename:\=% |
|
set filename=%filename:/=% |
|
set filename=%filename::=% |
|
set filename=%filename:?=% |
|
set filename=%filename:"=% |
|
set filename=%filename:<=% |
|
set filename=%filename:>=% |
|
set filename=%filename:|=% |
|
rem crashes the cmd if variables contain umlauts ... |
|
rem echo %artist% - %title% [%year%] (Duration: %duration%) |
|
|
|
echo. |
|
echo Converting to m4a ... |
|
ffmpeg -y -v quiet -i "%input%" "%tempimage%" |
|
ffmpeg -y -v %loglevel% -stats -activation_bytes %activation_bytes% -i "%input%" -c:a copy -vn "%tempfile%" || (echo Audiobook can't be unlocked with this Activation Bytes: %activation_bytes% & goto :cleanup) |
|
|
|
echo. |
|
echo Adding looped cover image audiobook |
|
ffmpeg -y -v %loglevel% -stats -r 1 -loop 1 -i "%tempimage%" -i "%tempfile%" -c:a copy -shortest "%dirname%%filename%" |
|
echo. |
|
echo Done! |
|
goto :cleanup |
|
|
|
:cleanup |
|
del /q "%tempfile%" >nul 2>&1 |
|
del /q "%tempimage%" >nul 2>&1 |
|
goto :eof |
Does this copy over the chapter information?