Using youtube-dl on iPad

Problem

As part of my work advocating for special-needs orphans, I produce a (mostly) weekly podcast highlighting several of the children on our website. Whenever one of the featured children has a video posted on our site, I try to include an audio snippet of the child talking or, as in the case of one little boy, jamming on his toy guitar. I record, edit, and publish this podcast entirely on my iPad (except for those rare occasions when the episode is an interview), and it’s been a challenge to figure out how to extract the audio from these kids’ videos, which are almost always hosted on YouTube or Vimeo. There are various apps for the Mac that’ll download YouTube videos, but there’s nothing comparable for the iPad. I discovered that it’s possible to download these videos using the iCab browser if you change the user agent, but I could never get this to work consistently. There is a command-line program you can run called youtube-dl that will download videos from YouTube (and other sites). The problem is, the iPad doesn’t ship with a Terminal app like the Mac does, so while I could do this on my Mac, I struggled to find a way to use this command on my iPad. During its beta period, the iOS/iPadOS app iSH Shell handled youtube-dl fine, but following its public, non-beta release and the removal and subsequent reinstatement of youtube-dl from GitHub, I couldn’t get iSH Shell to work properly. Maybe that’s because I’m a command-line novice, but whatever the cause was, this was no longer working for me. I was close to giving up, but one last search last weekend proved to be unexpectedly fruitful.

Solution

The answer lies with another command-line app for the iPad: a-Shell. I’d heard about this app before in the context of youtube-dl—I think on an episode of the Adapt podcast—but I was never able to get it to work. Everything came together, though, when I found this YouTube video explaining how to install ffmpeg in a-Shell. That was the missing piece in my previous attempts. I highly recommend watching the video, but I’m going to list the steps below. Once ffmpeg has been installed, youtube-dl works great in a-Shell on the iPad.

  1. Install a-Shell.
  2. Run the command pip install youtube-dl to install the youtube-dl package.
  3. Download ffmpeg from this GitHub page. Follow that link, scroll down to the bottom section, and click the link for ffmpeg. Or, you can click here to download it directly on your iPad. This will put it in your default downloads folder, which, in my case, is the Downloads folder in iCloud Drive.
  4. In the Files app, navigate to the On My iPad section and select the a-Shell folder. In that folder, create a folder called bin.
  5. Move the ffmpeg.wasm file from the Downloads folder into the bin folder. Now that it’s inside of a-Shell’s folder, the app can call on that program when it runs youtube-dl.
  6. Start using youtube-dl!
screenshot of the bin folder in the Files app

The simplest thing to do is to type the command youtube-dl <link to YouTube video>. That will create a video file, in that bin folder on your iPad, of the online video. Be warned, however, that by default youtube-dl will generate a .mkv video file, which is unplayable on the iPad without installing another app or converting it. I recommend telling a-Shell to download the best .mp4 version of a video by inserting -f '(mp4)' just before the video link. Give this one a try: youtube-dl -f '(mp4)' https://youtu.be/tEvXVJHTQAk

For more information on what you can do with youtube-dl, read this page. I didn’t realize there was so much I could do with youtube-dl, and I’m glad to know that I can download only the audio, if that’s all I really want.

All in all, I’m quite happy with this setup. I no longer have to use my Mac to download videos reliably and then transfer those files to my iPad. Everything can now be done directly on iPad, which is fantastic.

(Update 2020-12-01): If the a-Shell folder doesn’t appear in the On My iPad section of the Files app, try issuing the following commands back-to-back:

  1. cd ~/Documents
  2. mkdir bin

The first command makes sure that you’re in the main a-Shell folder, and the second creates the desired bin subfolder. Doing that should jog the Files app into showing all of this. If you still can’t see this in Files, reboot your iPad.

(Update 2020-12-02): If you saw this post via the link on MacStories and tried Federico’s shortcut, you might be unable to find the downloaded files in the Files app. According to a-Shell’s developer, files saved via the shortcut are saved to a $SHORTCUTS folder, which is invisible in the Files app. In a-Shell, use the command cd $SHORTCUTS to navigate to that folder, and then you can use UNIX commands like ls or mv to see, move, rename, etc. the files in that folder.

Quick Tip: Not-So-Smart Punctuation

I manage several WordPress websites, and I do so using my iPad, which is my primary computer. A little while ago I was debugging a bit of HTML in the WordPress editor, as it wasn’t rendering as expected. I went over every line carefully but could not locate the error. It was starting to get under my skin, and then I stumbled across my mistake: I had turned on Smart Punctuation in the keyboard settings for my iPad. All I had to do was open the Settings app, go to General > Keyboard > Smart Punctuation and toggle that feature off. I frequently turn on Smart Punctuation for other things, but now I know that I have to turn it off when coding for the web.

screenshot of Smart Punctuation toggle in the Settings app

So, if you find yourself coding on iPad and can’t figure out why your seemingly valid code isn’t giving you the intended result, check your Smart Punctuation setting.

Maybe one day I’ll be able to create a shortcut to toggle this setting on and off so that I don’t have to do it manually every time. The next-best thing is a shortcut created by Federico Viticci that allows you to jump straight to various locations within the Settings app. You can download the shortcut on this page; just search for Open Settings to find the right shortcut.