Remove DRM Easily (?) from Your Audible Purchases

NOTE: The following instructions are for Windows; I may later figure out the equivalent on macOS.

NOTE: The only way to remove DRM from an Audible audiobook is to play and record it digitally with your computer. If it’s a 17 hour book, the conversion takes 17 hours!

I listen to audiobooks a lot, and mostly I buy them from Audible. However, Audible’s own player sucks. Unless it has changed recently, its bookmarking system is non-existent, and it also couldn’t keep track of multiple books in progress at the same time. So I prefer to use the excellent Listen Audiobook Player on my Android phone (on iOS devices you might consider Bookmobile Audiobook Player). But it won’t play the Audible’s DRM-protected files, so somehow I have to get rid of the protection first. I’ve been using Aimersoft’s DRM Media Converter for the task for the last couple of years, but today I found out that it no longer works after a recent Windows update. It invokes iTunes (which is authorized to play the Audible DRM content) as it should, but for some reason it no longer ‘hears’ what iTunes plays back to it, so the mp3 is never written.

I spent a couple of hours figuring out a new solution. Even though this new solution requires a few of more components, it’s more stable and the required components are free/donationware, so you can get accomplish the task for free, or at least at a cost acceptable to you (I recommend pitching in to the Virtual Audio Cable folks for their fine piece of software!) ?

So let’s get started.

  1. Log in to your Audible account, then click on “Hi, {Yourname}! ˅” (on top of the Audible page), and navigate to Account Details > Update Settings, then scroll to the bottom of the page, and clear “Check for Audible Download Manager” checkbox if it is checked.
  2. Download and install Audible Manager. You’ll only use the Audible Download Manager from this installation; you’ll find it in the “AudibleManager” folder in the Start menu.
  3. Download and install iTunes. Once installed confirm that you’re using “Windows Audio Session” (which means system sound) in iTunes Preferences > Playback > “Play Audio Using”.
  4. Download and install Virtual Audio Cable. If you have a 64-bit system (which is likely), select the 64-bit installer when starting the installation (both are included in the download). Note that it needs to be installed as the Administrator, so you may need to right click on the installer, and select “Run as administrator”. Virtual Audio Cable is donationware, so once you have this setup working, consider returning to the VB-AUDIO Software website, and sending them a donation of your choice.
  5. Download and install Aktiv Mp3 Recorder. It is free.
  6. Open Aktiv Mp3 Recorder and configure it:

    aktiv_mp3

    1. Check detect silence
    2. Set silence duration at least to 20 seconds. If the audiobook you’re converting has long stretches of silence, set this to a longer amount so that the recording won’t stop prematurely. However, there will be this amount of silence at the end of the recording before the recording is automatically stopped when the book ends.
    3. Select CABLE Output (VB-Audio Virtual…) for the input device. If it doesn’t show up on the list (after you installed Virtual Audio Cable earlier during this process), reboot your computer and continue from this step.
    4. Select the output folder. The file name you’ll want to of course set for each book you’re converting.
    5. Select 128kBPS, 44Hz Stereo for the output format.
    6. Click on “Set Default” so that you don’t have to reconfigure this every time (the only thing that you need to change is the Target File name).
    7. When you’re ready to start recording, click on “Record” (but not yet!)
    8. Close the program (note that you have to exit the program in the systray where it remains after you close the main window).

