Example #1
0
        public bool UploadVideoToYouTube(YoutubeVideo video, out string videoId, string userName = "", string password = "")
        {
            //to upload video onto youtube, the video must have atleast 1 category
            videoId = string.Empty;
            if (video.Categories == null || video.Categories.Count == 0)
            {
                return(false);
            }

            var settings = new YouTubeRequestSettings(_applicationName, _developerKey,
                                                      string.IsNullOrEmpty(userName) ? _userName : userName,
                                                      string.IsNullOrEmpty(password) ? _password : password)
            {
                Timeout = 100000000
            };

            var request = new YouTubeRequest(settings);

            var newVideo = new Video {
                Title = video.Title, Description = video.Description
            };

            foreach (var category in video.Categories)
            {
                newVideo.Tags.Add(new MediaCategory(category, YouTubeNameTable.CategorySchema));
            }

            foreach (var tag in video.Tags)
            {
                newVideo.Tags.Add(new MediaCategory(tag, YouTubeNameTable.DeveloperTagSchema));
            }

            newVideo.Keywords                 = video.Tags.Any() ? String.Join(",", video.Tags.ToArray()) : string.Empty;
            newVideo.Private                  = true;
            newVideo.YouTubeEntry.Private     = false;
            newVideo.YouTubeEntry.Location    = new GeoRssWhere(video.Latitude, video.Longitude);
            newVideo.YouTubeEntry.MediaSource = new MediaFileSource(video.LocalFilePath, "video/wmv");

            try
            {
                Video createdVideo = request.Upload(newVideo);
                videoId = createdVideo.Id;
                return(true);
            }
            catch (Exception ex)
            {
            }

            return(false);
        }
Example #2
0
        public static YoutubeVideo ToYoutubeVideo(this YouTubeEntry entry)
        {
            YoutubeVideo video = new YoutubeVideo();

            video.VideoId = entry.VideoId;
            video.Title   = entry.Title.Text;
            foreach (var category in entry.Media.Categories)
            {
                if (category.Attributes["label"] != null)
                {
                    video.Categories.Add(category.Attributes["label"].ToString());
                }
            }
            if (entry.Statistics != null)
            {
                video.ViewCounts = long.Parse(entry.Statistics.ViewCount);
            }
            if (entry.Comments != null)
            {
                video.CommentCounts = long.Parse(entry.Comments.FeedLink.CountHint.ToString());
            }
            if (entry.Rating != null)
            {
                video.Rating = entry.Rating.Average;
            }
            if (entry.YtRating != null)
            {
                video.LikeCounts    = long.Parse(entry.YtRating.NumLikes);
                video.DislikeCounts = long.Parse(entry.YtRating.NumDislikes);
            }
            video.VideoUrl   = entry.AlternateUri.ToString();
            video.EmbededUrl = string.Format(_embededUrl, entry.VideoId);
            video.Uploader   = entry.Authors[0].Name;

            return(video);
        }