Exemple #1
0
        public static void getVideoInfo(YouTubeVideo video)
        {
            var videoRequest = auth().Videos.List("snippet");

            videoRequest.Id = video.id;

            var response = videoRequest.Execute();

            if (response.Items.Count > 0)
            {
                video.title         = response.Items[0].Snippet.Title;
                video.description   = response.Items[0].Snippet.Description;
                video.publishedDate = response.Items[0].Snippet.PublishedAt.Value;
            }
            else
            {
                Console.WriteLine("ERROR: Video not found!");
                //Video not found..
            }

            videoRequest = auth().Videos.List("contentDetails");

            videoRequest.Id = video.id;

            response = videoRequest.Execute();
            if (response.Items.Count > 0)
            {
                string   tmp    = response.Items[0].ContentDetails.Duration;
                TimeSpan t      = TimeSpan.FromSeconds(System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds);
                string   answer = string.Format("{1:D2}:{2:D2}",
                                                t.Hours,
                                                t.Minutes,
                                                t.Seconds,
                                                t.Milliseconds);
                video.duration    = answer;
                video.rawDuration = (int)System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds;
            }
            else
            {
                Console.WriteLine("ERROR: Video duration not found!");
                //Video not found..
            }
        }
Exemple #2
0
        public static void getVideoInfo(YouTubeVideo video)
        {
            var videoRequest = auth().Videos.List("snippet");

            videoRequest.Id = video.id;

            var response = videoRequest.Execute();

            if (response.Items.Count > 0)
            {
                video.title         = response.Items[0].Snippet.Title;
                video.description   = response.Items[0].Snippet.Description;
                video.duration      = "" + response.Items[0].FileDetails.DurationMs * 1000;
                video.publishedDate = response.Items[0].Snippet.PublishedAt.Value;
            }
            else
            {
                //Video not found..
            }
        }