FC2ブログ

<?php
// 検索ワード
$Get_Keyword = ereg_replace("[  ]+", " ", trim($_GET['vq']));
$Get_Keyword_enc_utf = urlencode(mb_convert_encoding($Get_Keyword, "UTF-8", "EUC-JP"));

// リクエストパラメータ
$Youtube = "http://gdata.youtube.com/feeds/api/videos";
$vq = "?vq=".$Get_Keyword_enc_utf;
$orderby = "&orderby="."relevance";
$start_index = "&start-index="."1";
$max_results = "&max-results="."25";
// $author = "&author="."";
$alt = "&alt="."atom";
// $format = "&format="."";
$lr = "&lr="."ja";
$racy = "&racy="."include";
// $restriction = "&restriction="."";
$time = "&time="."all_time";

// XML
$url = $Youtube.$vq.$orderby.$start_index.$max_results.$author.$alt.$format.$lr.$racy.$restriction.$time;
$xmldata = simplexml_load_file($url) or die("XMLパースエラー");

$id = $xmldata->id;
$updated = $xmldata->updated;
$category_scheme = $xmldata->category['scheme'];
$category_term = $xmldata->category['term'];
$title = mb_convert_encoding($xmldata->title, "EUC-JP", "UTF-8");
$logo = $xmldata->logo;
for($i = 0; $i < count($xmldata->link); $i++){
$link[$i]['rel'] = $xmldata->link[$i]['rel'];
$link[$i]['type'] = $xmldata->link[$i]['type'];
$link[$i]['href'] = $xmldata->link[$i]['href'];
}
$author_name = $xmldata->author->name;
$author_uri = $xmldata->author->uri;
$generator = $xmldata->generator;
$generator_version = $xmldata->generator['version'];
$generator_uri = $xmldata->generator['uri'];
// Open Search スキーマ
$openSearch = $xmldata->children("http://a9.com/-/spec/opensearchrss/1.0/");
$openSearch_totalResults = $openSearch->totalResults;
$openSearch_startIndex = $openSearch->startIndex;
$openSearch_itemsPerPage = $openSearch->itemsPerPage;

print $id."<br />";
print $updated."<br />";
print $category_scheme."<br />";
print $category_term."<br />";
print $title."<br />";
print $logo."<br />";
for($i = 0; $i < count($xmldata->link); $i++){
print $link[$i]['rel']."<br />";
print $link[$i]['type']."<br />";
print $link[$i]['href']."<br />";
}
print $author_name."<br />";
print $author_uri."<br />";
print $generator."<br />";
print $generator_version."<br />";
print $generator_uri."<br />";
print $openSearch_totalResults."<br />";
print $openSearch_startIndex."<br />";
print $openSearch_itemsPerPage."<br />";

