Creating Youtube Downloader for iPad/iOS
I use my iPad Air M1 mainly for reading books, consuming RSS feed, watching Youtube & not so often for making hand written notes. When I’m carrying it away from home & don’t have access to Wifi I need to have content downloaded offline.
Books are my first choice regardless of Internet accessibility so I always have some books downloaded in iBooks app. I also keep certain course material loaded into iPad but if I want to switch between preferences I might watch Youtube Videos instead, such as insightful biographical briefings of the Pious Saints of Islam.
Normally, I download the YouTube videos on my Mac using yt-dlp and then Airdrop them onto my iPad for offline watching. This process is nearly frictionless for me since my Mac is my primary computing device. I could achieve that on my iPad if only there was an UNIX emulator app for iPad. Okay I found one:
I came across this a-shell app lately which is a complete local terminal emulator, allowing to run most Unix commands on iPad / iOS devices. It has Python, Lua, JS, C, C++, TeX, sh and all Unix utilities installed by default making it an ideal app for CLI oriented workflow & our utility – yt-dlp.
For a-shell comes with both pip (package manager) and curl installed so we can install yt-dlp using two different methods. yt-dlp is the fork of youtube-dl which is a free & open source download manager utility for Youtube & over 1000 other video hosting websites.
With pip (Recommended)
You can install yt-dlp PyPI package with:
python3 -m pip install -U yt-dlp
If you want to install with curl run:
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o yt-dlp
Now that we have everything setup, we can start downloading our first Youtube video. Launch the a-shell and run the following command to download this Dopamine Detox video from Youtube.
yt-dlp -f mp4 https://www.youtube.com/watch?v=yvoxRMRRKmI&pp=ygUIYXBlcnR1cmU%3D -o "dopamine-detox.mp4"
If you installed the yt-dlp with curl then prefix the aforementioned command with
python3. The video will be downloaded in the Files app in the section On My iPad > a-Shell.
To download a video in 1080p, you can use the following command:
yt-dlp -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' [video URL]
To download the best video with the best audio, you can use the following command:
yt-dlp -f bestvideo+bestaudio [video URL]
It will download the video in best quality possible.
I personally don’t download any YT video as audio for offline listening, but in case you want to here is how you can extract the audio from any YT video.
yt-dlp -f m4a https://www.youtube.com/watch?v=dRiLOA1Y2Q8 -o remove-the-darkness.m4a
Again, it’ll download and the audio be available on the iPad in the “a-Shell” folder as m4a, which is well supported format by iPad / iOS.
If you want to download as mp3 run:
yt-dlp -x --audio-format mp3 [video URL] -o file-name.mp3
To extract the best audio quality, you can use:
yt-dlp -x --audio-format mp3 --audio-quality 0 [video URL]
Replace [video URL] with the URL of the video you want to download the audio from. The –audio-quality 0 option tells yt-dlp to download the best audio quality available. This will ensure that you get the highest possible audio quality in your MP3 file.
To download a playlist in mp4 format and 1080p resolution using yt-dlp, run:
yt-dlp -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' --merge-output-format mp4 [playlist URL]
If you want to extract the playlist as audio in mp3 format use the following command:
yt-dlp -x --audio-format mp3 [playlist URL]
This is the easiest and cleanest way on the iPad to download YouTube videos in the desired format for offline use. Depending on your familiarity with yt-dlp, you can do much more with this setup than what has been explained here. Remember that yt-dlp supports over 1000 video hosting sites, so use this post as a starting point to further explore this command line utility.
Reply via mail