使用可恢复上传将视频添加到播放列表 [英] Add a video to a playlist using resumable upload

查看:33
本文介绍了使用可恢复上传将视频添加到播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在使用可续传上传时将视频添加到播放列表中?

Does anyone know how to add a video to a playlist when using resumable upload?

让我说清楚.下面是我的代码.

Let me make this clear. Below is my code.

Video newVideo = new Video();
newVideo.Title = fileName.Split(".".ToCharArray())[0];
newVideo.Tags.Add(new MediaCategory("Nonprofit", YouTubeNameTable.CategorySchema));
newVideo.Description = DateTime.Now.ToShortDateString();
newVideo.YouTubeEntry.Private = false;
ResumableUploader m_ResumableUploader = null;
Authenticator YouTubeAuthenticator;

m_ResumableUploader = new ResumableUploader(100); //chunksize 1 MB
m_ResumableUploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(m_ResumableUploader_AsyncOperationCompleted);
m_ResumableUploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(m_ResumableUploader_AsyncOperationProgress);

YouTubeAuthenticator = new ClientLoginAuthenticator("YouTubeUploader", ServiceNames.YouTube, ConfigurationManager.AppSettings["USERNAME"].ToString(), ConfigurationManager.AppSettings["PASSWORD"].ToString());

YouTubeAuthenticator.DeveloperKey = ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString();
string contentType = MediaFileSource.GetContentTypeForFileName(fileName);
newVideo.MediaSource = new MediaFileSource(filePath, contentType);

AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/<username>/uploads");
link.Rel = ResumableUploader.CreateMediaRelation;
newVideo.YouTubeEntry.Links.Add(link);

System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

m_ResumableUploader.InsertAsync(YouTubeAuthenticator, newVideo.YouTubeEntry, new object());  

我正在尝试将视频直接上传到播放列表.

I am trying to upload a video directly to a playlist.

我正在查看这段代码,但很难将两者联系起来.需要帮助.

I am looking at this code and I am having a difficult time connecting the two. Need help.

https://developers.google.com/youtube/2.0/developers_guide_dotnet

将视频添加到播放列表

您可以使用 PlayListMember 对象将视频添加到播放列表.以下代码创建一个具有已知 ID 值的 PlayListMember 对象,然后将其添加到 Playlist 对象 (p).由于该请求未指定视频将在播放列表中出现的位置,因此将新视频添加到播放列表的末尾.

You can add a video to a playlist by using a PlayListMember object. The following code creates a PlayListMember object with a known ID value and then adds it to the Playlist object (p). Since the request does not specify a position where the video will appear in the playlist, the new video is added to the end of the playlist.

 // For Playlist object p
 PlayListMember pm = new PlayListMember();
 // Insert <id> or <videoid> for video here
 pm.Id = VIDEOID;
 request.AddToPlaylist(p, pm);

更新 1 - 添加到播放列表时出现不支持的 URI 格式"错误.

YouTubeRequestSettings ys = new YouTubeRequestSettings("YouTubeUploader",
ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString());
YouTubeRequest ytr = new YouTubeRequest(ys);
Video v = ytr.ParseVideo(e.ResponseStream);                  
PlayListMember pm = new PlayListMember();
Feed<Playlist> userPlaylists = ytr.GetPlaylistsFeed(ytr.Credentials.Username);
foreach (Playlist p in userPlaylists.Entries)
{
     fs.WriteLine(p.Title);
     if (p.Title == "Test 2")
     {
          pm.Id = v.VideoId;
          ytr.AddToPlaylist(p, pm);

          fs.WriteLine("Added To Playlist ");
     }
}

推荐答案

我想通了.YouTube 上的代码有错误.它告诉您将 PlayListMember id 设置为 VIDEOID.

I figured it out. The code on YouTube has an error in it. It tells you to set the PlayListMember id to the VIDEOID.

 // For Playlist object p
 PlayListMember pm = new PlayListMember();
 // Insert <id> or <videoid> for video here
 pm.Id = VIDEOID;
 request.AddToPlaylist(p, pm);

这是错误的.您需要将 VIDEOID 设置为 PlayListMember VideoID

That is incorrect. You need to set the VIDEOID to the PlayListMember VideoID

 // For Playlist object p
 PlayListMember pm = new PlayListMember();
 // Insert <id> or <videoid> for video here
 pm.VideoId = VIDEOID;
 request.AddToPlaylist(p, pm);

这篇关于使用可恢复上传将视频添加到播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