예제 #1
0
 public void initData(VideoBase currentVideo)
 {
     commentSource = new CommentsSource();
     videoId = currentVideo.VID;
     this.Title = currentVideo.TITLE;
     updateComment();
 }
예제 #2
0
 private void getRelatedVideo(VideoBase video)
 {
     BackgroundWorker getRelatedBw = new BackgroundWorker();
     getRelatedBw = new BackgroundWorker();
     getRelatedBw.DoWork += new DoWorkEventHandler(getRelatedBw_DoWork);
     getRelatedBw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(getRelatedBw_Completed);
     if (getRelatedBw.IsBusy != true)
     {
         List<object> arguments = new List<object>();
         arguments.Add(video);
         getRelatedBw.RunWorkerAsync(arguments);
     }
 }
예제 #3
0
 public static List<VideoBase> GetRelatedVideos(VideoBase vid)
 {
     List<VideoBase> list = new List<VideoBase>();
     try
     {
         YouTubeRequest ytRequest = new YouTubeRequest(new YouTubeRequestSettings(APP_NAME, DEV_KEY));
         Feed<Video> vid_feed = ytRequest.Get<Video>(new Uri(@"https://gdata.youtube.com/feeds/api/videos/" + vid.VID + "/related?v=2"));
         foreach (Video video in vid_feed.Entries)
         {
             VideoBase baseVideo = ConvertToVideoBase(video);
             list.Add(baseVideo);
         }
     }
     catch
     {
     }
     return list;
 }
예제 #4
0
        public static VideoBase ConvertToVideoBase(Video video)
        {
            VideoBase vid = new VideoBase();
            try
            {
                vid.TITLE = video.Title;
                if (video.WatchPage != null)
                {
                    vid.LINK = video.WatchPage.ToString();
                }
                else if (video.VideoId != null)
                {
                    vid.LINK = video.VideoId;
                }
                vid.VIEW_COUNT = video.ViewCount;
                vid.COMMENT_COUNT = video.CommmentCount;
                double totalSecond = double.Parse(video.YouTubeEntry.Duration.Seconds);
                TimeSpan t = TimeSpan.FromSeconds(totalSecond);
                if (totalSecond < 59 * 60) vid.DURATION = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
                else vid.DURATION = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds);
                vid.DESCRIPTION = video.Description;

                vid.VID = video.VideoId;
                MediaThumbnail[] thumbs = video.Thumbnails.ToArray();
                List<string> tempThumbs = new List<string>();
                for (int i = 0; i < thumbs.Length; i++)
                {
                    tempThumbs.Add(thumbs[i].Url);
                }
                vid.THUMBNAILS = tempThumbs;

                AtomCategory[] cates = video.Categories.ToArray();
                List<string> tempCates = new List<string>();
                for (int i = 0; i < cates.Length; i++)
                {
                    tempCates.Add(cates[i].Label);
                }
                vid.CATEGORIES = tempCates;
                if (video.YouTubeEntry.YtRating != null && video.YouTubeEntry.YtRating.NumLikes != null) vid.LIKE = video.YouTubeEntry.YtRating.NumLikes;
                else vid.LIKE = "";
                if (video.YouTubeEntry.YtRating != null && video.YouTubeEntry.YtRating.NumDislikes != null) vid.DISLIKE = video.YouTubeEntry.YtRating.NumDislikes;
                else vid.DISLIKE = "";
                if (video.YouTubeEntry.Rating != null)
                {
                    Dictionary<string, double> rating = new Dictionary<string, double>();
                    rating.Add("NumRaters", video.YouTubeEntry.Rating.NumRaters);
                    rating.Add("Min", video.YouTubeEntry.Rating.Min);
                    rating.Add("Max", video.YouTubeEntry.Rating.Max);
                    rating.Add("Average", video.YouTubeEntry.Rating.Average);
                    vid.RATING = rating;
                }

                vid.AUTHOR = video.YouTubeEntry.Authors.ToString();
            }
            catch
            {
            }
            return vid;
        }