public static YoutubeVideo FromSingleVideo(string uri) { var uriConverter = new UriConverter(new WebClientImpl()); var videoId = uriConverter.GetVideoId(uri); var gdataUri = uriConverter.FromYoutubeVideoToGDataVideo(videoId); var webClient = new WebClientImpl(); var responseXml = webClient.DownloadString(gdataUri); var responseDocument = XDocument.Parse(responseXml, LoadOptions.SetBaseUri); XNamespace atom = "http://www.w3.org/2005/Atom"; var titleElement = responseDocument.Root.Element(atom + "title"); var videoTitle = titleElement != null ? titleElement.Value : string.Empty; var flvUri = uriConverter.GetFlvUriFromYoutubeVideoUri(videoId); return string.IsNullOrEmpty(flvUri) ? null : new YoutubeVideo { FlvUri = flvUri, Link = uri, Title = videoTitle }; }
public LocalFlvFile DownloadAndSaveAsTempFile(YoutubeVideo youTubeVideo) { youTubeVideo.ThrowIfNull("youTubeVideo"); var localFile = new LocalFlvFile { FileName = GetTempFileNameWithExtension("flv") }; var webClient = new WebClientImpl(); webClient.DownloadFile(youTubeVideo.FlvUri, localFile.FileName, _stateNotifier.SetProgress); return localFile; }
public void GetContentsOfYoutubePage() { var videoUri = "http://www.youtube.com/watch?v=6mgZZ3og1g0&feature=PlayList&p=C8DD769C19089393&index=5"; var webClient = new WebClientImpl(); var youtubePageData = webClient.DownloadString(videoUri); Assert.IsFalse(string.IsNullOrEmpty(youtubePageData)); Assert.IsTrue(youtubePageData.Length > 0); }