Exemplo n.º 1
0
        /// <summary>
        /// Given the specified <paramref name="metaData"/>, generates proper <see cref="GrabResult"/>.
        /// </summary>
        protected virtual GrabResult GrabUsingConfiguration(Configuration configuration, Uri originalUri)
        {
            var grabList = new List <IGrabbed>();

            // Ensure we have at least one video format available
            if (string.IsNullOrWhiteSpace(configuration?.Request?.Files?.Progressive?.FirstOrDefault().Url))
            {
                return(null);
            }

            if (configuration.Video?.Thumbs != null)
            {
                foreach (var keyValuePair in configuration.Video.Thumbs)
                {
                    var imageType = GrabbedImageType.Thumbnail;
                    if (keyValuePair.Key == "base")
                    {
                        imageType = GrabbedImageType.Primary;
                    }

                    grabList.Add(new GrabbedImage(imageType, null, new Uri(keyValuePair.Value)));
                }
            }

            foreach (var progressive in configuration.Request.Files.Progressive)
            {
                var format = new MediaFormat(progressive.Mime, MimeHelper.ExtractMimeExtension(progressive.Mime));
                var vid    = new GrabbedMedia(new Uri(progressive.Url), null, format, MediaChannels.Both)
                {
                    Resolution = progressive.Quality
                };
                grabList.Add(vid);
            }

            var result = new GrabResult(originalUri, grabList)
            {
                Title = configuration.Video?.Title
            };

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Given the specified <paramref name="metaData"/>, generates proper <see cref="GrabResult"/>.
        /// </summary>
        protected virtual GrabResult GrabUsingMetadata(IDictionary <string, string> metaData)
        {
            var grabList = new List <IGrabbed>();

            // extract metadata
            var title            = metaData.GetOrDefault("og:title");
            var image            = metaData.GetOrDefault("og:image");
            var description      = metaData.GetOrDefault("og:description");
            var originalUri      = new Uri(metaData.GetOrDefault("og:url"));
            var type             = metaData.GetOrDefault("og:type");
            var video            = metaData.GetOrDefault("og:video");
            var video_secure_url = metaData.GetOrDefault("og:video:secure_url");
            var video_type       = metaData.GetOrDefault("og:video:type");
            var video_width      = int.Parse(metaData.GetOrDefault("og:video:width", "0"));
            var video_height     = int.Parse(metaData.GetOrDefault("og:video:height", "0"));

            // grab image
            if (!string.IsNullOrEmpty(image))
            {
                grabList.Add(new GrabbedImage(GrabbedImageType.Primary, null, new Uri(image)));
            }

            // grab video
            if (!string.IsNullOrEmpty(video))
            {
                var format = new MediaFormat(video_type, MimeHelper.ExtractMimeExtension(video_type));
                var vid    = new GrabbedMedia(new Uri(video), null, format, MediaChannels.Both);
                grabList.Add(vid);
            }

            // make result
            var result = new GrabResult(originalUri, grabList)
            {
                Title       = title,
                Description = description,
            };

            return(result);
        }