Thursday, December 20, 2018

Overcast, AudioBooks, Huffduffer, and Workflow

The best minds of my generation are thinking about how to make people click ads. - Jeff Hammerbacher
My preferred way of reading AudioBooks is to get the chapters loaded directly into Overcast so I can intersperse them with them with podcast episodes and so I can use Smart Speed and faster playback. It’s wonderful to finish up an episode of TWiT followed up by a chapter of Embassytown and so on.
You pay a subscription to Overcast so that you can upload your audio files to the Overcast servers and load your content from there. That is a fine way to do it. Castro actually supports side loading any audio files from your iCloud Drive, an even cooler feature, which I think will come next year in Overcast. But what to do for now?
There is this great, simple, free service called Huffduffer that lets you host your own Podcast RSS file where you an use a web form and fill in the title, audio location, and it will add it in. So I subscribe to that RSS in Overcast, upload my audiobook file to Dropbox, and then add the Dropbox public link to my Huffduffer. Even cooler, after Overcast downloads the audio file, I can delete it off my Dropbox account.
I was always a little annoyed and needing to get the link from Dropbox, and then use the Huffduffer web form to add it. On the iPhone, that is not always so easy and I wondered if I would be able to do it through a shortcut. The answer is yes, but it’s complicated.
Step 1: Getting the Dropbox URL is pretty easy. I mean, you share in Dropbox to Shortcuts and that activates the workflow. A little bit of replace to switch to the direct download URL and then I also regex out the filename so I can use that for a Episode Name suggestion.

Step 2: Storing the Huffduffer username and password I do a little tricky because I don’t want to store it directly in the workflow. So I think a decent little trick here is I store it in a dictionary file on iCloud Drive. It is pretty darn complicated to write the simple idea of, “if the file does not contain the username, then ask for it, otherwise use what’s in the file.”

Step 3: The Huffduffer login is easy, it just posts to a standard login form and gets back a session cookie. I don’t quite understand what is happening from sandboxing perspective but the workflow doesn’t get access to cookie that’s been set in Mobile Safari and the cookie doesn’t persist through multiple iterations of the workflow — but it does get sent in subsequent URL calls to Huffduffer.

Step 4: Sorry Huffduffer. On the form to add your article, there is a hidden randomly generated string called “csrf” which is probably something like “Client Side Reference” and I would guess is setup to make scripting harder. But in the modern world of scripts it’s really just an annoyance. Now getting with Shortcuts is a bit weird. When you “Get Contents of a URL” it basically gives you back the rendered page at RTF so you don’t have access to the hidden variable, but if you pipe that through “Make HTML from Rich Text” you get back to the original HTML of the page. From there a simple regex can pull the value out.

Step 5: Now the final step is just to execute the actual add form call with the form data and BOOM, magically the Dropbox URL (or any Web URL) has become a part of my Huffduffer account.

Epilogue: Shortcut development is painful. When trying to develop a little route (like getting the HTML) I have to setup a second shortcut with the small chunk of workflow and experiment. Once that is working I load the working test shortcut on my iPhone and re-implement it on my iPad because there is no way to copy-paste.
And then getting screenshots of the shortcuts if it is more than a single screen? I had to take multiple shots and then load them all into Pixelmator and crop and paste layers together. Not fun for anyone.