Youtube Scraper

Another scraper, this time for Youtube:

USAGE:

1
<?php youtube("BMW") ?>

CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function youtube($keyword) {
	$url = 'http://www.youtube.com/rss/tag/'.urlencode($keyword).'.rss';
	$youtube = fopen($url, "r");
	if (preg_match('/<enclosure url=\"(.*)swf/s', $youtube, $y)) {
		$youtube = $y[1];
		$youtube = substr($y[1], 0, 36);
		$video = '';
		$video .= "\n".'<object type="application/x-shockwave-flash" style="width:400px; height:325px;" data="'.$youtube.'">';
    	$video .= "\n".'<param name="movie" value="'.$youtube.'" />';
    	$video .= "\n".'</object>';
    	$video .= "\n";
    	print $video;
	}
}
?>

8 Responses to “Youtube Scraper”


  1. 1 Nils

    uhm.. doesn’t work for me..
    I get a blank page..

  2. 2 busin3ss

    uhm.. doesn’t work for me..
    I get a blank page..

    Nils you are right, I was missing this line:
    $youtube = fopen($url, “r”);
    I just updated the code with the fix.

  3. 3 Jagged55

    Thanks for the code…I am anxious to use it!

    Is this code working correctly? I am getting a blank page and
    am not sure if it is an error that I made or if the code still
    needs more updating.

    There is a very good chance that I messed up so forgive me if
    it is my fault :)

  4. 4 ShinZaiaku

    Warning: preg_match() expects parameter 2 to be string, resource given in /home/public_html/004/youtube.php on line 5

    I’m getting this error.

  5. 5 Arpit

    I don’t have any idea of how to use this script. Can you please give us some detailed instruction for doing it? I have messaged you on Digital point forum about this. Please guide me.

  6. 6 busin3ss

    I don’t have any idea of how to use this script. Can you please give us some detailed instruction for doing it? I have messaged you on Digital point forum about this. Please guide me.

    It’s actually really easy, just copy the code and save it on a file (youtube.php for example). Then wherever you want to insert a Youtube video related to a keyword, just add this:

    require_once(’youtube.php’); // assuming your file is called youtube.php

    And then just wherever you want to see the video add this:

    youtube(’bmw’); // this will include a youtube video about BWM

  7. 7 Arpit

    Will this make my blog automated? Or should I have to add any cronjob or something to control the frequency of updating my blog?

  8. 8 Zaiaku

    No it wont post automatically but will give your site or page dynamic content.

Leave a Reply

Quote selected text