Example #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);
        }
Example #2
0
 public static void TestEntryFeed()
 {
     YouTubeAPI.Feed.entry entry = new YouTubeAPI.Feed.entry(YouTubeAPI.Feed.feedType.upload);
     entry.group.title.type = "plain";
     entry.group.title.Text = "Bad Wedding Toast";
     entry.group.description.type = "plain";
     entry.group.description.Text = "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), YouTubeCategories.PeopleAndBlogs);
     entry.group.keywords.listKeywords.Add("toast");
     entry.group.keywords.listKeywords.Add("wedding");
     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, "http://www.w3.org/2005/Atom", namespaces);
     Console.WriteLine(strSRZD);
 }
Example #3
0
        public static void TestEntryFeed()
        {
            YouTubeAPI.Feed.entry entry = new YouTubeAPI.Feed.entry(YouTubeAPI.Feed.feedType.upload);
            entry.group.title.type       = "plain";
            entry.group.title.Text       = "Bad Wedding Toast";
            entry.group.description.type = "plain";
            entry.group.description.Text = "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), YouTubeCategories.PeopleAndBlogs);
            entry.group.keywords.listKeywords.Add("toast");
            entry.group.keywords.listKeywords.Add("wedding");
            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, "http://www.w3.org/2005/Atom", namespaces);

            Console.WriteLine(strSRZD);
        }
Example #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;
        }