Your Ad Here

Simple YouTube API Class in PHP: Redeaux — Revision 2 (update)

Just a note: It’s not 100% done yet, still have a few minor tweaks. I’m going to be uploading the final version this Friday. I think there will be one more revision after this one, then we will launch the official first version. Thank you for all of your patient and feedback as we strive to make this the most popular PHP4/5 YouTube API on the internet.

A lot of you have read our post including our YouTube API. I know because it almost gets as much traffic as the post on how to hide everything on your myspace profile.

Now because of it’s popularity you guys have requested a lot of bug fixes and a new release — revision 2. On top of that a lot of you are still using PHP4, I have no idea why, but you are.

I decided to address every individual bug that you guys commented on the post, and address issues that I thought were relevant on top of your findings (which have been extremely helpful.)

This brings me to the NEW and IMPROVED YouTube API Class.

Here’s the current changelog

  • Page numbers are inaccurate, and don’t allow you to go to the last page because of numbering issues
    • This was caused by YouTube displaying x amount of videos per page, and us/you having a different number of results per page, for example compared to YouTube’s 20 results per page. So while there would be 3149 pages, there’s really not that many because you either have MORE videos per page than YouTube does, or you have way less, either way this has been fixed by dividing the total number of videos by the amount of videos you want per page.
  • Spaces in search result in internal error because no URL encoding was present.
    • You guys know the bug, you’d search for “big rocket” or “nice booty” and it would break because the space (%20 in url encoding) wasn’t getting encoded properly. This has been fixed.

There are more bugs that have been fixed, but those two were really most prominent in the sense that, they caused everything else to break.

Here’s the new feature list (these are supplemental features, none of the old functionality is gone, these are just added to it.)

  • Support for PHP4 (yes, that’s right.)
  • Support for curl_init() instead of the user of file_get_contents() (disabled on some shared hosts.)
  • Support for searching by video title (instead of tag.)
  • Support for retrieving video by id
  • Support for “method scaffolding” you can pass multiple things like video_id=this&tag=this&search=this, etc. It will return supplemental results.
  • Support for “naked display” displaying videos in a style-less layout so you can style it on your own.
  • Support for manual methoding. Use the manual_method() to write your own custom call and return the results, or errors, formatted inside of the HTML.
  • Support for “embed_only()” display. So you can create scripts to embed videos.

All of the support is in ONE class file. You don’t download a separate version if you’re using PHP4, or PHP5, it’s all the same thing and it detects it by itself.
…and a lot more.

I will be writing a full blown tutorial on how to get the most out of the YouTube API class on Friday so you guys can get to work, along with a zip and a rar.

I have an idea to allow you to get updates for it dynamically from WaxJelly’s dev server (sort of like a remote SVN.) but through PHP directly. Let me know what you think about that, in other words, you don’t have to patch it, we do it for you and you just turn the boolean on or off. It’s an idea, and a good one I think.

ALSO! We’re going to be putting this thing on DIGG FRIDAY! You guys better help us out and return some love by digging it (if you digg it, of course.) we’re not forcing anybody here, but the more people we get using it the better it’s going to get.

I’m also willing to accept your code and give you credit for it, so I’ll have more info on that this friday.

If you have any ideas boys, post them now, you’ve got 5 days and then I’m releasing this it. Let me know what you think.

