WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
Yeni Setiawan
Date : Jun 21st 2007
Grade : 4 of 5 (graded 13 times)
Viewed : 28379
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Yeni Setiawan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

The usage is so easy, I already use it on my running website: http://mobi.web.id/youtube/

<?php
// first function, read HTML from youtube
function get_content_of_url($url){
   
$ohyeah = curl_init();
   
curl_setopt($ohyeah, CURLOPT_RETURNTRANSFER, 1);
   
curl_setopt($ohyeah, CURLOPT_URL, $url);
   
$data = curl_exec($ohyeah);
   
curl_close($ohyeah);
    return
$data;
}

// second function, get path that lead into movie files
function get_flv_link($string) {
        if (
preg_match('/\/player2\.swf\?(.*)", "movie_player"/', $string, $match)) {
           
$url = $match[1];
            return
'http://youtube.com/get_video.php?'.$url;
        }
}

// third function, read header returned by second function above
function get_http_header($url){
   
$uh = curl_init();
   
curl_setopt($uh, CURLOPT_URL, $url);
   
curl_setopt($uh, CURLOPT_HEADER, 1);
   
curl_setopt($uh, CURLOPT_RETURNTRANSFER, 1);
   
$res = curl_exec($uh);
   
curl_close($uh);
    return
$res;
}

// fourth function, parse the header and show only the link
function show_url($http_header){
   
$arai = explode("\n",$http_header);
    foreach(
$arai as $ini){
        if(
eregi("location",$ini)) $url = $ini;
    }
    list(
$sampah,$hasil) = explode("Location:",$url);
    return
str_replace("\n","",trim($hasil));
}

// fifth function, join the four functions above
function download_youtube($url){
   
$data = get_content_of_url($url);
   
$next_url = get_flv_link($data);
   
$data = get_http_header($next_url);
    return
show_url($data);
}
?>


Usage Example
<?php
error_reporting
(0); // <-- to eliminate error report
ini_set("max_execution_time",0); // <-- to avoid operation timed out
echo download_youtube("http://youtube.com/watch?v=O-Tt229laCE");
?>



How to strip non-alpha characters from a string
Categories : Regexps, PHP
Using data from a string.
Categories : PHP, Strings, CURL
PHP Domain Availability Checker
Categories : PHP, Complete Programs, Regexps, HTTP, Sockets
Clever Email Validation Function - E-Mail validation function with an eregi expression and socket connection.
Categories : Email, PHP, Regexps
Form input return conformance
Categories : HTML and PHP, PHP, Regexps
A function to check if a URL exists
Categories : PHP, CURL, HTTP
Returns Yahoo! Address Book and Messenger List as an Array
Categories : PHP, PHP Classes, CURL
Making sure a string containes only digits or no digits.
Categories : Strings, PHP, Regexps
Ping a Server and run a command to fix it if it is down
Categories : PHP, Errors and Logging, Regexps
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
How to check if a file is of type gif or jpg?
Categories : PHP, Regexps, Graphics
Parse html (title :: meta)
Categories : PHP, HTML and PHP, Regexps
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
curl_close -- Close a CURL session
Categories : PHP, PHP Functions, CURL
 Roberto Inetti wrote :1754
can you help me.
doesn't work for me