Get artist name and song name by YouTube code
On my website, people are able to drop their YouTube code link Like faXwJ9TfX9g
How do I get the name of the artist and name of the song, with a simple Javascript.
Input : faXwJ9TfX9g by User
Output : Name of artist
Output : Name of the Song
Output : Length of the Song
开发者_运维技巧
Best regards,
Simon Buijs Zwaag Netherlands
Youtube videos don't have tags for artist and song title (like mp3 files do, for example). So, AFAIK the best you can do is get the video title. You could go further and parse it to get the artist and song name, but I don't think this is something you'd want to do. Using the Data API here's what you can do:
<html>
<head>
<script type="text/javascript">
function processData(data) {
var title = data.entry.title.$t;
var duration = data.entry.media$group.media$content[0].duration;
}
</script>
</head>
<body>
<script
type="text/javascript"
src="http://gdata.youtube.com/feeds/api/videos/faXwJ9TfX9g?alt=json-in-script&callback=processData">
</script>
</body>
</html>
This article has a complete answer, including a second version using user selected IDs at runtime (most examples I found seemed to only have a hardcoded ID).
http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html
精彩评论