Welcome to the Pythonista Community Forums!

Pythonista is a Python programming environment for iOS. To learn more, head over to the Pythonista Website.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter
Youtube Downloader
  • Disclaimer: This works in combination with a (free) third-party App Store app.

    The code is here:

    http://gist.github.com/4704121

    Using the gist downloader or manually saving it into Pythonista, it should be named 'YoutubeDL' when looking at your list of scripts in the Pythonista interface.

    In the comments, you'll notice a bookmarklet:

    javascript:window.location='pythonista://YoutubeDL?action=run&argv='+encodeURIComponent(document.location.href);


    In Mobile Safari, create a Bookmark for any page and name it something meaningful to you (mine is named: "--- m.Youtube DL"). Then go into Bookmark Edit mode and change the URL to the javascript listed above.

    The app that this script works in combination with is called 'iDownloads PLUS - Download Manager!', free, from Amad Marwat, in the iOS app store.

    How to use the script:

    Browse to http://m.youtube.com in Mobile Safari, view a video that you like (press Stop if it starts playing, you need to be looking at the page - not the video actually playing), then click on "Bookmarks" and select the bookmarklet that you created.

    This will launch my script, which will pull the URL of the page you were looking at as an argument, parse it, figure out the direct download URL for the .mp4 video file, then open iDownloads directly to that URL to start downloading it.

    I picked iDownloads because it's free, can download in the background (up to 10 minutes, with notifications when complete), can download multiple files, can play the .mp4 files directly, has HTTP sharing and iTunes documents capabilities (for getting the video to a computer), can save .mp4 files to your Photo roll, and also has 'Open In...' capabilities to move them to another app.

    When the download opens in iDownloads, it'll prompt with a few options - I usually choose 'Download As' and then give it a whatever.mp4 video file name.

    There's some tweaks, if you look at the source code of the script, where you can change what your preferred default download type / quality is (flv, mp4, webm, 720p, 480p, etc.).

    Why I wrote this:

    Apple has continued to crack down on App Store authors that make video download utilities and disallow submission / updates for apps that provide the ability to download content from YouTube and save it to your device. Every app that ever offered this feature (free or paid for) has always eventually removed it claiming 'compliance with YouTube Terms of Service', but it's always been Apple twisting the wrist.

    With this bit of code, in theory you could use any app in the App Store as long as it provided a custom URL opener (in this case 'iDownloads://') and took web URLs and offered to download them if they were not web pages. This script should be 'future proof' against Apple :)

    I use it in combination with a few other tools that I have so that, without accessing a computer, in my house I can download a YouTube video and then save it to a Samba / SMB file share on the network - making it instantly available to my TVs (WiiMC and XBMC on an AppleTV). Makes it a breeze to download stuff for my 3 year old without having to find the laptop.
  • Tried to test it and it didn't work for me. I double checked the URL for the JavaScript and it's correct. http://i.imgur.com/N5xzODd.png
  • It' did not work for me too. When the bookmark open pythonista at my iphone, pythonista wrote that the YoutubeDL.py has invalid syntax. Can you help me?
  • Not working...getting the same error as others...
  • Remove the .py
  • Removing the .py worked! Thanks jmk. Not sure why the autor of this post was unable to provide the correct info?
  • Works fine! Thanks for creating the script, without .py ;-)
  • For all that were having problem with my script, I see there was a misunderstanding in my original instructions about this particular bit:

    Using the gist downloader or manually saving it into Pythonista, it should be named 'YoutubeDL.py'

    Every file listed in the Pythonista script list already has a '.py' suffix (behind the scenes), Pythonista just hides the suffix. I forget that many people new to python / Pythonista don't realize this, as I come to Pythonista from coding python in general on many different OSes. It wasn't a comment saying "When looking at your list of scripts in Pythonista, make sure it says 'YoutubeDL.py' ...". I was just trying to make sure you named it "YoutubeDL" - and just thought everyone understood the ".py" was a given.

    Please forgive me for the confusion I've caused, it was a poor choice of comment on my part. I've edited the original for more clarity.

    Also - are people using the current gist downloader(s) seeing the script appear in Pythonista with '.py' in the file name? Or were they following my poorly worded instructions and re-naming the file to include the '.py' ?

  • Is there anyway to only download the audio of the video? Or strip the audio from the mp4?
  • It's pretty clear from youtube's terms of service (http://www.youtube.com/static?gl=GB&template=terms) that this is not allowed
  • @DKatri - Not with my tool. I'm only downloading the media as offered up by YouTube. I'm not manipulating the media files, so I can't offer you a method for extracting the audio component of video+audio streams.
  • Works great with GoodReader, as noted by Dalorbi in this article: http://www.macstories.net/links/ios-youtube-downloader-with-pythonista/

    Seems to download QUICKER than actually trying to watch it in YouTube. lol