Tools: powershell, hoopla-dl script, ffmpeg, mplayer
There's a couple different ways to install powershell. I installed it via apt (sudo apt install powershell) but there's also a snap (
https://snapcraft.io/powershell) so whatever suits your fancy.
Invoke powershell via the command line ($ pwsh). (NB: I tried to add a shebang (#!/usr/bin/pwsh) to the powershell script to get it to run through the interpreter from the native shell but that wasn't successful so you will need to actually enter the shell.)
The hoopla-dl script isn't particularly helpful in terms of command-line documentation (or documentation in general) so I usually refer back to what I used in the past. I am going to walk through the download of
https://www.hoopladigital.com/title/11872742, The Death of the USS Thresher:
$ echo $SHELL
/bin/bash
$ pwsh
PowerShell 7.1.4
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /dev/shm/cache> which ffmpeg /home/user/bin/ffmpeg
PS /dev/shm/cache> ./hoopla2.5.ps1 -Outputfolder /dev/shm/cache -FfmpegBin /home/user/bin/ffmpeg -KeepDecryptedData -TitleID 11872742
WARNING: Epubzip binary not found (/dev/shm/cache/epubzip.exe). If you are downloading ebooks (rather than comics or audiobooks), you may wish to download the binary from https://github.com/dino-/epub-tools/releases, specify a different path with -EpubZipBin, or specify -KeepDecryptedData so that you can manually pack afterward.
Directory: /dev/shm/cache Mode LastWriteTime Length Name ---- ------------- ------ ---- ----- 9/20/2021 7:59 AM 297520325 The Death of the USS Thresher.m4a Decrypted data for 11872742 (The Death of the USS Thresher) stored in /tmp/dec-183294214-20210920075715
PS /dev/shm/cache> ls -l './The Death of the USS Thresher.m4a'; mediainfo './The Death of the USS Thresher.m4a'
-rw-rw-r-- 1 bvargo bvargo 297520325 Sep 20 07:59 './The Death of the USS Thresher.m4a'
General
Complete name : ./The Death of the USS Thresher.m4a
Format : MPEG-4
Format profile : Apple audio with iTunes info
Codec ID : M4A (isom/iso2)
File size : 284 MiB
Duration : 5 h 6 min
Overall bit rate mode : Variable
Overall bit rate : 129 kb/s
Writing application : Lavf58.29.100
Audio
ID : 1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 5 h 6 min
Bit rate mode : Variable
Bit rate : 128 kb/s
Maximum bit rate : 130 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 281 MiB (99%)
Default : Yes
Alternate group : 1
PS /dev/shm/cache> ls /tmp/dec-183294214-20210920075715/
filesequence0000000.ts filesequence0000062.ts filesequence0000124.ts filesequence0000186.ts filesequence0000248.ts
filesequence0000001.ts filesequence0000063.ts filesequence0000125.ts filesequence0000187.ts filesequence0000249.ts
filesequence0000002.ts filesequence0000064.ts filesequence0000126.ts filesequence0000188.ts filesequence0000250.ts
.
.
.
filesequence0000055.ts filesequence0000117.ts filesequence0000179.ts filesequence0000241.ts filesequence0000303.ts
filesequence0000059.ts filesequence0000121.ts filesequence0000183.ts filesequence0000245.ts ttm_9781541423053.m3u8
filesequence0000060.ts filesequence0000122.ts filesequence0000184.ts filesequence0000246.ts
filesequence0000061.ts filesequence0000123.ts filesequence0000185.ts filesequence0000247.ts
Key points with the hoopla-dl script parameters:
-TitleID comes from the title in the URL for the audiobook.
-KeepDecryptedData saves the individual one minute audio files. These can be stitched back together using ffmpeg concatenate but most likely they're just going to be deleted. They're left in /tmp, e.g., in /tmp/dec-183294214-20210920075715, in this case.
-Ffmpegbin is the location of ffmpeg. If you installed it via apt, it should be /usr/bin/ffmpeg. If you compiled it yourself, it may be e.g., ~/bin/ffmpeg. To find what version is called via the path, use `which ffmpeg`
-Outputfolder I use /dev/shm/cache because it is an easy ram disk and I don't commit anything to disk until finished manipulating. Modify to suit your needs...I'm even though I call the full path, I'm still just using ./
At least for me, I can call ls -l, mediainfo, and ffmpeg from within Powershell to get an output of the finished file(s). You can also see from the MediaInfo output that this is not chaptered, so aside from breaking it in half just for smaller files, this is done, dress it up in a .torrent, spank it on the bottom, and send it on it's way.
To break it into smaller files:
First, figure out a midpoint. If you just go by MediaInfo, you have a length of 05:06 hh:mm. With
mplayeryou can get a precise length (down to hundredths of a second in this case). From there, you can call two ffmpeg processes. In the following two examples, the file will be split at the midpoint without re-encoding (and, hence, without generational loss).
Mplayer to look at all file info:
$ mplayer -vo dummy -ao dummy -identify The\ Death\ of\ the\ USS\ Thresher.m4a
MPlayer 1.3.0 (Debian), built with gcc-9 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing The Death of the USS Thresher.m4a.
libavformat version 58.29.100 (external)
libavformat file format detected.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f4b5eb4e600]Protocol name not provided, cannot determine if input is local or a network protocol, buffers and access patterns cannot be configured optimally without knowing the protocol
ID_AUDIO_ID=0
[lavf] stream 0: audio (aac), -aid 0, -alang und
Clip info:
major_brand: M4A
ID_CLIP_INFO_NAME0=major_brand
ID_CLIP_INFO_VALUE0=M4A
minor_version: 512
ID_CLIP_INFO_NAME1=minor_version
ID_CLIP_INFO_VALUE1=512
compatible_brands: isomiso2
ID_CLIP_INFO_NAME2=compatible_brands
ID_CLIP_INFO_VALUE2=isomiso2
encoder: Lavf58.29.100
ID_CLIP_INFO_NAME3=encoder
ID_CLIP_INFO_VALUE3=Lavf58.29.100
ID_CLIP_INFO_N=4
Load subtitles in ./
ID_FILENAME=The Death of the USS Thresher.m4a
ID_DEMUXER=lavfpref
ID_AUDIO_FORMAT=MP4A
ID_AUDIO_BITRATE=128000
ID_AUDIO_RATE=44100
ID_AUDIO_NCH=2
ID_START_TIME=0.00
ID_LENGTH=18396.65
ID_SEEKABLE=1
ID_CHAPTERS=0
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 58.54.100 (external)
AUDIO: 44100 Hz, 2 ch, floatle, 128.0 kbit/4.54% (ratio: 16000->352800)
ID_AUDIO_BITRATE=128000
ID_AUDIO_RATE=44100
ID_AUDIO_NCH=2
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
No such audio driver 'dummy'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting... (End of file)
ID_EXIT=EOF
A lot of info, but all we need is the length of the file (in seconds), so pipe to grep for "ID_LENGTH":
$ mplayer -vo dummy -ao dummy -identify The\ Death\ of\ the\ USS\ Thresher.m4a |grep ID_LENGTH
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
ID_LENGTH=18396.65
No such audio driver 'dummy'
Could not open/initialize audio device -> no sound.
Divide that number in half and put it into an ffmpeg command:
ffmpeg -loglevel error -stats -i The\ Death\ of\ the\ USS\ Thresher.m4a -acodec copy -to 9198.325s The\ Death\ of\ the\ USS\ Thresher\ --\ Part\ 01.m4a
size= 145274kB time=02:33:18.33 bitrate= 129.4kbits/s speed=7.46e+03x
$ ffmpeg -loglevel error -stats -i The\ Death\ of\ the\ USS\ Thresher.m4a -acodec copy -ss 9198.325s The\ Death\ of\ the\ USS\ Thresher\ --\ Part\ 02.m4a
size= 145274kB time=02:33:18.31 bitrate= 129.4kbits/s speed=4.79e+03x
-to is the stop time of the first half, i.e., 9198.325 seconds into the whole.
-ss is the start time of the second half i.e., 9198.325 seconds into the whole.
If you want to convert formats, e.g., to 17 kb/s opus, you can do that directly by specifying the codec and bitrate instead of using the -acodec copy flag:
$ ffmpeg -loglevel error -stats -i The\ Death\ of\ the\ USS\ Thresher.m4a -acodec libopus -b:a 17k -to 9198.325s The\ Death\ of\ the\ USS\ Thresher\ --\ Part\ 01.opus
size= 19754kB time=02:33:18.33 bitrate= 17.6kbits/s speed=49.4x
video:0kB audio:19062kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.629999%
$ ffmpeg -loglevel error -stats -i The\ Death\ of\ the\ USS\ Thresher.m4a -acodec libopus -b:a 17k -ss 9198.325s The\ Death\ of\ the\ USS\ Thresher\ --\ Part\ 02.opus
size= 20058kB time=02:33:18.32 bitrate= 17.9kbits/s speed=45.4x