Ejemplo n.º 1
0
        private YouTubeApiResult ParseYouTubeXmlResponse(string xmlText)
        {
            var xml = XElement.Parse(xmlText);
            XNamespace yt = "http://gdata.youtube.com/schemas/2007";
            XNamespace media = "http://search.yahoo.com/mrss/";
            XNamespace atom = "http://www.w3.org/2005/Atom";
            var result = new YouTubeApiResult();
            result.ID = (from c in xml.Descendants(yt + "videoid") select c).First().Value;
            result.Title = (from c in xml.Descendants(atom+"title") select c).First().Value;
            result.Description = (from c in xml.Descendants(media + "description") select c).First().Value;
            result.Published = (from c in xml.Descendants(atom+"published") select c).First().Value;
            result.Thumbnail = (string)(from c in xml.Descendants(media + "thumbnail") select c).First().Attribute("url");
            result.Success = "true";
            var author = (from c in xml.Descendants(atom + "author") select c).First();
            var authorName = author.Descendants(atom + "name").First().Value;
            var authorUri = author.Descendants(atom + "uri").First().Value;
            result.Author = string.Format("<a href='{0}'>{1}</a>", authorUri, authorName);

            return result;
        }
Ejemplo n.º 2
0
        public Media CreateYouTubeMedia(Media obj, Guid objID, YouTubeApiResult youTubeResult)
        {
            var imgID = Guid.NewGuid().ToString().Substring(0, 12);
            string fileName = string.Format("{0}.jpg", imgID);

            using (Stream stream = new ImageDownloader().DownloadImageAsStream(youTubeResult.Thumbnail))
            {
                imgManager.SaveThumb75x75_MediumCompressed(stream, ImageManager.MediaPhotosTmPath, fileName);
            }

            obj.FeedVisible = true; //-- Movies are always visible

            obj.TypeID = (byte)MediaType.Youtube;
            obj.Content = (new YouTubeMediaData() { Thumbnail = fileName, YouTubeID = youTubeResult.ID }).ToJson();
            obj.ContentType = "application/json";
            obj.Description = youTubeResult.Description;
            obj.Author = youTubeResult.Author;
            obj.TakenDate = DateTime.Parse(youTubeResult.Published).Date;

            return CreateMedia(obj, objID);
        }