Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="BoundaryString"></param>
        /// <returns></returns>
        private MemoryStream GetPOSTData(string BoundaryString, YouTubeVideoFileInfo YouTubeFileInfo)
        {
            //byte[] buffer;
            string        strPostData        = string.Empty;
            MemoryStream  ms                 = new MemoryStream();
            StringBuilder strPostDataBuilder = new StringBuilder();

            strPostDataBuilder.AppendLine("--" + BoundaryString);
            strPostDataBuilder.AppendLine("Content-Type: application/atom+xml; charset=UTF-8");
            strPostDataBuilder.AppendLine();

            #region YouTube feed initialization

            YouTubeAPI.Feed.entry entry = new YouTubeAPI.Feed.entry(YouTubeAPI.Feed.feedType.upload);
            entry.group.title.type       = "plain";
            entry.group.title.Text       = YouTubeFileInfo.Title;                                                 //"Bad Wedding Toast";
            entry.group.description.type = "plain";
            entry.group.description.Text = YouTubeFileInfo.Description;                                           //"I gave a bad toast at my friend's wedding.";
            entry.group.category.scheme  = "http://gdata.youtube.com/schemas/2007/categories.cat";
            entry.group.category.Text    = EnumToString.Get(typeof(YouTubeCategories), YouTubeFileInfo.Category); //"People";
            entry.group.keywords.Text    = YouTubeFileInfo.Keywords;

            #endregion
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add("media", "http://search.yahoo.com/mrss/");
            namespaces.Add("yt", "http://gdata.youtube.com/schemas/2007");
            string strSRZD = XmlSerializationUtility.ObjectToXmlString(entry, namespaces);

            strPostDataBuilder.Append("<?xml version=\"1.0\"?>");
            strPostDataBuilder.AppendLine(strSRZD);
            //Console.WriteLine("************************************");
            //Console.WriteLine(strPostDataBuilder.ToString());
            //Console.WriteLine("************************************");
            strPostDataBuilder.AppendLine("--" + BoundaryString);
            strPostDataBuilder.AppendLine("Content-Type: video/mpeg");
            strPostDataBuilder.AppendLine("Content-Transfer-Encoding: binary");
            strPostDataBuilder.AppendLine();

            //>>Test
            //using (StreamWriter streamWriter = new StreamWriter("Atom.xml"))
            //{
            //    streamWriter.Write(strPostDataBuilder.ToString());
            //}
            //<<Test

            ms.Write(Encoding.UTF8.GetBytes(strPostDataBuilder.ToString()), 0, Encoding.UTF8.GetByteCount(strPostDataBuilder.ToString()));
            byte[] fileToUpload = FileUtils.GetFile(YouTubeFileInfo.FilePath);
            ms.Write(fileToUpload, 0, fileToUpload.Length);
            ms.Write(Encoding.UTF8.GetBytes("\n--" + BoundaryString + "--"), 0, Encoding.UTF8.GetByteCount("\n--" + BoundaryString + "--"));
            return(ms);
        }
