YouTube Downloader and Feed Parser

So I decided to spend a bit of time over the holidays scratching an itch and writing some PHP code. The result is a new open source project: YouTube Downloader.

Its main purpose, for me, was to enable me to subscribe to a user’s YouTube videos as a podcast, and have the episodes downloaded in Downcast on my iPad. In the process though I also found it useful to make it usable as a form-based script, where you input a video’s ID and get a list of the available formats for download. So, the project does both.

Here’s the form (thanks to Twitter Bootstrap for the look & feel):

downloader

Once you’ve put a video id in the appropriate field and submitted, you’ll get a result that looks something like this:

results

You can right-click and choose “Save link as” (or whatever your browser calls it) to save any of the files. Unfortunately you have to set the filename and extension yourself.

To use it on a feed, take a look at feed_parser.php provided in the download. You can set a few variables at the top – including what feed it is you want to process – and then it will output an XML file which can be consumed in a podcatcher / podcast client.

Once you’ve got it working (outputting correctly to screen), set it to write out to a file in cron – for example:

/usr/bin/php /var/www/html/feed_parser.php > /var/www/html/feed.xml

If you want to manage multiple different feeds just duplicate feed_parser.php and rename it, and make sure to save the output to different filenames. There’s nothing specific about the name feed_parser.php or the output to feed.xml, so you can have many different ones running.

Feel free to use it, fork it on Github, and send me some pull requests!

Did you like this? Share it:
11 Comments. Leave a comment or send a Trackback.
  1. #1 • Kau said on January 3 2013:
     

    This script is not working anymore. It saves me an empty document.

  2. #2 • if3lc said on January 27 2013:
     

    localhost is working,error does not but on the webhost is not working

  3. #3 • John said on February 21 2013:
     

    Not sure why folks are having trouble with it – it continues to work for me.

    I use it in a configuration where it is part of following a youtube user’s feeds and downloading their videos, and use it several times a week successfully.

  4. #4 • James said on February 28 2013:
     

    It doesn’t work.

  5. #5 • John said on February 28 2013:
     

    James – it does work. I use it several times a week.

    Likely configuration issue or difference in how your server is configured versus mine.

    Do you have access to the php error logs on your machine? Can you share any more info about what isn’t working and how you’ve set it up?

  6. #6 • Mark said on April 11 2013:
     

    I get the same issue :
    http://eels.wyrdweb.com/YouTube-Downloader-master/

  7. #7 • Mark said on April 11 2013:
     

    Nevermind. It was because I had to install php5-curl.
    Thanks!

  8. #8 • John said on April 11 2013:
     

    Mark – after you installed php5-curl, did it start working for you?

    I think based on the IPv4 address issue it won’t – see this issue at GitHub:

    https://github.com/jeckman/YouTube-Downloader/issues/1

    Seems that in order for it to work, you have to either:

    A. Be running it locally (client and server on same machine)

    or

    B. Be running IPv6 on the server AND have an IP address in the US (or maybe just have a client IP that is the same region as the server IP)

  9. #9 • John said on April 11 2013:
     

    People for whom the script is not working might want to check out this project, which uses JavaScript to do the parsing on the client side, removing the IP issues:

    https://github.com/edse/keepvideos

  10. #10 • pradeepv said on May 6 2013:
     

    Hi, am able to download the videos in localhost, but am not able to download from my server. when i open the download link it says Access to the webpage was denied. URL: http://demo.pradeep-designer.com/youtube/getvideo.php?videoid=1A7lVzHttRY&debug=on&type=Download. Even “https://github.com/edse/keepvideos” works in localhost not in server. any help?

  11. #11 • John said on May 9 2013:
     

    pradeepv Is your server in a different region than your localhost?

    YouTube may be doing some filtering by region. The keepvideos version uses javascript to do the parsing locally, so I’m not sure why that one would fail.