59 comments so far

  1. clever July 16, 2007 8:12 pm

    Me parece una buena noticia que el viernes se lanze la version php4 lo estaba esperando desde hace mucho tiempo bueno te dejo un codigo que parese funcionar bien

    http://e.leven.com.ar/u2b/downloads/1.0.zip

  2. Zaiaku July 16, 2007 10:33 pm

    Great job! I’m can’t wait to start modifying it. I have a few personal ideas that I want to try out myself that I’ve been working on.

  3. bryan July 16, 2007 10:44 pm

    Well post them! Come on! That’s the point! Open source! Community!

  4. bryan July 16, 2007 10:45 pm

    Share your ideas.

  5. Zaiaku July 17, 2007 12:44 am

    SE optimized url’s but don’t think many people would care about them much. I hoping that I will still be able to intergrate your script with other forum and cms scripts. A download option would be good especially if it will be able to convert on the fly.

  6. Lars Koudal July 17, 2007 5:04 pm

    I am quite curious to see how this API works out.

    I have a few sites that are already depending on a custom script and setup, but one thing that could be interesting would be to have API calls to check and verify a video is still available.

  7. bryan July 17, 2007 5:49 pm

    Lars,
    I’ll look at putting this into a class method for ya ;)

  8. Zaiaku July 20, 2007 12:45 pm

    OK its friday time to post the script so I can start to get to work on it :)

  9. rob July 20, 2007 2:32 pm

    Friday indeed post that baby

  10. Zaiaku July 20, 2007 8:55 pm

    Now I’m wondering if they forgot. You ever waiting inline for a new gaming console. This is looking like deja vu to me. LOL

  11. rob July 20, 2007 10:46 pm

    yeah I was waiting myself, I thought it would be out by now.

  12. lee July 23, 2007 6:50 am

    Hi.

    It is cool..
    So when will you upload new version?

  13. bahtiyar July 23, 2007 11:04 am

    Hi its good script for youtube galery.i tried make a scripts seo friendly but i didn’t .if you make this script its very usefull ..

  14. Zaiaku July 23, 2007 3:08 pm

    I have a added a few things to make it more SEO friendly. I’m waiting for this new version to come out so I can add it to it, if anything needs to be changed from my original.

  15. rob July 23, 2007 4:55 pm

    I also made some changes to fix some errors but its really useless because the new version fixes them and more, not sure why the owner haven’t responded to us since the 17th but was active in other post on the site.

  16. bryan July 23, 2007 6:05 pm

    hey!

    It’s not as easy as it sounds :) Sorry to miss the deadline, but personal matters have gotten in the way. I’m not duckin’ your comments, just busy that’s all…DSL sucks too so my house is out of internet.

    I’ll keep you posted.

  17. Zaiaku July 23, 2007 9:00 pm

    LOL of course DSL succs. Thanks for letting us know what’s going on.

  18. deif July 25, 2007 6:43 pm

    de donde se descarga?

  19. Adam July 29, 2007 6:46 pm

    Great work on the class. Waiting anxiously for the update! heheheh

  20. Zaiaku July 30, 2007 2:33 am

    Well since I’m almost done setting up a new site, I really wanting to intergrated this script with it. I had a few ideas about intergration with it. I’m sure everyone is understanding personal matters comes first though.

  21. Rob August 6, 2007 3:51 pm

    Any update on this?

  22. Zaiaku August 6, 2007 4:58 pm

    I was wodnering that too. We went way pass the due date.

  23. wesley August 8, 2007 12:11 pm

    I don’t see any support for search by title? (The official api doesn’t even have this)

  24. andrab August 16, 2007 12:26 am

    Lotsa love to you! It IS the missing secret ingredient for your class, right? - that was a hint ;-)

  25. Zaiaku August 16, 2007 2:43 am

    It’s been a while since any word of the new version.

  26. joanilson August 28, 2007 3:41 pm

    I’m still waiting the upload of the new version…

  27. Steve August 29, 2007 9:45 pm

    Great Class! cant wait to start playing with the new version. Have a thanks and a link from my site to yours.

  28. BG September 1, 2007 2:09 am

    Just checking if a new date is set to release the new code? Looking forward to using the new features! thx

  29. basscleff September 10, 2007 8:43 pm

    any updates on this being released?

  30. Romeo Khan September 18, 2007 4:04 am

    I need the coding to display related video in the video player page ajax

    any idea how to add comment system?

    Please help

  31. giggi September 20, 2007 2:48 pm

    friday… which year?

  32. Jason September 25, 2007 10:07 pm

    Fatal error: Cannot use string offset as an array in /home/friend/public_html/videos/youtube.class.php on line 177

    I get errors like this very frequently when loading pages, has this been fixed?

  33. Joe September 26, 2007 1:23 am

    how long before new release

  34. Tommy September 26, 2007 10:25 pm

    Also interested if this has been released yet? Couldn’t locate a download button as in the previous post.

  35. Zaiaku September 27, 2007 2:17 am

    Wow I almost forgot all about this. I wondering what happened to the new version aswell.

  36. pcxd October 7, 2007 3:51 am

    buen reproductor de videos youtube yu mas lo pueden descargar de http://pcxd.com.ar

  37. Hum October 8, 2007 5:45 am

    Hi,
    I am longtime waiting for your new version. Any good news? Please…..

  38. Bryan October 10, 2007 12:05 am

    Hello! Great stuff! I read the first post and look forward to seeing a new version. Second, do you do simple custom jobs for the clueless like myself? I don’t know where to begin.

    Thanks!

    Bryan

  39. janangull October 11, 2007 4:48 am

    where is the link for the new version, will you gona post it here or update the download link on first version page?

  40. siyon October 22, 2007 7:05 am

    Is the new version to use in php4 also released? If yes where is the link to download.
    I got to use the other one on php5 . It is working. But i need in PHP4.Please reply

  41. Seeds For Wealth October 29, 2007 5:58 pm

    Bryan, you’re the real genius behind this YouTube script I found at HotScripts.com (http://www.hotscripts.com/Detailed/74755.html).

    I was wondering if you could take a look at the script and tell me, us, if it gets your stamp of approval: http://ooglester.com/

    I’m not a coder and it makes me nervous using scripts from sources that aren’t yet proven to be trustworthy.

    And because you have the potential for greatness, could you also make a move to create a downloadable script along the same lines as this ooglester character?

    Package it in one simple download. I’d pay money for that. I think you have lighting here! :D

  42. tealpaphatt November 1, 2007 9:47 pm

    ONLINE - DRUGSTORE!
    PRICES of ALL MEDICINES!

    FIND THAT NECESSARY…
    VIAGRA, CIALIS, PHENTERMINE, SOMA… and other pills!

    Welcome please: pills-prices.blogspot.com

    NEW INFORMATION ABOUT PAYDAY LOANS!

    Welcome please: payday-d-loans.blogspot.com

    GOOD LUCK!

  43. bryan November 5, 2007 5:09 pm

    Seeds for Wealth:

    Meshach and I are collaboratively the genius’ behind the YouTube API class.

    I don’t mind, but I’d appreciate a link back to this blog on your software if you did in fact build off of ours.

    Just give credit where credit is due is all we ask.

    “by waxjelly.com” or anything will do, thanks.

  44. Jereme November 6, 2007 1:48 pm

    @bryan

    First let me say thanks so much for this wonderful script. It is AWESOME!!!

    I have been working hard on a site using ooglester’s adaptation. I just wanted to share it with you.

    http://www.ubuntuce.com/uketube/index.php
    http://www.ukulelevideos.com (once forwarding begins)

    I have a link back to this site as well. :)

    Thanks, Jereme
    http://www.TheJesusTV.com

  45. dan November 14, 2007 8:41 am

    Quick dirty fix for the empty result error.

    LOCATE:
    $this->return = file_get_contents(youtube::return_call());

    ADD AFTER:

    $contentword = “length”; //word to look for.
    $contentword = preg_match( “/$contentword/i”, $this->return ); // //locate word lenght from youtube query which is not found if the there are no videos results.

    if($contentword != “”)
    {
    echo “no results”;
    // do a redirect here with or whatever…
    die();
    }
    else {
    //there are results
    }

    IMPORTANT, CHANGE THE “” AND ” …. (this bogs changes them)…
    good luck

  46. wtf November 24, 2007 1:12 am

    4 months and about 24 “fridays” later… is the new version ready yet?

  47. sgrunt November 24, 2007 6:38 pm

    hi Bryan, i’m not a php programmer but i’ve fixed some minor things as ugly photo id number appearing on top of the page, and broken pagination problem (just add the variable pagenumber to the links).

    But i need to solve 2 things:

    1)how to use more than one tag for search (example: italy + food)
    2) how to sort “most recent” results for the my tags. Could you help me writing me via email please?

  48. cally December 2, 2007 2:38 am

    sgrunt
    thanks to you the id is fixed - remove the echo(which is in the class.php)

    please can you say exactly how you did the broken pagination problem.

  49. cally December 2, 2007 11:31 am

    has anyone managed to fix the related video problem

    where the related may be example 8 more pages

    now it just keeps going so you get page 9 of 8 page 10 of 8 etc..

    needs fioxing or search engines will see it as double content and a waste site

  50. Jereme December 3, 2007 2:17 pm

    I have updated my two sites with the new YouTube API!

    I used a different script that is available at http://www.bizzarmedia.com for $5.00. (I am not the developer).

    You can check out my new updated sites below.

    http://www.UkuleleVideos.com
    http://www.LinuxClips.com

    Thanks, Jereme

  51. Films Trailer December 31, 2007 7:04 am

    nice script also…

  52. Jereme December 31, 2007 9:43 am
  53. Ziggy January 3, 2008 11:32 am

    Hi!

    So nobody have the new version? Where it can be downloaded? I’ve integrated it into joomla and seyret (a fantastic video component) but it’s really full of bugs…

  54. mai January 7, 2008 11:15 am

    Hi

    I would like to show the videos just in Thai Languages.
    How can I set the YouTube API.

    Many Thanks
    ma

  55. oetube February 1, 2008 12:17 pm

    can i post here?

  56. Jereme February 3, 2008 11:54 am

    We have just added a new YouTube Downloader Script at http://www.ooglester.com!

    Thanks, Jereme
    http://www.TheFreeTube.com

  57. satsilem April 8, 2008 8:48 am

    is there any link for the new version. Please reaaly nice script but I only can find the v1. And my online server runs on PHP4.

    Thanks in advance

  58. Zaiaku April 8, 2008 5:07 pm

    Wow I’ve been gone for so long finally found the address here again and I missed this. Wow I am so behind right now.

  59. Is a nice script, but i phink you can use more web2.0, like ajax…

    When i make a search, and i go to page 2, i need load the embebed video all time. And, if i have in page 5, and click in a video, when video play, videos page resulto go to page 1 :(

    I use in http://ronaldogoal.com

    P.S-sorry my bad english:)

Leave a comment

Please be polite and on topic. Your e-mail will never be published.