Beispiel #2
0
 public static void YouTube()
 {
     YouTubeService youTube = new YouTubeService("AI39si6FVg_zhgRNm_kODUN80kTgzXUgF1qMrlzr9VpMj4GlCo6KkLxNVccugM4sV5b0b6gxIpg6rO0hjp82sDeY0YJpIfZmVw");
     youTube.Login("Jhotest", "jhotest", "simple");
     youTube.OnTranferingProgress += new EventHandler<YouTubeEventArgs>(youTube_OnTranferingProgress);
     //youTube.RetriveVideo();
     YouTubeVideoFileInfo newFileInfo = new YouTubeVideoFileInfo()
     {
       FilePath = @"e:\MYFOLDERS\Visual Studio 2008\Projects\VideoUploader\Bin\test.flv",
       Title = "Test video title",
       Description = "Description for my video",
       Category = YouTubeCategories.PetsAndAnimals,
       Keywords = "test, .net, library, programing"
     };
     youTube.UploadVideo(newFileInfo);
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="YouTubeFileInfo"></param>
        /// <returns></returns>
        public void UploadVideo(YouTubeVideoFileInfo YouTubeFileInfo)
        {
            //Console.WriteLine("Uploading...");

            FileInfo fileUploadInfo    = new FileInfo(YouTubeFileInfo.FilePath);
            string   strBoundaryString = this.GetBoundaryString();

            Request.InitURI(Requests.UploadVideo(this.AuthInfo.YouTubeUser));
            Request.YouTubeRequest.Headers.Add("Slug", fileUploadInfo.Name);
            Request.YouTubeRequest.ContentType = String.Format("multipart/related; boundary={0}", strBoundaryString);
            Request.YouTubeRequest.KeepAlive   = false;
            //string strResponse = Request.DoPOST(this.AuthInfo, this.GetPOSTData(strBoundaryString, FileName));
            Request.DoPOST(this.AuthInfo, this.GetPOSTData(strBoundaryString, YouTubeFileInfo));
            eventWaitResponse.WaitOne();

            //>>Test
            //using (StreamWriter streamWriter = new StreamWriter("response.xml"))
            //{
            //    streamWriter.Write(this.strResponse);
            //}
            //Console.WriteLine(this.strResponse);
            //<<Test
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="BoundaryString"></param>
        /// <returns></returns>
        private MemoryStream GetPOSTData(string BoundaryString, YouTubeVideoFileInfo YouTubeFileInfo)
        {
            //byte[] buffer;
            string strPostData = string.Empty;
            MemoryStream ms = new MemoryStream();
            StringBuilder strPostDataBuilder = new StringBuilder();

            strPostDataBuilder.AppendLine("--" + BoundaryString);
            strPostDataBuilder.AppendLine("Content-Type: application/atom+xml; charset=UTF-8");
            strPostDataBuilder.AppendLine();

            #region YouTube feed initialization

            YouTubeAPI.Feed.entry entry = new YouTubeAPI.Feed.entry(YouTubeAPI.Feed.feedType.upload);
            entry.group.title.type = "plain";
            entry.group.title.Text = YouTubeFileInfo.Title;//"Bad Wedding Toast";
            entry.group.description.type = "plain";
            entry.group.description.Text = YouTubeFileInfo.Description;//"I gave a bad toast at my friend's wedding.";
            entry.group.category.scheme = "http://gdata.youtube.com/schemas/2007/categories.cat";
            entry.group.category.Text = EnumToString.Get(typeof(YouTubeCategories),YouTubeFileInfo.Category);//"People";
            entry.group.keywords.Text = YouTubeFileInfo.Keywords;

            #endregion
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add("media", "http://search.yahoo.com/mrss/");
            namespaces.Add("yt", "http://gdata.youtube.com/schemas/2007");
            string strSRZD = XmlSerializationUtility.ObjectToXmlString(entry, namespaces);

            strPostDataBuilder.Append("<?xml version=\"1.0\"?>");
            strPostDataBuilder.AppendLine(strSRZD);
            //Console.WriteLine("************************************");
            //Console.WriteLine(strPostDataBuilder.ToString());
            //Console.WriteLine("************************************");
            strPostDataBuilder.AppendLine("--" + BoundaryString);
            strPostDataBuilder.AppendLine("Content-Type: video/mpeg");
            strPostDataBuilder.AppendLine("Content-Transfer-Encoding: binary");
            strPostDataBuilder.AppendLine();

            //>>Test
            //using (StreamWriter streamWriter = new StreamWriter("Atom.xml"))
            //{
            //    streamWriter.Write(strPostDataBuilder.ToString());
            //}
            //<<Test

            ms.Write(Encoding.UTF8.GetBytes(strPostDataBuilder.ToString()), 0, Encoding.UTF8.GetByteCount(strPostDataBuilder.ToString()));
            byte[] fileToUpload = FileUtils.GetFile(YouTubeFileInfo.FilePath);
            ms.Write(fileToUpload, 0, fileToUpload.Length);
            ms.Write(Encoding.UTF8.GetBytes("\n--" + BoundaryString + "--"), 0, Encoding.UTF8.GetByteCount("\n--" + BoundaryString + "--"));
            return ms;
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="YouTubeFileInfo"></param>
        /// <returns></returns>
        public void UploadVideo(YouTubeVideoFileInfo YouTubeFileInfo)
        {
            //Console.WriteLine("Uploading...");

            FileInfo fileUploadInfo = new FileInfo(YouTubeFileInfo.FilePath);
            string  strBoundaryString =  this.GetBoundaryString();

            Request.InitURI(Requests.UploadVideo(this.AuthInfo.YouTubeUser));
            Request.YouTubeRequest.Headers.Add("Slug", fileUploadInfo.Name);
            Request.YouTubeRequest.ContentType = String.Format("multipart/related; boundary={0}", strBoundaryString);
            Request.YouTubeRequest.KeepAlive = false;
            //string strResponse = Request.DoPOST(this.AuthInfo, this.GetPOSTData(strBoundaryString, FileName));
            Request.DoPOST(this.AuthInfo, this.GetPOSTData(strBoundaryString, YouTubeFileInfo));
            eventWaitResponse.WaitOne();

            //>>Test
            //using (StreamWriter streamWriter = new StreamWriter("response.xml"))
            //{
            //    streamWriter.Write(this.strResponse);
            //}
            //Console.WriteLine(this.strResponse);
            //<<Test
        }