Jump to content

youtube integration


diabloroker

Recommended Posts

A friend of mine coded this but it suddenly stopped working.

 

After placing the youtube URL into the field, it displays the error, "The video details cannot be retrieved.". We like that the error detection works but why did it break?

 

<?php
include('application.php');
if ($myID == 0) goto('login.php');
_v('e;i:eid');

if ($mode == 'e')
{
$main .= "<center><br><br>
      The video cannot be found. <br> <br> <br>
      <input type='button' name='b1' class='bttn' value='< Go Back' onclick=\"location.replace('myvideos.php');\">
    </center>";
}

if ($mode == 'delete')
{
$qc = mysql_query("SELECT * FROM `video` WHERE `vid_id` = '$eid' AND `vid_useid` = '$myID'");
if (mysql_num_rows($qc) == 0) goto('myvideos.php');
$rc = mysql_fetch_assoc($qc);
extract($rc);
if ($vid_thumb != '') @unlink("$base_path/photo/video/$vid_thumb");
$qd = mysql_query("DELETE FROM `video` WHERE `vid_id` = '$eid' AND `vid_useid` = '$myID' LIMIT 1");
goto('myvideos.php');
}

// Add From Youtube

if ($mode == 'addys')
{
_v('ttl,dsc,ytc,tags,thumb,v__id,catid');
$now = date('Y-m-d H:i:s');
$url = gen_url($ttl, 60, 'video', 'vid_url');
$fname = '';

if ($m_ytc != '') $hcode = $m_ytc;
else $hcode = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/'.$v__id.'&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$v__id.'&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
$tags = make_tags($tags, ' ');

$qins = mysql_query("INSERT INTO `video`
     (`vid_useid`, `vid_catid`, `vid_title`, `vid_url`, `vid_desc`, `vid_code`, `vid_date`, `vid_enabled`, `vid_tags`, `vid_thumb`) VALUES 
     ('$myID', '$catid', '$m_ttl', '$url', '$m_dsc', '$hcode', '$now', '1', '$tags', '$fname')") or die(mysql_error());
$last = mysql_insert_id();

$yfile = "http://i2.ytimg.com/vi/$v__id/default.jpg";
$fname = 'vt'.$last.'.'.'jpg';
$thumb = new thumb($yfile, 'jpg', "photo/video/$fname");
$thumb -> fixed(120, 90);
if (!file_exists("photo/video/$fname")) $fname = '';
$qupd = mysql_query("UPDATE `video` SET `vid_thumb` = '$fname' WHERE `vid_id` = '$last'");
goto('myvideos.php');
}

if ($mode == 'adda')
{
_v('vurl');
$info = get_youtube_info($vurl);
if ($info['error'] != '') { $mode = 'addy';  $e = 1; }
else
{
	extract($info);
	$cj = new jsValid('frmab');
	$cj->addf('ttl,catid');
	$js = $cj->show(1, 0);
	$main .= "<form action='myvideos.php' method='post' name='frmab' id='frmab' style='margin:0px' enctype='multipart/form-data'><input type='hidden' name='mode' value='addys'><input type='hidden' name='thumb' value='$thumb'><input type='hidden' name='v__id' value='$v__id'>
         <table border='0' cellspacing='2' cellpadding='3' align='center' width='400'>
          <tr><td><b>Title</b>:<br><input type='text' name='ttl' value=\"$title\" class='input' style='width:340px'></td></tr>
          <tr><td><br><b>Category</b>:<br>".sel_db('catid', 'category', 'cat_id', 'cat_name', "`cat_type` = 'videos'", '', '- Select -', 'input', '', '238')."</td></tr>
          <tr><td><b>Description</b>:<br><textarea name='dsc' class='input' style='width:340px;height:100px'>$desc</textarea></td></tr>
          <tr><td><b>Tags</b>: <br><input type='text' name='tags' value=\"$tags\" class='input' style='width:340px'></td></tr>
          <tr><td align='center'><br><input type='submit' name='sub' class='bttn' value='Add Video'>     <input type='button' name='cnc' class='bttn' value='Cancel' onclick=\"location.replace('myvideos.php');\"></td></tr>
         </table></form>$js";
}
}

if ($mode == 'edits')
{
_v('ttl,catid,dsc,tags');
$tags = make_tags($m_tags, ' ');
$qupd = mysql_query("UPDATE `video` SET `vid_catid` = '$m_catid', `vid_title` = '$m_ttl', `vid_desc` = '$m_dsc', `vid_tags` = '$tags' WHERE `vid_id` = '$eid' AND `vid_useid` = '$myID'");
goto("$base_url/myvideos.php");
}

if ($mode == 'edit')
{
$qv = mysql_query("SELECT * FROM `video` WHERE `vid_id` = '$eid' AND `vid_useid` = '$myID'");
if (mysql_num_rows($qv) == 0) goto("$base_url/myvideos.php");
$rv = mysql_fetch_assoc($qv);
extract($rv);
$tags = unmake_tags($vid_tags, ',');

$cj = new jsValid('frmab');
$cj->addf('ttl,catid');
$js = $cj->show(1, 0);
$main .= tab('Edit Video', 600);
$main .= "<form action='myvideos.php' method='post' name='frmab' id='frmab' style='margin:0px' enctype='multipart/form-data'><input type='hidden' name='mode' value='edits'><input type='hidden' name='eid' value='$eid'>
       <table border='0' cellspacing='2' cellpadding='3' align='center' width='400'>
        <tr><td><b>Title</b>:<br><input type='text' name='ttl' value=\"$vid_title\" class='input' style='width:340px'></td></tr>
        <tr><td><br><b>Category</b>:<br>".sel_db('catid', 'category', 'cat_id', 'cat_name', "`cat_type` = 'videos'", $vid_catid, '', 'input', '', '238')."</td></tr>
        <tr><td><b><br>Description</b>:<br><textarea name='dsc' class='input' style='width:340px;height:100px'>$vid_desc</textarea></td></tr>
        <tr><td><b>Tags</b>: <br><input type='text' name='tags' value=\"$tags\" class='input' style='width:340px'></td></tr>
        <tr><td align='center'><br><input type='submit' name='sub' class='bttn' value='Update'>     <input type='button' name='cnc' class='bttn' value='Cancel' onclick=\"location.replace('myvideos.php');\"></td></tr>
       </table></form>$js";
$main .= tabe();
}


if ($mode == 'addy')
{
$main = "
     <form action='myvideos.php' method='post' name='frmab' id='frmab' style='margin:0px' enctype='multipart/form-data'>
     <input type='hidden' name='mode' value='adda'>
     <center><br>
     Please enter the YOUTUBE URL of the video <br>
     <i>eq: http://www.youtube.com/watch?v=B5i3mQhtNtg</i><br><br>
       <input type='text' name='vurl' class='input' style='width:300px'><br><br>
       <input type='submit' name='sub' class='bttn' value='Continue >'>    
       <input type='button' name='cnc' class='bttn' value='Cancel' onclick=\"location.replace('myvideos.php')\">
   </center>";
if ($e == 1) $main .= "<center><font color='red'>The video details cannot be retrieved.</font>";
}


if ($mode == '')
{
$main .= tab2('My Videos', "<input type='button' name='b1' class='bttn' value='Add Youtube Video' onclick=\"location.replace('$base_url/myvideos.php?mode=addy');\">", 650);
$main .= "<div style='margin:10px'>";
$qe = mysql_query("SELECT * FROM `video` WHERE `vid_useid` = '$myID' ORDER BY `vid_id` DESC");
if (mysql_num_rows($qe) == 0) $main .= "<center><br>You have not added any videos yet.</center>";
else
{
	$main .= "<table border='0' cellspacing='4' cellpadding='3' width='600' align='center'>";
	while ($re = mysql_fetch_assoc($qe))
	{
		extract($re);
		$thumb = ' ';
		if ($vid_thumb != '') $thumb = "<img src='photo/video/$vid_thumb' border='0'>";
		$vid_desc = mktext($vid_desc, 250);
		$vlink = URL::video($vid_id, $vid_url);
		$main .= "
             <tr>
              <td width='140' valign='top'><a href='$vlink'>$thumb</a></td>
              <td width='460' valign='top'>
                <a class='evtt' href='$vlink'>$vid_title</a>
                <div style='margin-top:5px;line-height:17px'>$vid_desc</div>
                <div style='margin-top:3px;color:#555555;line-height:19px'>
                     <a href='myvideos.php?mode=edit&eid=$vid_id'>Edit Video</a>  
                     <a href='#' onclick=\"if (confirm('Are you sure you want to delete this video?')==true) location.replace('myvideos.php?mode=delete&eid=$vid_id');\">Delete Video</a></div>
              </td>
             </tr><tr><td colspan='2'><div style='border-top:1px solid #C7C7C7;height:2px;margin-top:4px;'> </div></td></tr>";
	}
	$main .= "</table>";
}
$main .= "<center><br><br>
       <input type='button' name='b1' class='bttn' value='Add Youtube Video' onclick=\"location.replace('$base_url/myvideos.php?mode=addy');\">            
     </center></div>";
$main .= tabe();
$main .= "<div style='line-height:19px;margin-left:20px;margin-bottom:20px'>Easily import your favorite YouTube videos and share them with members. No uploading required. <br /> <a href='".URL::page('faq')."'>Support</a> </div>";
}

$_vtemplate['main'] = $main;
$_vtemplate['right'] = $right;
$tp = new page($_vtemplate, 'template/default2.html');

Link to comment
Share on other sites

Your error reporting lacks the correct error reporting, ironically. "Cannot be retrieved.." is not helpful. Debug your code, add checks on every bit of the code, ESPECIALLY seeing if the video path EXISTS, as youtube, bans certain hosts and changes its locations/videos at will. It's most likely some simple parsing problem though..

Link to comment
Share on other sites

Is the "The video details cannot be retrieved." from Youtube or your code? If it's from your code then. 1) Find the error, and WHY it was triggered. 2) work your code/logic around it. If you can't, find then do the same with your other functions. It doesn't look that hard to solve.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.