我有一个 YouTube 模块,每天从一些 youtube 用户帐户中抓取视频。我想知道,如何在 YouTube 视频标题中添加额外的关键字?
原标题:乔恩迈克尔 - 视频
我想将标题更改为 - Jon Michael - Video - Hot Clip
这是我用来将 YouTube 视频导入我的网站的脚本模块。
错误报告(0);$feedURL = ' http://gdata.youtube.com/feeds/api/users/ '.$username.'/uploads?orderby=published&start-index=1&max-results=50';
$sxml = @simplexml_load_file($feedURL);
//print_r($sxml);
if($sxml)
{
// get summary counts from opensearch: namespace
$counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/');
echo "Total Videos=".$counts."<br/>";
$_SESSION['total'] = ceil($counts->totalResults);
$i='0';
$_SESSION['page'] = 1;
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = @$attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
$published = (string)$entry->published;
$publishedDate = strtotime($published);
$arr[] = array(
'title' => addslashes((string)$media->group->title),
'description' => addslashes((string)$media->group->description),
'url' => (string)$watch,
'thumbnail' => (string)$thumbnail,
'duration' => (string)$length,
'views' => (string)$viewCount,
'rating' => (string)$rating,
'published' => $publishedDate
);
$i++;
}
}
foreach($arr as $key=>$val)
{
$title=$val[title];
$description=$val[description];
$thumb=$val[thumbnail];
$duration=$val[duration];
$views=$val[views];
$rating=$val[rating];
$publish=$val[published];
$url2=$val[url];
$urlexp=explode('&',$url2);
$url=$urlexp[0];
$urlexp=explode('?v=',$url);
$youtube_key=$urlexp[1];
$tags=$title;
echo '<b>Title</b>='.$title;
echo '<br/><b>Description</b>='.$description;
echo '<br/><b>Url</b>='.$url;
echo '<br/><b>Thumb</b>='.$thumb;
echo '<br/><b>Duration</b>='.$duration;
echo '<br/><b>Views</b>='.$views;
echo '<br/><b>Rating</b>='.$rating;
echo '<br/><b>Publish</b>='.$publish;
$er="select VIDEOID from videos where youtube_key='".$youtube_key."'";
$chkExist=mysql_query($er) or die(mysql_error());
if(mysql_num_rows($chkExist)=='0')
{
$date=date('Y-m-d',strtotime(now));
$query = mysql_query("INSERT INTO videos(USERID,title,description,tags,categories,filesize,time_added,date_added,featured,viewcount,runtime,public,rating,allowcomments,allowratings,allowembeds,allowdownloads,active,mature,youtube_embed,youtube_key) values('4','".mysql_real_escape_string($title)."','".mysql_real_escape_string($description)."','".$tags."','".$cat."','0','".strtotime(now)."','".$date."','1','".mysql_real_escape_string($views)."','".mysql_real_escape_string($duration)."','1','".mysql_real_escape_string($rating)."','1','1','1','1','1','0','1','".mysql_real_escape_string($youtube_key)."')");
$videoid = mysql_insert_id();
$sql = mysql_query("UPDATE videos SET video_name='".$videoid.".flv' WHERE VIDEOID ='".$videoid."'");
$thumbname=$videoid.'-1.jpg';
$thumbname2=$videoid.'-2.jpg';
$thumbname3=$videoid.'-3.jpg';
$thumb1='http://i.ytimg.com/vi/'.$youtube_key.'/1.jpg';
$thumb2='http://i.ytimg.com/vi/'.$youtube_key.'/2.jpg';
$thumb3='http://i.ytimg.com/vi/'.$youtube_key.'/3.jpg';;
copy($thumb1,'images/videothumbs/'.$thumbname);
copy($thumb2,'images/videothumbs/'.$thumbname2);
copy($thumb3,'images/videothumbs/'.$thumbname3);
}
elseif(mysql_num_rows($chkExist))
{
echo 'Already Exists';
}
echo '<br/><br/><hr size="1"/>';
}