admin管理员组

文章数量:1303389

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

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

Share edited Jan 22, 2010 at 20:55 ZoogieZork 11.3k5 gold badges47 silver badges42 bronze badges asked Jan 22, 2010 at 20:44 SimonSimon 1011 silver badge3 bronze badges 2
  • Wele to StackOverflow! Great first question. – Tyler Carter Commented Jan 22, 2010 at 20:58
  • Feel free to upvote this if you want to see this feature added. – Cardinal System Commented Mar 2, 2021 at 3:08
Add a ment  | 

2 Answers 2

Reset to default 5

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./feeds/api/videos/faXwJ9TfX9g?alt=json-in-script&callback=processData">
    </script> 
  </body>
</html>

This article has a plete 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./2010/01/retrieve-youtube-video-title.html

本文标签: javascriptGet artist name and song name by YouTube codeStack Overflow