foreach($xmldata->entry as $entry){
// 配列の初期化
$category = array();
$link = array();
$MediaRSS_content = array();
$MediaRSS_thumbnail = array();

$id = $entry->id;
$published = $entry->published;
$updated = $entry->updated;
for($i = 0; $i < count($entry->category); $i++){
$category[$i]['scheme'] = $entry->category[$i]['scheme'];
$category[$i]['term'] = mb_convert_encoding($entry->category[$i]['term'], "EUC-JP", "UTF-8");
$category[$i]['label'] = mb_convert_encoding($entry->category[$i]['label'], "EUC-JP", "UTF-8");
}
$title = mb_convert_encoding($entry->title, "EUC-JP", "UTF-8");
$content = mb_convert_encoding($entry->content, "EUC-JP", "UTF-8");
for($i = 0; $i < count($entry->link); $i++){
$link[$i]['rel'] = $entry->link[$i]['rel'];
$link[$i]['type'] = $entry->link[$i]['type'];
$link[$i]['href'] = $entry->link[$i]['href'];
}
$author_name = $entry->author->name;
$author_uri = $entry->author->uri;
// Google Data スキーマ
$GoogleData = $entry->children("http://schemas.google.com/g/2005");
// Google Data comments
$GoogleData_feedLink_attributes = $GoogleData->comments->feedLink->attributes();
$GoogleData_feedLink = $GoogleData_feedLink_attributes['href'];
$GoogleData_countHint = $GoogleData_feedLink_attributes['countHint'];
// Media RSS
$MediaRSS = $entry->children("http://search.yahoo.com/mrss/");
// Media RSS category
$MediaRSS_category = $MediaRSS->group->category;
$MediaRSS_category_attributes = $MediaRSS->group->category->attributes();
$MediaRSS_category_label = $MediaRSS_category_attributes->label;
$MediaRSS_category_scheme = $MediaRSS_category_attributes->scheme;
// Media RSS content
for($i = 0; $i < count($MediaRSS->group->content); $i++){
$MediaRSS_content_attributes = $MediaRSS->group->content[$i]->attributes();
$MediaRSS_content[$i]['url'] = $MediaRSS_content_attributes['url'];
$MediaRSS_content[$i]['type'] = $MediaRSS_content_attributes['type'];
$MediaRSS_content[$i]['medium'] = $MediaRSS_content_attributes['medium'];
$MediaRSS_content[$i]['expression'] = $MediaRSS_content_attributes['expression'];
$MediaRSS_content[$i]['duration'] = $MediaRSS_content_attributes['duration'];
$MediaRSS_content[$i]['yt:format'] = $MediaRSS_content_attributes['yt:format'];
}
// Media RSS description
$MediaRSS_description = $MediaRSS->group->description;
$MediaRSS_description_attributes = $MediaRSS->group->description->attributes();
$MediaRSS_description_type = $MediaRSS_description_attributes->type;
// Media RSS keywords
$MediaRSS_keywords = mb_convert_encoding($MediaRSS->group->keywords, "EUC-JP", "UTF-8");
// Media RSS player
$MediaRSS_player_attributes = $MediaRSS->group->player->attributes();
$MediaRSS_player_url = $MediaRSS_player_attributes->url;
// Media RSS thumbnail
for($i = 0; $i < count($MediaRSS->group->thumbnail); $i++){
$MediaRSS_thumbnail_attributes = $MediaRSS->group->thumbnail[$i]->attributes();
$MediaRSS_thumbnail[$i]['url'] = $MediaRSS_thumbnail_attributes['url'];
$MediaRSS_thumbnail[$i]['height'] = $MediaRSS_thumbnail_attributes['height'];
$MediaRSS_thumbnail[$i]['width'] = $MediaRSS_thumbnail_attributes['width'];
$MediaRSS_thumbnail[$i]['time'] = $MediaRSS_thumbnail_attributes['time'];
}
// YouTube XML スキーマ
$YouTube_XML = $MediaRSS->children("http://gdata.youtube.com/schemas/2007");
// YouTube XML duration
$YouTube_XML_duration_attributes = $YouTube_XML->duration->attributes();
$YouTube_XML_duration_seconds = $YouTube_XML_duration_attributes->seconds;
// Google Data comments
$GoogleData_rating_attributes = $GoogleData->rating->attributes();
$GoogleData_rating_average = $GoogleData_rating_attributes->average;
$GoogleData_rating_max = $GoogleData_rating_attributes->max;
$GoogleData_rating_min = $GoogleData_rating_attributes->min;
$GoogleData_rating_numRaters = $GoogleData_rating_attributes->numRaters;
$GoogleData_rating_rel = $GoogleData_rating_attributes->rel;
// YouTube XML statistics
$YouTube_XML = $entry->children("http://gdata.youtube.com/schemas/2007");
$YouTube_XML_statistics_attributes = $YouTube_XML->statistics->attributes();
$YouTube_XML_statistics_favoriteCount = $YouTube_XML_statistics_attributes->favoriteCount;
$YouTube_XML_statistics_viewCount = $YouTube_XML_statistics_attributes->viewCount;

print $id."<br />";
print $published."<br />";
print $updated."<br />";
for($i = 0; $i < count($category); $i++){
print $category[$i]['scheme']."<br />";
print $category[$i]['term']."<br />";
print $category[$i]['label']."<br />";
}
print $title."<br />";
print $content."<br />";
for($i = 0; $i < count($link); $i++){
print $link[$i]['rel']."<br />";
print $link[$i]['type']."<br />";
print $link[$i]['href']."<br />";
}
print $author_name."<br />";
print $author_uri."<br />";
// Google Data comments
print $GoogleData_feedLink_attributes."<br />";
print $GoogleData_feedLink."<br />";
print $GoogleData_countHint."<br />";
// Media RSS category
print $MediaRSS_category."<br />";
print $MediaRSS_category_attributes."<br />";
print $MediaRSS_category_label."<br />";
print $MediaRSS_category_scheme."<br />";
// Media RSS content
for($i = 0; $i < count($MediaRSS_content); $i++){
print $MediaRSS_content[$i]['url']."<br />";
print $MediaRSS_content[$i]['type']."<br />";
print $MediaRSS_content[$i]['medium']."<br />";
print $MediaRSS_content[$i]['expression']."<br />";
print $MediaRSS_content[$i]['duration']."<br />";
print $MediaRSS_content[$i]['yt:format']."<br />";
}
// Media RSS description
print $MediaRSS_description_attributes."<br />";
print $MediaRSS_description_type."<br />";
// Media RSS keywords
print $MediaRSS_keywords."<br />";
// Media RSS player
print $MediaRSS_player_url."<br />";
// Media RSS thumbnail
for($i = 0; $i < count($MediaRSS_thumbnail); $i++){
print $MediaRSS_thumbnail[$i]['url']."<br />";
print $MediaRSS_thumbnail[$i]['height']."<br />";
print $MediaRSS_thumbnail[$i]['width']."<br />";
print $MediaRSS_thumbnail[$i]['time']."<br />";
}
// YouTube XML duration
print $YouTube_XML_duration_seconds."<br />";
// Google Data comments
print $GoogleData_rating_average."<br />";
print $GoogleData_rating_max."<br />";
print $GoogleData_rating_min."<br />";
print $GoogleData_rating_numRaters."<br />";
print $GoogleData_rating_rel."<br />";
// YouTube XML statistics
print $YouTube_XML_statistics_attributes."<br />";
print $YouTube_XML_statistics_favoriteCount."<br />";
print $YouTube_XML_statistics_viewCount."<br />";
}
?>


参考URL
リファレンス ガイド: Data API プロトコル -
PHP で YouTube API を操作する

一言
取得できたのだけ表示させているけど、何が何を表しているのかわからね
オンライン コンパイラ/インタプリタ
テクニカル分析
プロフィール

Author:雨宮
Firefoxを使用しているので気づかなかったけど、IE6でソースコードを上手くコピーできない

5/3
携帯用ならIE6でもソースコードをコピーできる
携帯用

検索フォーム


あわせて読みたいブログパーツ
一寸先は闇 RSS