Example #1
0
        public static TimeSpan GetDailyMotionVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait)
        {
            chrome.Url = $"https://www.dailymotion.com/embed/video/{video_id}";
            dynamic length;

            try
            {
                wait.UntilElementIsVisible(By.CssSelector("button[aria-label*=\"Playback\"]")).Click();
                length = wait.UntilElementIsVisible(By.CssSelector("span[aria-label*=\"Duration\"]")).Text;
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #2
0
        public static TimeSpan GetKanopyLinkLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc)
        {
            chrome.Url = $"https://byu.kanopy.com/video/{video_id}";
            dynamic length;

            try
            {
                wait.UntilElementIsVisible(By.CssSelector("button.vjs-big-play-button")).Click();
                length = wait.UntilElementIsVisible(By.CssSelector("div.vjs-remaining-time-display"))
                         .Text
                         .Split('-')
                         .Where(s => !string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s))
                         .LastOrDefault();
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
                cc     = false;
                return(new TimeSpan(0));
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            cc     = wait.UntilElementIsVisible(By.CssSelector("span[data-title='Press play to launch the captions")).Displayed;
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #3
0
        public static TimeSpan GetAlexanderStreenLinkLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc)
        {
            chrome.Url = $"https://search.alexanderstreet.com/view/work/bibliographic_entity|video_work|{video_id}";
            dynamic length;

            try
            {
                length = wait.UntilElementIsVisible(By.CssSelector("span.fulltime")).Text;
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
                cc     = false;
                return(new TimeSpan(0));
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            cc     = wait.UntilElementIsVisible(By.CssSelector("ul.tabs")).Text.ToLower().Contains("transcript");
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #4
0
        public static TimeSpan GetVimeoVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait)
        {
            chrome.Url = $"https://player.vimeo.com/video/{video_id}";
            dynamic length;

            try
            {
                length = wait.UntilElementIsVisible(By.CssSelector("div.timecode")).Text;
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #5
0
        public static TimeSpan GetBYUMediaSiteVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc)
        {
            chrome.Url = $"https://byu.mediasite.com/Mediasite/Play/{video_id}";
            dynamic length = null;

            try
            {
                wait.UntilElementIsVisible(By.CssSelector(".play-button")).Click();
                while ("0:00" == length || "" == length || null == length)
                {
                    length = wait.UntilElementIsVisible(By.CssSelector("span[class*=\"duration\"]")).Text;
                }
            }
            catch
            {
                try
                {
                    while ("0:00" == length || "" == length || null == length)
                    {
                        length = wait.UntilElementIsVisible(By.CssSelector("span[class*=\"duration\"]")).Text;
                    }
                }
                catch
                {
                    Console.WriteLine("Video not found");
                    length = "00:00";
                    cc     = false;
                    return(new TimeSpan(0));
                }
            }

            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            cc     = wait.UntilElementExist(By.CssSelector("button.cc.ui-button")).GetAttribute("aria-disabled") == "false" ? true : false;
            if (!TimeSpan.TryParseExact(length, "hh':'mm':'ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #6
0
        public static TimeSpan GetPanoptoVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc)
        {
            chrome.Url = $"https://byu.hosted.panopto.com/Panopto/Pages/Embed.aspx?id={video_id}&amp;v=1";
            while ((string)chrome.ExecuteScript("return document.readyState") != "complete")
            {
            }
            ;
            dynamic length = null;

            try
            {
                while (chrome.FindElementsByCssSelector("[id=copyrightNoticeContainer]").FirstOrDefault().Displayed)
                {
                }
                ;
                wait.UntilElementIsVisible(By.CssSelector("div#title"));
                wait.UntilElementIsVisible(By.CssSelector("div#playIconContainer")).Click();

                length = wait.UntilElementIsVisible(By.CssSelector("span[class*=\"duration\"]")).Text;
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
                cc     = false;
                return(new TimeSpan(0));
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            cc     = !wait.UntilElementExist(By.CssSelector("div.fp-menu.fp-subtitle-menu")).GetAttribute("outerHTML").ToLower().Contains("no subtitles");
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #7
0
        public static TimeSpan GetFacebookVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait)
        {
            chrome.Url = $"https://www.facebook.com/video/embed?video_id={video_id}";
            dynamic length;

            try
            {
                wait.UntilElementIsVisible(By.CssSelector("img")).Click();
                length = wait.UntilElementIsVisible(By.CssSelector("div[playbackdurationtimestamp]")).Text.Replace('-', '0');
            }
            catch
            {
                try
                {
                    //If that didn't work then try refreshing the page (I kept running into false negatives) and try again
                    chrome.Navigate().Refresh();
                    wait.UntilElementIsVisible(By.CssSelector("img")).Click();
                    length = wait.UntilElementIsVisible(By.CssSelector("div[playbackdurationtimestamp]")).Text.Replace('-', '0');
                }
                catch
                {
                    Console.WriteLine("Video not found");
                    length = "00:00";
                }
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #8
0
        public static TimeSpan GetPanoptoVideoViewerLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc)
        {
            chrome.Url = $"https://byu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?tid={video_id}";
            while ((string)chrome.ExecuteScript("return document.readyState") != "complete")
            {
            }
            ;
            dynamic length = null;

            try
            {
                length = wait.UntilElementIsVisible(By.CssSelector("div#timeRemaining")).Text.Replace("-", "");
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
                cc     = false;
                return(new TimeSpan(0));
            }
            if ((length as string).Length < 5)
            {
                length = "0" + length;
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            cc     = wait.UntilElementIsVisible(By.CssSelector("div#transcriptTabHeader")).Enabled;
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }
Example #9
0
        public static TimeSpan GetBrightcoveVideoLength(string video_id, ChromeDriver chrome, WebDriverWait wait, out bool cc, out string text)
        {
            chrome.Url = $"https://studio.brightcove.com/products/videocloud/media/videos/search/{video_id}";
            string length;

            text = "";
            try
            {
                length = wait.UntilElementIsVisible(By.CssSelector("div[class*=\"Thumbnail\"]")).Text;
            }
            catch
            {
                Console.WriteLine("Video not found");
                length = "00:00";
                cc     = false;
                return(new TimeSpan(0));
            }
            if ((length as string).Count(c => c == ':') < 2)
            {
                length = "00:" + length;
            }
            length = (length as string).RollOverTime();
            try
            {
                chrome.FindElementsByCssSelector("div.name").Where(c => c.Text.Contains(video_id)).FirstOrDefault().FindElement(By.TagName("a")).Click();
                cc = !wait.UntilElementExist(By.CssSelector("section#textTracksPanel")).Text.Contains("There are no text tracks");
            }
            catch
            {
                cc = false;
            }
            try
            {
                var NameElement = wait.UntilElementExist(By.CssSelector("div[id*=\"video-name\"]"));
                text = "\nVideo name: " + NameElement.Text;
            }
            catch
            {
                text = "\nFailed to find video name";
            }
            if (!TimeSpan.TryParseExact(length, @"h\:mm\:ss", null, out TimeSpan video_length))
            {
                return(new TimeSpan(0));
            }
            return(video_length);
        }