如何使用YouTube或其他API从youtube频道(ISRC,Video_ISRC,Asset_ID,UPC)上的视频中获取完整信息。
private void btnSend_Click(object sender, EventArgs e)
{
string channelname = txtChannel.Text;
string developerKey = "AI39si4f9ZH80eTwUdmc3sd89kYTxEjWxWEXIPyW2hP8LIYEDJjoUrcl26jEbpzYJpaH3Bckk-4GVtfgEPQ9GkrDERRydwaobQ";
StreamWriter sw = new StreamWriter(@"d:\youtubechannelcontent.txt");
YouTubeRequestSettings settings = new YouTubeRequestSettings(channelname, developerKey);
YouTubeRequest _request = new YouTubeRequest(settings);
string _feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", channelname);
Feed<Video> _vediofeed = _request.Get<Video>(new Uri(_feedUrl));
int max = _vediofeed.TotalResults;
int index = 1;
MessageBox.Show(max.ToString());
YouTubeRequest request = new YouTubeRequest(settings);
while (index<max)
{
string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?max-results=50&start-index={1}", channelname, index);
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (var item in videoFeed.Entries)
{
sw.WriteLine(item.Author + "," + item.CommmentCount + "," + item.ETag + "," + item.Id + "," +item.RatingAverage+ "," +item.Title+ "," +item.Updated+ "," +item.Uploader+ "," +item.VideoId+ "," +item.ViewCount+ "," +item.WatchPage);
//sw.WriteLine(item.Title+","+item.YouTubeEntry);
}
index += 50;
}
}
此代码无法获取视频的ISRC,Video_ISRC,Asset_ID和UPC。
答案 0 :(得分:1)
为简单起见,您可以像这样使用api v2:
const string channelName = "YourChannel";
var URL =string.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads",
channelName);
using (var reader = new XmlTextReader(URL))
{
while (reader.Read())
{
if (reader.Name.Equals("media:player"))
{
string attribute = reader["url"];
if (attribute != null)
{
Response.Write("Youtube Video Link" + attribute + "<br />");
}
}
}
}
您可以使用v3
进行类似的操作,但这需要更多的工作