Created
February 27, 2011 13:47
-
-
Save yukioc/846194 to your computer and use it in GitHub Desktop.
YouTube DataAPI sample program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html><head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | |
| <script type="text/javascript"> | |
| function yt_search(){ | |
| var keyword=encodeURIComponent(document.getElementById("keyword").value); | |
| var script=document.createElement("script"); | |
| script.type="text/javascript"; | |
| script.src="http://gdata.youtube.com/feeds/api/videos?" | |
| + "vq=" + keyword + "&alt=json-in-script&max-results=30&callback=yt_cb"; | |
| var yt_view=document.getElementById("yt_view"); | |
| yt_view.innerHTML="Loading..."; | |
| yt_view.appendChild(script); | |
| } | |
| var imgs=[]; | |
| var timer=false; | |
| function imgs_update(){ | |
| if(!timer){ | |
| timer=true; | |
| for(var i=0;i<imgs.length;i++){ | |
| var o=imgs[i].thumbnail.shift(); | |
| imgs[i].img.src=o.url; | |
| imgs[i].thumbnail.push(o); | |
| } | |
| setTimeout(function(){timer=false;imgs_update();},2000); | |
| } | |
| } | |
| function yt_cb(data){ | |
| var yt_view=document.getElementById("yt_view"); | |
| yt_view.innerHTML=""; | |
| imgs=[]; | |
| for (var i=0,e=data.feed.entry;i<e.length;i++){ | |
| var group=e[i].media$group; | |
| var a=document.createElement("a"); | |
| var img=document.createElement("img"); | |
| a.href = group.media$player[0].url; | |
| a.title = group.media$title.$t; | |
| img.src = group.media$thumbnail[0].url; | |
| img.width = '120'; | |
| a.appendChild(img); | |
| yt_view.appendChild(a); | |
| imgs.push({img:img, thumbnail:group.media$thumbnail.concat()}); | |
| } | |
| imgs_update(); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <p><a href=http://code.google.com/intl/ja/apis/youtube/reference.html"> | |
| YouTube Data API</a> Sample</p> | |
| <form onsubmit="yt_search();return false;"> | |
| <input type="text" id="keyword"> | |
| <input type="submit" value="search"> | |
| </form> | |
| <div id="yt_view"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment