Jump to content

Video Embed Code Extractor- Help! It's not working like it should....


musicmasteria

Recommended Posts

Note: If someone already has a working version of this script PLEASE direct me to it. I couldn't find one anywhere...

 

Hello anyone! Please help a newbie coder figure out what's going on here...

 

My script first needs the following url parameter to be set: http://script-url-here.com?s=http://url-of-site-to-be-checked-here.com

 

$url = "http://url-of-site-to-be-checked-here.com";

 

Next it reads the entire contents of that url and puts it in a variable

 

$content = file_get_contents($url);

 

After that it finds the total number of '<embed' and '<object' in $content and then uses while loops to find the positions and writes everything out. (see the code below)

 

Here is the entire script:

-It's not working right

-Some kind of infinite loop?

-Complains about line 53 (strpos() Offset not contained in string)

---The error on 53 is probably what is causing it all. I was trying to

<html>
<head><title>Video Embed Code Extractor</title></head>
<body>
<div id='wrapper'>
<?php
$url = $_GET["s"];
if (isset($url)){ //This wraps around the whole code

//A little if statement to add a 'http://' to the url if it is not already there
$urlpos = strpos($url,'http://');
if ($urlpos === false) {
$url= 'http://'.$url;
}else{
// do nothing
}




echo 'The Url You Submitted: '.$url.'<br/>';
// Get url contents
$content = file_get_contents($url);

//Set strings to be searched for later
$embed_begin='<embed';
$embed_end='>';
$object_begin='<object';
$object_end='object>';

// Finds the number of Embed and Object Codes and the total number
$embed_count=substr_count($content,$embed_begin);
$object_count=substr_count($content,$object_begin);
$total_items=$embed_count+$object_count;

If ($total_items==0){
die('Sorry, No Videos found... ');
}else{
?>
You are in luck! We found: <?php if($total_items>1){echo $total_items.' Videos';}else{echo $total_items.' Video';}?><br/>
<?php
//if elseif and else combo to deside what to display
if($embed_count==0){
echo $object_count.' Object Video(s)<br/><br/>';
}elseif($object_count==0){
echo $embed_count.' Embed Video(s)<br/><br/>';
}else{
echo $embed_count.' Embed Video(s) and '.$object_count.' Object Video(s)<br/><br/>';
}
}

// The search for embeds
$embedpos_0=0;
$count1=1;

while (($count1 <= $embed_count)&& ($count1 < 5)) {  // the ($count1 < 5) part was because I kept getting infinite loops...
$embedpos_.$count1 = strpos($content, $embed_begin, $embedpos_.($count1-1));
$embedendpos_.$count1 = strpos($content, $embed_end, $embedpos_.$count1); 
$embedoutput_.$count1 = substr($content, $embedpos_.$count1, ($embedendpos_.$count1-$embedpos_.$count1));
$embedhtml_.$count1 = str_replace("<","<",$embedoutput_.$count1);
$count1++;
echo $count1;
echo $embed_count.' ';
}


// The search for objects
$objectpos_0 = 0;
$count2 = 1;

while (($count2 <= $object_count)&& ($count2 < 5)) {
$objectpos_.$count2 = strpos($content, $object_begin, $objectpos_.($count2-1));
$objectendpos_.$count2 = strpos($content, $object_end, $objectpos_.$count2);
$objectoutput_.$count2 = substr($content, $objectpos_.$count2, ($objectendpos_.$count2-$objectpos_.$count2));
$objecthtml_.$count2 = str_replace("<","<",$objectoutput_.$count2);
$count2++;;
}

/////Begin the writing process

//Embeds First
$count3 = 1;

while (($count3 <= $embed_count)&& ($count3 < 5)) {
?>
<br/><br/>
<form>
<input type="text" size="35" value="<?php echo $embedhtml_.$count3; echo $embed_end; ?>" onClick='highlight(this)'; readonly>
</form>
<br/><br/>
<?php
$count3++;;
}

//Objects Next
$count4 = 1;

while (($count4 <= $object_count)&& ($count4 < 5)) {
echo $objectoutput_.$count4.'>';
?>
<br/><br/>
<form>
<input type="text" size="35" value="<?php echo $objecthtml_.$count4; echo $object_end; ?>" onClick='highlight(this)'; readonly>
</form>
<br/><br/>
<?php

$count4++;
}

?>
<script language="JavaScript">
function highlight(field) {
       field.focus();
       field.select();
}</script>
<?php
}else{ //Ending the isset($url)
die('Please set the url ?s=*entire-url-here*');
}
echo '<br/>';        // Me trying to debug stuff here...
echo $embed_begin.'-1-<br/>';
echo $embed_count.'-2-<br/>';
echo $object_count.'-3-<br/>';
echo $total_items.'-4-<br/>';

?>
</div>
</body>
</html>

 

Any thoughts?

 

Has someone already done this before and I'm waisting my time?

 

Thanks for the help in advance!

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.