The above steps need to be done only once to set up. The following steps are repeated whenever you download new content from Audible, and process the conversion:

  1. Once you have purchased an audiobook in Audible, go to your “Library” in Audible, and click on the “DOWNLOAD” button for that book. A file with name “admhelper.adh” will be downloaded. While each “DOWNLOAD” action (for any audiobook you have purchased) downloads an “admhelper.adh” file, each file is specific to the book which you downloaded it for. When you double-click on an “admhelper.adh” file, Audible Download Manager will open and immediately start downloading the corresponding DRM-protected audio file. The file has an “.aax” extension.
  2. Open iTunes and click on the drop-down in the top left corner. By default it is set to “Music”, but choose “Audiobooks” instead. Then drag and drop the downloaded audiobook file (with the “.aax” file extension) into iTune’s library pane on the right. If you haven’t played Audible content with iTunes previously, you will be prompted to authorize iTunes with Audible. Proceed to do so, and a browser window will open. Log in to Audible with the same credentials you purchased the book with, and click on the link “Click here to complete your activation!”. You are now ready to play the audiobook in iTunes, and you can test-play it if you like.
  3. To prepare for conversion, set the system audio input/output: go to the Control Panel, open “Sound”, and in “Playback” tab set the default to “CABLE Input” (make note of what was the previous default as you’ll want to return to it after the conversion is complete). Then go to the “Recording” tab, and set the default to “CABLE Output”. NOTE: If you use DFX or other sound enhancer that iTunes plays through, you should set the output (to “CABLE Input”) in that program’s settings.
  4. To prepare for conversion, open the Volume Mixer from the system tray (or hit Win+R, then type “sndvol”, and click “OK” to open the mixer). Select “CABLE Input” device from the Device drop-down if it’s not already selected, and mute System Sounds, and preferably the browser and other sound sources besides iTunes (any sounds made by the system or the browser will otherwise be included in the converted audiobook).
  5. Ready to go! Open iTunes, make sure the audiobook you want to convert is on the Audiobooks library page. Open Aktiv Mp3 Recorder, make sure the settings are as you set them earlier, then enter the audiobook’s name in the File name field. Click on “Record”, then switch (within 20 seconds or whatever you configured as Silence Duration) to iTunes, and start playing of the audiobook. Switch back to the Aktiv Mp3 Recorder, and make sure that the audio is coming in (the level indicators should be moving). Then wait. And wait. ? Note that you can go to the iTunes window and see on the top, next to the playing book’s title, how much time is remaining. After the entire book has played through (you won’t hear it while it’s playing), the Aktiv Mp3 Recorder will notice once there the set Silence Duration (20 seconds if you followed my steps) has elapsed, and stop the recording. You can then take the Mp3 file and tag it as you see fit (say, with Foobar2000, or any of the million other Mp3 players/taggers), copy it to your mobile device, and play it with the player of your choice!

Well, this wasn’t totally simple. ? But once you have set it up and ran through it once, it’s pretty quick to do. Obviously, after you’ve done with the conversion, you’ll want to unmute the system and browser sounds, and switch the playback/recording default devices as they were before you altered them.

I hope this is useful to someone out there! ?

Exploring GitHub Flavored Markdown local preview

I’ve been writing various lengthy documents for GitHub repositories recently, and as I push them to GitHub, and then view them in the browser, there’s almost always something wrong with the layout resulting in additional commits or amends/forced updates which I would rather avoid. I was initially using MacDown to edit/preview Markdown, but its rendering of GitHub Flavored Markdown (GFM) was way off. There had a to be a better way, and there is! I found two solutions that work reasonably well: the first one is Node-based vmd for general use (it watches the given file, and thus works with any editor), and the second is a set of plugins for Sublime Text 3. The former is now my choice for offline GFM previewing (such as on a plane), while the latter is my preferred choice because 1) Sublime Text 3 is already my go-to editor, 2) the Sublime Text plugins provide incredibly handy macros for, and context-highlighting of the Markdown being edited and, most importantly 3) the GFM is rendered through the GitHub API, ensuring that the rendered output matches the way GitHub renders it 100%. Both `vmd` and the Sublime Text solution work on macOS, Windows, and Linux Desktop.

Some other options that I looked at included Grip (a cool idea, but it kept crashing on me), or Atom‘s GFM preview (which, even with the right extensions installed, wasn’t accurately GFM, which is strange considering that Atom is made by GitHub; if you know how to make Atom render GFM through the GitHub API, please comment this article).

First, `vmd`. It’s easy to set up, simply first install Node.js on your platform, then add `vmd` with `npm` as a global:

npm install -g vmd

Now simply point `vmd` to the file you’re editing, and it gets re-rendered every time the file is saved as long as `vmd` is running.

vmd SomeFileName

That’s all. You can use any editor to edit the file.

