Youtube batch processing – less costly requests

The need:

YouTube is a very popular video hosting service as everyone knows. And there are many others like me who use this service to host videos. Then when needed these videos are searched based on user request and different levels of information are displayed. While this seems to be a trivial task and yes YouTube has a very nice API with all the functionality needed right there, and the documentation is really very comprehensive. On a side note I have always been such a big fan of Google APIs.

Anyways, so as I was saying these requests if made regularly can be really very costly. Imagine 10 videos being displayed on a page on xyz website and 10 requests are being made, each to fetch the details of every video, details such as title, tags, date, etc. And imagine that page receives 10 hits every second, which would mean 10 x 10 = 100 requests to YouTube being made every second. Lets consider for a moment that there is no caching mechanism being used, what to do now?

YouTube API comes to the rescue yet again! The API has a nice little feature known as batch processing, which allows you to send multiple different queries in one single request to the API. To quote the API “The YouTube Data API supports batch processing, enabling you to execute up to 50 operations with a single API request rather than submit a separate request for each individual operation”. So the above problem can be very easily solved using batch processing. You can ask YouTube to send you information about all the 10 videos in one single request.

Implementation:

I have written a nifty piece of code in PHP (my favorite language) that accepts YouTube video URLs as parameter and then queries YouTube using curl. The response is then parsed and converted into objects, an object corresponding to each video, with all the video information that you need.

You can download the code from here.

You may also want to have a look here.

Ovais is a storage architect with keen focus on reliability, efficiency and performance of OLTP databases, more specifically MySQL. He currently works at Uber on ensuring storage reliability and scalability. Previously, he helped different web properties scale their MySQL infrastructure. He also worked at Percona as a Senior MySQL consultant and at a few other startups in various capacities.

  • Nice work! =)

  • Nice work! =)

  • Thanks,.

  • Thanks,.

  • LfmjLb numocgstzrrq, [url=http://wraasplttaky.com/]wraasplttaky[/url], [link=http://qccmwqupiphq.com/]qccmwqupiphq[/link], http://fmlubtxqzcro.com/

  • LfmjLb numocgstzrrq, [url=http://wraasplttaky.com/]wraasplttaky[/url], [link=http://qccmwqupiphq.com/]qccmwqupiphq[/link], http://fmlubtxqzcro.com/

  • eKJfp3 vxxshzydrymj, [url=http://widztnfaoylb.com/]widztnfaoylb[/url], [link=http://rzuqxgcnhsvz.com/]rzuqxgcnhsvz[/link], http://mvotuifacypp.com/

  • eKJfp3 vxxshzydrymj, [url=http://widztnfaoylb.com/]widztnfaoylb[/url], [link=http://rzuqxgcnhsvz.com/]rzuqxgcnhsvz[/link], http://mvotuifacypp.com/

  • Great information! I’ve been looking for something like this for a while now. Thanks!

  • Great information! I’ve been looking for something like this for a while now. Thanks!

  • What a great resource!

  • What a great resource!

  • Great post.

  • Great post.

  • Grande borne! Agradecimentos para tomar o momento de escrever algo que é realmente leitura do valor. Demasiado frequentemente eu encontro a informação inútil e não a algo que é realmente relevante. Agradecimentos para seu trabalho duro.

  • Grande borne! Agradecimentos para tomar o momento de escrever algo que é realmente leitura do valor. Demasiado frequentemente eu encontro a informação inútil e não a algo que é realmente relevante. Agradecimentos para seu trabalho duro.

  • I was just talking with my friend about this today at dinner . Don’t know how we got on the topic actually , they brought it up. I do recall having a amazing chicken salad with cranberries on it. I digress…

  • I was just talking with my friend about this today at dinner . Don’t know how we got on the topic actually , they brought it up. I do recall having a amazing chicken salad with cranberries on it. I digress…

  • found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

  • found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

  • That was a different thought track. I admire your finesse that you put into your post . Please do move forward with more similar to this.

  • That was a different thought track. I admire your finesse that you put into your post . Please do move forward with more similar to this.

  • Glad to see that this site works well on my Droid , everything I want to do is functional. Thanks for keeping it up to date with the latest.

  • Glad to see that this site works well on my Droid , everything I want to do is functional. Thanks for keeping it up to date with the latest.

  • Your blog is so informative … ..I just bookmarked you….keep up the good work!!!!

  • Your blog is so informative … ..I just bookmarked you….keep up the good work!!!!

  • Email Privacy

    Can batch processing return json or just xml?
    In any case, I have tried and failed via &alt=json

  • I havent tested it out for json., will test and let you know,.

  • Shravan

    m looking for the same in dot net.. ny idea???

  • Great work and great class. I want to add to the POST request the yt dev key, in order to be more reliable to youtube via the requests.
    I wonder where in the request it should be added?
    Thanks

  • Great work and great class. I want to add to the POST request the yt dev key, in order to be more reliable to youtube via the requests.
    I wonder where in the request it should be added?
    Thanks

  • For beginners, they can subscribe and utilize the free hosting services that can be seen almost everywhere online. Video hosting may cost a bit, but you get better results that will benefit your business especially for search engine optimization purposes.

  • Oakley vault

    The eyewear brand companies Oakley vault sunglasses mainly for women with a couple of designs in the actual mens category. Known because of its colorful and unique sets, Oakley vault are easily recognizable using the embossed logo on the actual temples. The exquisite design is from the frames range from Oakley sunglasses outlet to classic aviator tones, with pastel and earthy colored lenses. The variety of colors the brand offers could be compared with the mood from the Cheap Oakley vault.

  • Ray Ban Sunglasses

    Ray Ban
    UK
    have produced its initial appearance about 80years
    in the past and become a hitting item inside the market speedily. These
    Ray Ban
    Sunglasses
    are committed to blocking glares and
    several other dangerous rays. Due to their distinctive traits and effectiveness
    in filtering dangerous rays, raybanuk2012.net
    grows to be widely accepted and famous all over the globe.

     

  • gerhard

    the code is down, it would be really helpful for me to have a look at it 🙂
    thanks

  • Thank you for pointing that out.
    I moved the code over to github and I have updated the link in this post. Here is the github link: https://github.com/ovaistariq/youtube-batch-processing

  • jezjones

    Helpful script, but it looks like YouTube has turned off version 2 of the API so your script needs updating.