private void LoadUri() { if (!String.IsNullOrEmpty(YouTubeID)) { imageUri = YouTube.GetThumbnailUri(YouTubeID); UpdateImage(); } else { imageUri = null; } }
/// <summary> /// Return all YouTube videeos /// </summary> /// <returns></returns> private async Task <List <YouTubeVideo> > GetYouTubeVideos() { List <YouTubeVideo> LstVideos = new List <YouTubeVideo>() { new YouTubeVideo { YouTubeId = "J--Zs64jMqw", Title = await YouTube.GetVideoTitleAsync("J--Zs64jMqw"), ThumbnailUri = YouTube.GetThumbnailUri("J--Zs64jMqw", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("J--Zs64jMqw", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "razaRCeATaw", Title = await YouTube.GetVideoTitleAsync("razaRCeATaw"), ThumbnailUri = YouTube.GetThumbnailUri("razaRCeATaw", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("razaRCeATaw", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "eHMUHwXG45s", Title = await YouTube.GetVideoTitleAsync("eHMUHwXG45s"), ThumbnailUri = YouTube.GetThumbnailUri("eHMUHwXG45s", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("eHMUHwXG45s", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "JlnMYbHm3tU", Title = await YouTube.GetVideoTitleAsync("JlnMYbHm3tU"), ThumbnailUri = YouTube.GetThumbnailUri("JlnMYbHm3tU", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("JlnMYbHm3tU", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "QacWskCibnU", Title = await YouTube.GetVideoTitleAsync("QacWskCibnU"), ThumbnailUri = YouTube.GetThumbnailUri("QacWskCibnU", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("QacWskCibnU", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "QlAnthLUa5k", Title = await YouTube.GetVideoTitleAsync("QlAnthLUa5k"), ThumbnailUri = YouTube.GetThumbnailUri("QlAnthLUa5k", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("QlAnthLUa5k", YouTubeQuality.Quality2160P) }, }; return(LstVideos); }
private void btnPlay_Click(object sender, RoutedEventArgs e) { String text = TextBoxURLPath.Text; var YoutubeIdLen = text.LastIndexOf("v="); if (YoutubeIdLen >= 1) { YoutubeId = text.Substring(YoutubeIdLen + 2); var largeImage = new BitmapImage(); //Uri uri = new Uri(imgSrc, UriKind.Absolute); largeImage.UriSource = YouTube.GetThumbnailUri(YoutubeId, YouTubeThumbnailSize.Large); Img.Source = largeImage; } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { var statusbar = StatusBar.GetForCurrentView(); statusbar.BackgroundColor = new Windows.UI.Color() { R = 153, G = 122, B = 165 }; statusbar.BackgroundOpacity = 1; statusbar.ForegroundColor = Windows.UI.Colors.White; } int paramIndex = e.Parameter.ToString().IndexOf("|"); string id = e.Parameter.ToString().Substring(0, paramIndex); MovieTitle = e.Parameter.ToString().Substring(paramIndex + 1); Cast = new ObservableCollection <ExtendedVideoCast>(); IsLoading = true; Genres = ""; try { var movie = await App.Context.Connection.Kodi.VideoLibrary.GetMovieDetailsAsync(int.Parse(id)); Movie = new ExtendedVideoDetailsMovie(movie, false); foreach (var cast in movie.Cast) { Cast.Add(new ExtendedVideoCast(cast)); } Genres = Helpers.Combine(movie.Genre); Director = Helpers.Combine(movie.Director); Studio = Helpers.Combine(movie.Studio); Rating = movie.Rating / 2; Votes = string.Format(_resourceLoader.GetString("/movies/VotesFormat"), movie.Votes); Minutes = movie.Runtime / 60; if (Movie.Movie.ImdbNumber == null) { ButtonSeeImdb.Visibility = Visibility.Collapsed; } TrailerVisibility = Visibility.Collapsed; if (!string.IsNullOrWhiteSpace(Movie.Movie.Trailer)) { TrailerVisibility = Visibility.Visible; Regex regex = new Regex(@"video[_]?id=(?<youtubeId>[^&]*)"); if (regex.IsMatch(Movie.Movie.Trailer)) { Match match = regex.Match(Movie.Movie.Trailer); if (match.Groups["youtubeId"].Success) { string youtubeId = match.Groups["youtubeId"].Value; ImageTrailer = YouTube.GetThumbnailUri(youtubeId); var urlTrailer = await YouTube.GetVideoUriAsync(youtubeId, YouTubeQuality.Quality1080P); PlaybackList = new MediaPlaybackList(); PlaybackList.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromUri(urlTrailer.Uri))); } } } } catch (Exception ex) { App.TrackException(ex); var dialog = new MessageDialog(_resourceLoader.GetString("GlobalErrorMessage"), _resourceLoader.GetString("ApplicationTitle")); await dialog.ShowAsync(); } finally { IsLoading = false; } if (!string.IsNullOrWhiteSpace(Movie?.Movie?.Thumbnail)) { ImageUrl = await Helpers.LoadImageUrl(Movie.Movie.Thumbnail); } if (!string.IsNullOrWhiteSpace(Movie?.Movie?.FanArt)) { FanArt = await Helpers.LoadImageUrl(Movie.Movie.FanArt); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { string movieTitle; string id; int intId; if (!NavigationContext.QueryString.TryGetValue("id", out id) || !NavigationContext.QueryString.TryGetValue("title", out movieTitle) || !int.TryParse(id, out intId)) { if (NavigationService.CanGoBack) { NavigationService.GoBack(); } return; } Cast = new ObservableCollection <ExtendedVideoCast>(); MovieTitle = HttpUtility.UrlDecode(movieTitle); IsLoading = true; Genres = ""; try { var movie = await App.Context.Connection.Xbmc.VideoLibrary.GetMovieDetailsAsync(intId); Movie = new ExtendedVideoDetailsMovie(movie, false); foreach (var cast in movie.Cast.Take(5)) { Cast.Add(new ExtendedVideoCast(cast)); } Genres = Helpers.Combine(movie.Genre); Director = Helpers.Combine(movie.Director); Studio = Helpers.Combine(movie.Studio); Rating = movie.Rating / 2; Votes = string.Format(AppResources.Page_Tv_Shows_Votes_Format, movie.Votes); Minutes = movie.Runtime / 60; if (Movie.Movie.ImdbNumber == null) { ButtonSeeImdb.Visibility = Visibility.Collapsed; } TrailerVisibility = Visibility.Collapsed; if (!string.IsNullOrWhiteSpace(Movie.Movie.Trailer)) { TrailerVisibility = Visibility.Visible; int index = Movie.Movie.Trailer.IndexOf("videoid=", StringComparison.Ordinal); if (index < 0) { index = Movie.Movie.Trailer.IndexOf("video_id=", StringComparison.Ordinal); } _youtubeId = Movie.Movie.Trailer.Substring(index); index = _youtubeId.IndexOf('='); _youtubeId = _youtubeId.Substring(index + 1); ImageTrailer = YouTube.GetThumbnailUri(_youtubeId); } } catch (Exception ex) { App.TrackException(ex); MessageBox.Show(AppResources.Global_Error_Message, AppResources.ApplicationTitle, MessageBoxButton.OK); } finally { IsLoading = false; } if (Movie?.Movie != null && !string.IsNullOrWhiteSpace(Movie.Movie.Thumbnail)) { ImageUrl = await Helpers.LoadImageUrl(Movie.Movie.Thumbnail); } }
public static void Main(string[] args) { string input = "https://www.youtube.com/watch?v=xyvQaVUeu90"; // here 'input' is the URL of youtube video... // you can also assign URL of a video from playlist to 'input'... // 'input' can also be a search query (e.g. input = "windows 10")... string playlistID; string playlistTitle; YouTube youtube = new YouTube(); // create object of YouTube class... switch (youtube.Check(input)) // 'Check(input)' method automatically detects if input is a URL or a search query and returns 'InputType'... { // (e.g. InputType.VideoURL, InputType.PlaylistURL, InputType.SearchQuery, InputType.Invalid)... case YouTube.InputType.VideoURL: foreach (Information information in youtube.Informations(youtube.GetVideoID(input))) { /* * all the information can be retrieved from 'information' object... */ bool adaptive = information.adaptive; // whether the video is in DASH format or not (if the video is in DASH format, value of 'adaptive' will be true)... int itag = information.itag; // itag is a tag assigned by youtube for different resolutions and file formats... string videoID = information.videoID; // unique video id... string title = information.title; // title of the video... string duration = information.duration; // duration of the video... playlistID = information.playlistID; // unique playlist id... string playlistIndex = information.playlistIndex; // index of the video in it's playlist... playlistTitle = information.playlistTitle; // title of the playlist... string resolution = information.resolution; // video quality (e.g. 4K, 2K, Full HD, HD etc)... string fileType = information.fileType; // if the information is about the DASH audio file or video file... string fileSize = information.fileSize; // size of the file... string fileExtension = information.fileExtension; // file extension... string downloadLink = information.downloadLink; // download link of that video... Uri thumbnailUri = youtube.GetThumbnailUri(information.videoID, YouTube.ThumbnailQuality.High); // there are 3 qualities (Low, Medium, High) available for thumbnail... string thumbnailURL = thumbnailUri.ToString(); // to get the URL of the thumbnail... Console.WriteLine(information + "\n"); // also you can just simply print the 'information' object... } break; case YouTube.InputType.PlaylistURL: playlistID = youtube.GetPlaylistID(input); // unique playlist id from PlaylistURL... string playlistPage = youtube.GetPlaylistPage(playlistID); // downloads web page of the playlist as string... playlistTitle = youtube.GetPlaylistTitle(playlistPage); // parses title of the playlist... int playlistVideoCount = youtube.CountPlaylistVideos(playlistPage); // parses the number of videos in a playlist... Console.WriteLine("Playlist Title = " + playlistTitle + "\nVideo(s) = " + playlistVideoCount + "\n"); foreach (string url in youtube.PlaylistURLs(playlistID)) // you will get URLs of all the videos of the playlist... { Console.WriteLine(url); } Console.WriteLine("\n"); foreach (Information information in youtube.PlaylistInformations(playlistID)) { /* * * you can get all the information from 'information' object * just like the previous example... * */ Console.WriteLine(information + "\n"); // also you can just simply print the 'information' object... } break; case YouTube.InputType.SearchQuery: int page = 3; // page must be greater than zero... // here we set 'page = 3' because we want to get the search results from the third page... foreach (string videoID in youtube.Search(page, input)) // you will get URLs of all the videos from the third page of the search result... { Console.WriteLine(youtube.ToVideoURL(videoID)); } break; case YouTube.InputType.Invalid: Console.WriteLine("Invalid input detected..."); break; } Console.ReadKey(); }