However, if you’re using Sublime Text 3, give the following a try; it makes Markdown editing outright fun. The following instructions are for ST3.

  1. Install Sublime package manager if it’s not yet installed. Then restart Sublime.
  2. Install the following packages with the Package Manager:
    `Ctrl-Shift-p [Win] / Cmd-Shift-p [macOS] > Package Control: Install Package`

    Restart Sublime.

  3. Install monokaiC theme (read the installation instructions on its GitHub page).The target location depends on the platform, see this StackOverflow answer for details, but use the User subdir under the directory listed for your platform.
  4. SETTINGS

    1. In Markdown Preview User Settings:
      `Preferences > Package Settings > Markdown Preview > Settings — User`

      Add:

      {
         "git_oauth_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
         "github_mode": "gfm",
         "enable_autoreload": true
      }

      ** Get the `git_oauth_token` from GitHub. Log in to your GitHub account, then:
      `Settings > Developer Settings > Personal Access Tokens`, or use generatetoken.sh script. No scope permissions are required for a token for it to be valid for Markdown rendering. Note that without a token set you’re limited to about 60 renders per hour, while with the token set you can make 5000 requests per hour (which you’ll never hit, since the re-render only occurs on file save).

      ** Make sure you have a comma at the end of each line, except the last parameter line in the settings

    2. In Markdown Editing User Settings for GFM:
      `Preferences > Package Settings > Markdown Editing > Markdown GFM Settings — User`

      Add:

      {
        "color_scheme": "Packages/User/ME-MonokaiC.tmTheme",
        "extensions":
        [
          "md"
        ]
      }
    3. In Key bindings
      `Preferences > Key Bindings — User`

      Add:

      { "keys": ["alt+l"], "command": "markdown_preview", "args": {"target": "browser", "parser":"markdown"} },
      { "keys": ["alt+m"], "command": "markdown_preview", "args": {"target": "browser", "parser":"github"} }
      

    Restart Sublime.

  5. Enable Simple Reload:
    `Ctrl-Shift-p [Win] / Cmd-Shift-p [macOS] > Live Reload: Enable/Disable Plugins > Enable Simple Reload` You need to reactivate Simple Reload like this whenever you restart Sublime, and want to use the auto-reload.

All set! Open an existing markdown (.md) file, or start a new file and save it with `.md` extension. Then hit `alt-m` for GitHub-rendered preview, or `alt-l` for locally rendered (but less accurate for GFM) Markdown preview. When you make changes and save the file, the preview gets automatically refreshed in your browser using the originally selected method (i.e. GitHub API or local).

Be sure to read the MarkdownEditing documentation for awesomely useful keyboard macros and other support for Markdown! This will also give you syntax highlighting in fenced code blocks when you postfix the first triple-backtick with supported language identifier, like so:

