Hi, I'm trying to migrate a youtube script i found here to Youtube API version 2. Everything is kinda ok except for my view.php file
There are certain videos that doesnt have a 3GP or MP4 mobile stream and with that I'm having
Line 29 is
I try to make a conditional statement to check if 3GP/MP4 stream link is available using empty and isset function
both throw an error
with this PHP
throw an error of
Heres the VIEW.PHP
Problem Fix. Thanks
There are certain videos that doesnt have a 3GP or MP4 mobile stream and with that I'm having
HTML Code:
Fatal error: Call to a member function attributes() on a non-object in C:\wamp\www\view.php on line 29
PHP Code:
/* Get 3GP STREAM URL */
/* THIS IS LINE 29 */ $attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];
PHP Code:
if (!empty($media->group->content[1]->attributes())) {
$attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];
} else { echo "";}
PHP Code:
if (isset($media->group->content[1]->attributes())) {
$attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];
} else { echo "";}
HTML Code:
Fatal error: Can't use method return value in write context in C:\wamp\www\view.php on line 29
PHP Code:
if ($media->group->content[1]->attributes() == "") { echo ""; }
else {
$attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];
}
HTML Code:
Fatal error: Call to a member function attributes() on a non-object in C:\wamp\www\view.php on line 29
Heres the VIEW.PHP
PHP Code:
<?php
header("Content-type: text/html; charset=UTF-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
/* Function to parse a video <entry> */
function parseVideoEntry($entry) {
$obj= new stdClass;
/* Get author name and feed URL */
$obj->author = $entry->author->name;
$obj->authorURL = $entry->author->uri;
/* Geet video publish date */
$obj->publish = $entry->published;
/* Get nodes in media: namespace for media information */
$media = $entry->children('http://search.yahoo.com/mrss/');
$obj->title = $media->group->title;
$obj->description = $media->group->description;
/* Get video category */
$attrs = $media->group->category->attributes();
$obj->category = $attrs['label'];
/* Get FLV STREAM URL */
$attrs = $media->group->content[0]->attributes();
$obj->flv = $attrs['url'];
/* Get 3GP STREAM URL */
$attrs = $media->group->content[1]->attributes();
$obj->tgpp = $attrs['url'];
/* Get MP4 STREAM URL */
$attrs = $media->group->content[2]->attributes();
$obj->mp4 = $attrs['url'];
/* Get video thumbnail */
$attrs = $media->group->thumbnail[0]->attributes();
$obj->thumbnailURL = $attrs['url'];
/* Get <yt:duration> node for video length */
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];
/* Get <yt:stats> node for viewer statistics */
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
if ($yt->statistics)
{
$attrs = $yt->statistics->attributes();
$obj->viewCount = $attrs['viewCount'];
}
else
{
$obj->viewCount = 0;
}
//LIKES get <yt:rating> node for number of likes statistics
//$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
if ($yt->rating)
{
$attrs = $yt->rating->attributes();
$obj->numLikes = $attrs['numLikes'];
}
else
{
$obj->numLikes = 0;
}
//DISLIKES get <yt:rating> node for number of dislikes statistics
//$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
if ($yt->rating)
{
$attrs = $yt->rating->attributes();
$obj->numDislikes = $attrs['numDislikes'];
} else
{
$obj->numDislikes = 0;
}
return $obj;
} // close funcion parseVideoEntry
/* Get video ID from $_GET */
!isset($_GET['id']) ? die ('ERROR: Missing video ID') : $vid = $_GET['id'];
/* Set video data feed URL */
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$vid.'?v=2';
/* Read feed into SimpleXML object */
$entry = simplexml_load_file($feedURL);
/* Parse video entry */
$video = parseVideoEntry($entry);
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?=$video->title?></title>
<link href="./style.css" rel="stylesheet" type="text/css" />
</head>
<ul>
<li>Stream:</li>
<li><a href="<?=$video->tgpp?>">3GP</a></li>
<li><a href="<?=$video->mp4?>">MP4</a></li>
<li><a href="<?=$video->flv?>">Youtube Player</a></li>
</ul>
Comment