我的视频博客帖子生成器(http://v.leau.co/)这样做,但不在wp上下文中。
您提供一个查询,例如“superman”(然后等待(不知道它正在做什么)(因为im是唯一的用户)),然后单击您想发布的视频,单击生成代码,您就有了拇指所在的代码,因为它同时下载了这些代码。此代码可以复制并粘贴到帖子中。
换句话说,如果您将代码放入函数调用中,它将返回一段代码,例如a href,其中包含添加到内容中的视频链接,或本地下载的特色图像链接。
这就是你要找的代码吗?我认为核心是:
用于检索更多结果的函数(因此,如果您只想在结果代码中显示多个视频,而不是一个特定的视频):
function retrieveMoreResults($key, $q, $start, $cache) {
$url = "http://ajax.googleapis.com/ajax/services/search/video?v=1.0&q=" . $q . "&rsz=large&start=" . $start. "&key=" . $key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($body, true);
$tempOutputString .= display($responseData, $cache, $q);
return $tempOutputString;
}
获取初始结果页的函数:
function retrieveResults($key, $q, $cache) {
# first call
$url = "http://ajax.googleapis.com/ajax/services/search/video?v=1.0&q=" . $q . "&rsz=large&key=" . $key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($body, true);
$tempOutputString = "";
$tempOutputString .= display($responseData, $cache, $q);
$boolFirstRequest = true;
foreach ($responseData["responseData"]["cursor"]["pages"] as $GsearchResultClass) {
$start = $GsearchResultClass["start"];
if ($boolFirstRequest) {
$boolFirstRequest = false;
} else {
$tempOutputString .= retrieveMoreResults($key, $q, $start, $cache);
}
}
return $tempOutputString;
}
在某个目录(变量)中显示下载拇指并返回一段代码以放入帖子的函数:
function display($responseData, $cache, $tag) {
$strBuffer="";
foreach ($responseData["responseData"]["results"] as $GsearchResultClass) {
#
# there are YouTube urls and also Google Video urls they are both different
# the one from Google video has the word "ThumbnailServer" in it
# example:
# youtube: http://1.gvt0.com/vi/6jKzr143K8U/default.jpg
# video.google: http://3.gvt0.com/ThumbnailServer2?app=vss&contentid=7efbd69963e4cc67&offsetms=30000&itag=w160&hl=en&sigh=J6N1fv_It6H5jJWX51fKt-eYqNk
#
$thumbId="";
$imageThumb=$GsearchResultClass["tbUrl"];
if (strstr($imageThumb, \'ThumbnailServer\')) {
$imgStringBits = explode(\'&\',$imageThumb);
$parsedImgStr=strstr($imgStringBits[1],\'=\');
$parsedImgStr = substr($parsedImgStr,1);
$thumbId = $parsedImgStr;
} else {
$imgStringBits = explode(\'/\',$imageThumb);
$thumbId = $imgStringBits[4];
}
$imgFile=$cache . "/" . $thumbId . ".jpg";
#
# Now that we have the imageFile Name check if we already have it in the cache:
# - if we have it NEVER delete it (why should we?)
# - if we dont well... get it via curl
#
if (!file_exists($imgFile)) {
$ch = curl_init ();
$timeout = 5;
curl_setopt ($ch, CURLOPT_USERAGENT, \'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0\');
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt ($ch, CURLOPT_URL, $imageThumb);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt ($ch, CURLOPT_VERBOSE, 1);
$rawdata = curl_exec ($ch);
curl_close ($ch);
if($rawdata) {
$fp = fopen($imgFile, \'w\');
fwrite($fp, $rawdata);
fclose($fp);
} else {
#
# If our Curl action retrieves nothing then use the default image
#
$imgfile="images/default.jpg";
}
}
#
# Now that we have the image url create a div (hmm.. might drop that
# styling later on in a seperate csss) containg the video thumb, link
# and the description. When you like it you can add all the other
# parameters that Google returns like length etc...
#
$strBuffer .= "<div style=\\"float:left;width:125px;height:130px;font-size:8px;font-family:arial;\\" class=\\"thumb\\"><div>";
$strBuffer .= "<a href=\\"#\\" class=\\"del\\" id=\\"$thumbId\\"> ADD</a><br />";
$strBuffer .= "<a href=\\"" . $GsearchResultClass["playUrl"] . "\\" target=\\"_blank\\">";
$strBuffer .= "<img src=\\"" . $imgFile . "\\" alt=\\"" . $GsearchResultClass["title"] . "\\" border=\\"0\\" width=\\"120\\">";
$strBuffer .= "</a><br />\\n";
#
# Note that we also add a delete option, for now that only removes it from the page
# but in the next version it should do an AJAX call to write the id somewhere so
# that we never see it again.
#
$strBuffer .= $GsearchResultClass["titleNoFormatting"] . "<br />";
$strBuffer .= "</div></div>\\n";
}
return $strBuffer;
}
调用上述函数:
function moviePage($tag, $cacheName, $cacheTime, $key) {
$cache = $cacheName . "/" . $tag;
checkCache($cache);
cleanCacheHTML($cache);
$filename = $tag . ".html";
$spFile=$cache . "/" . $filename;
if (file_exists($spFile) && filemtime($spFile) > $cacheTime ) {
$strBuffer = file_get_contents($spFile) . "<!-- " . $spFile . " from cache -->";
} else {
$strBuffer = retrieveResults($key, $tag, $cache);
}
$strBuffer .= "<br clear=\\"all\\">";
$fp = fopen($spFile, \'w\');
fwrite($fp, $strBuffer);
fclose($fp);
return $strBuffer;
}
($键是您的Google API键)(http://code.google.com/intl/nl-NL/more/)
我怎么认为剩下的更多的只是“获取返回的内容并将其添加到帖子的内容中+将下载的缓存拇指设置为特色?”?
P、 在提到YouTube视频时,最好在视频中发布缩略图,因为老视频通常会被YouTube删除,结果会留下难看的帖子。用你自己的大拇指,至少图像会永远留在那里,这样之后你就可以知道你最初在那里发布了什么。