```sql

Happy GitHub Markdown editing! Octocat

Update 2018-03-02: The `git_oauth_token` must be set in Markdown Editing package settings, not in global Sublime settings. This correction has been reflected in the above instructions.

Workflow magic (or so it seems :-)

A few days ago I came across the solution to a workflow issue I had been for long wishing could be done. Today I solved another one, and since they’re connected, I outline them below. Maybe they’ll make someone’s day! 🙂

I often work with remote servers that are almost always some flavor of Linux, most frequently Ubuntu/Debian, but also CentOS/Redhat. Despite of being a lifelong geek, I really dislike `vi`, finding it massively unintuitive. Maybe I haven’t figured out its intricacies, but I doubt it – it just doesn’t jive with me. In the 90’s I remembered most of Emacs’ chords by heart (or more likely by muscle memory), and really enjoyed using it, but for some reason I eventually stopped using it and only now am picking it up again. For now, however, my go-to editor in Linux is `joe`, which is handy enough (more so than `pico` or `nano`), but none of them still are as comfortable and flexible to use than a good GUI editor. In Windows & macOS my editor of choice is Sublime Text 3, and a few days ago I came across this answer in StackOverflow. Enter rmate/rsub! To make the magic happen, first install a small `rmate` script on your server (but call it `rsub` since you’re using Sublime Text rather than TextMate):

sudo curl -L --output /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate
sudo chmod +x /usr/local/bin/rsub

Or perhaps like this (requires `git`, but makes it easier to keep rmate/rsub up-to-date by executing `git pull` in the cloned directory):

cd /opt
git clone https://github.com/aurora/rmate.git
ln -s /opt/rmate/rmate /usr/local/bin/rsub

Then add a few lines in `~/.ssh/config` on your Mac (Windows users, keep reading, you haven’t been forgotten):

Host *
  RemoteForward 52698 127.0.0.1:52698
  UseKeyChain no

To exclude some domains where you’ll never use `rsub`, like GitHub:

Host github.com
  Hostname github.com
  User myUserName
  ForwardAgent no
  ClearAllForwardings yes
  IdentityFile ~/.ssh/myGitHubKey

(the significant line above is `ClearAllForwardings yes`)

Then install `rsub` package in Sublime (easiest done with Package Control), and now `rsub someFileName` command on the remote opens `someFileName` in Sublime on Mac! Like magic!! No need to mess with FTPS. Just one word of caution.. if you put the Mac to sleep, the “rsubbed” file may become disconnected from the remote, so when you make the first save after resuming work, verify that the changes are indeed saved, or close the file and reopen it from the remote.

`rsub` also works with Sublime Text in Windows. The only part of the above setup that differs on Windows is the SSH config since Microsoft’s effort to create a native OpenSSH port for Windows is slow going (“non-production ready pre-release v0.0.17.0” with 161 open issues as of writing of this post). I usually use the excellent commercial SSH client VanDyke’s SecureCRT as the SSH terminal in Windows. I initially thought reverse port forwarding would not be possible in it, but alas, I stand corrected! Van Dyke’s always helpful and knowledgeable technical support pointed out how to achieve the desired port forwarding in it (the config section in question was titled: “Port Forwarding – Remote/X11”, and that indeed meant “remote OR X11”, not “remote X11”, as I had read it. So regardless of whether you use PuTTY (or its derivatives like KiTTY) or SecureCRT, you setting up the port forwarding is a snap. I’ll outline below PuTTY’s setup first, then SecureCRT’s equivalent configuration.

Install and fire up PuTTY. Just to make sure you start from a clean slate, click on “Default Settings” and then “Load”:

putty-1-load-defaults

Set the name (or IP) of the server you’ll be running `rsub` from:

putty-2-set-server-name

If you’re not using PuTTY’s key agent Pageant to authenticate, enter the path for your private RSA key. Note that it must be in `PPK` format (if you have PEM format key, you need to convert it with PuTTYgen, another PuTTY utility program):

putty-3-set-key

Add the remote listener port:

putty-4-add-remote-listener-port

[OPTIONAL] If you’re NOT using this PuTTY session for the shell (i.e. if you’re using for that purpose some another program that lacks the reverse forwarding capability), disable the shell for this connection:

putty-5-do-not-start-shell

[OPTIONAL] Similarly, if you’re not using this PuTTY session for the shell, set the window size to a small value:

putty-6-set-window-size

Finally, back in the Session tab, save the session: give it a name, then click on “Save”. If this is a shell-less RSUB session only, give a descriptive name:

putty-7-save-session

Now you have configured a RSUB session in PuTTY. For convenience, you may want to create a desktop link to activate the [RSUB] session. If so, right click on the desktop and select “New > Shortcut”, then enter the path to `putty.exe`, followed by `-load`, and the name you gave the session in PuTTY:

putty-8-create-shortcut

Finally, give a descriptive name for the desktop link:

putty-9-name-shortcut

And now you have a link that opens the RSUB channel to your remote server:

putty-10-link-image

Click on it, and it opens a small session window. As long as you keep it open, you can use the `rsub` command on the remote to open and edit remote files on your local Sublime Text!

And now, the same for SecureCRT:

Once you have configured a profile otherwise (set the hostname, username, and authentication information – [preferably] either a PEM format key, or a password [if allowed by your server]), head to Connection > Port Forwarding > Remote/X11, like so:

rsub-scrt-1-add-remote-port-forwarding

Click on “Add”, and enter a name for this tunnel, such as “RSUB” here, and the port 52698. When you enter it in the “Remote > Port” field, the “Local > Port” is automatically filled out for you:

rsub-scrt-2-add-remote-port-forwarding

And now you have the `rsub` port forwarding in place in SecureCRT!

rsub-scrt-3-remote-port-forwarding-added

Now when you open the session, you automatically have a `rsub` port open as well, and once you open Sublime Text on Windows, you can proceed to type `rsub someFileName` on the server, and it opens in Sublime.

So far so good (remote editing is working great!). Today I needed to diff an old configuration file against the new one, and the CLI `diff` output was too tedious to decipher. Then it occurred to me that maybe it would be possible to somehow use my favorite GUI diff utility, Beyond Compare with Sublime — and it is! The only thing to note is that when you open Beyond Compare from the files open in Sublime, you’ll need to save the completed diff first in Beyond Compare, and then in Sublime. Note that the file change indicator doesn’t light up in Sublime even when it has received the changes resulting from the diff reconciliation in Beyond Compare. The changes are received in Sublime when you save them in Beyond Compare, but not saved from Sublime [to the server over `rsub`] until you explicitly hit save in Sublime.

Now.. the files opened in Sublime from a remote using `rsub` can be diffed by this method with Beyond Compare! Working with remote files just became a lot more fun! 🙂

Update 2017-11-07: The article was updated with the latest `rsub` installation details, and PuTTY configuration instructions were added.

Update 2017-11-09: Van Dyke’s technical support pointed out to me that the reverse port forwarding can be accomplished in SecureCRT as well, so I corrected the article, and added the configuration details for SecureCRT.

Update 2017-11-24: I just noticed you can open two files from two different servers (using `rsub`), or one file from a server, and one file locally, and then compare them with Beyond Compare as described above. So cool!

Update 2018-01-17: Note that if you have a connection open from multiple machines, the first one that reverse-forwards the port `52698` receives the file when you run `rsub someFileName` on the remote. This can be confusing if you work on same remotes from multiple systems, so if you so choose, you can map a different port from different laptops/desktops, like so:

laptop – `RemoteForward 52698 127.0.0.1:52698`
desktop – `RemoteForward 52699 127.0.0.1:52698`

(NOTE: The first port value is the forwarded remote port; the second value is the local port which always remains at `52698` as it corresponds to the Sublime’s rsub extension port set in Sublime > Preferences > Package Settings > rsub > port)

Then on the remote system set up couple of aliases, respectively (here we assume the `rmate` repo was cloned in `/opt/rmate` rather than downloaded with `curl`):

alias rsubl='/opt/rmate/rmate --port 52698'
alias rsubd='/opt/rmate/rmate --port 52699'

If you set up multiple `rsub` alternatives like this, you may not want to copy/symlink the `rmate` executable to `/usr/local/bin/rsub` as that way you have to use the the port-specific aliased commands instead.

Introducing duplicity-nfs-backup, or How to Use duplicity-backup Safely with NFS/CIFS Shares

After completing nfs_automount script a bit over a week ago, I soon realized rdiff-backup I had planned to use with the now-nearly-guaranteed-to-be-online NFS shares would not work. I then turned to my other favorite *NIX server backup solution, duplicity with duplicity-backup.sh wrapper script. It utilizes gzip-based archives, which works much better with NFS/CIFS shares. Besides the other odd problems with rdiff-backup and NFS, it resolves the more obvious issue with conflicting users/permissions between the client and the NFS share host as duplicity doesn’t maintain a direct mirrored copy of the files being backed up.

The only problem was that since duplicity creates incrementals, and I generally like to keep backups around for several months, the incrementals are really never needed beyond couple of weeks. Beyond that in my applications the day-by-day backups are overkill, and should be pruned. Duplicity provides an option to do so (“remove-all-inc-of-but-n-full”), but duplicity-backup.sh hadn’t implemented it, so I first contributed a patch to zertrin’s project. Then I proceeded to write a wrapper for the wrapper to add the extra pre-backup checks, and duplicity-nfs-backup was born.

So what is duplicity-nfs-backup? It is a wrapper script designed to ensure that an NFS/CIFS-mounted target directory is indeed accessible before commencing with backup. While duplicity-backup.sh can be used to back up to a variety of mediums (ftp, rsync, sftp, local file…), duplicity-nfs-backup is specifically intended to be used with NFS/CIFS shares as backup targets.

The script that was the impetus for writing duplicity-nfs-backup, nfs_automount, attempts to keep the NFS shares online at all times, but the client system can’t always help with such situations. What if the target system becomes unreachable due to a network problem? Or what if a disk, or a filesystem mount fails on the target while the share is still available? In any of these cases duplicity-backup/duplicity would back up into an empty mountpoint. duplicity-nfs-backup adds the necessary checks to ensure that this won’t happen, and it also issues log/syslog warnings when a backup fails due to a share that has gone M.I.A.

I mentioned earlier that duplicity-nfs-backup is “a wrapper for the wrapper.” Paraphrasing zertrin, it is important to note that duplicity-nfs-backup IS NEITHER duplicity, NOR is it duplicity-backup! It is only a wrapper script for duplicity-backup, also written in bash.

This means that you will need to install and configure duplicity and duplicity-backup.sh before you can utilize duplicity-nfs-backup. I also recommend that you would make use of nfs_automount as it significantly improves the chances that the NFS target share will be online when duplicity-nfs-backup attempts to access it.

This script is intended to be run from crontab. duplicity-nfs-backup takes no arguments, simply set the configuration parameters in duplicity-nfs-backup.conf and you’re done!

Like nfs_automount, duplicity-nfs-backup is also distributed under MIT license.

Clone or download duplicity-nfs-backup from my GitHub repository, and let me know if you come across any problems (or also if it works fantastically and saves the day! :)). Pull requests are always welcome.