Ejemplo n.º 1
0
        /// <summary>
        /// Get youtube video depending of choosen quality settings
        /// </summary>
        /// <param name="videosToProcess">List of VideoInfo</param>
        /// <param name="quality">The youtube quality settings</param>
        /// <returns>The trailer's video info</returns>
        private VideoInfo GetVideoByStreamingQuality(IEnumerable <VideoInfo> videosToProcess,
                                                     Constants.YoutubeStreamingQuality quality)
        {
            while (true)
            {
                var videos = videosToProcess.ToList(); // Prevent multiple enumeration

                if (quality == Constants.YoutubeStreamingQuality.High)
                {
                    // Choose high quality Youtube video
                    return(videos.OrderByDescending(x => x.Resolution).FirstOrDefault());
                }

                // Pick the video with the requested quality settings
                var preferredResolutions = StreamingQualityMap[quality];

                var preferredVideos =
                    videos.Where(info => preferredResolutions.Contains(info.Resolution))
                    .OrderByDescending(info => info.Resolution);

                var video = preferredVideos.FirstOrDefault();

                if (video != null)
                {
                    return(video);
                }
                videosToProcess = videos;
                quality         = (Constants.YoutubeStreamingQuality)(((int)quality) - 1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get VideoInfo of a youtube video
        /// </summary>
        /// <param name="youtubeLink">The youtube link of a movie</param>
        /// <param name="qualitySetting">The youtube quality settings</param>
        private async Task <VideoInfo> GetVideoInfoForStreamingAsync(string youtubeLink,
                                                                     Constants.YoutubeStreamingQuality qualitySetting)
        {
            // Get video infos of the requested video
            var videoInfos = await Task.Run(() => DownloadUrlResolver.GetDownloadUrls(youtubeLink, false));

            // We only want video matching criterias : only mp4 and no adaptive
            var filtered = videoInfos
                           .Where(info => info.VideoType == VideoType.Mp4 && !info.Is3D && info.AdaptiveType == AdaptiveType.None);

            return(GetVideoByStreamingQuality(filtered, qualitySetting));
        }