示例#1
0
        public bool TryGetReplacement(string remoteUrl, string pageTitle, string favicon, out UrlReplacement replacement)
        {
            replacement = null;

            var match = Regex.Match(remoteUrl, @"(?:https?:\/\/)?(?:www\.)?(?:(?:(?:youtube.com\/watch\?[^?]*v=|youtu.be\/)([\w\-]+))(?:[^\s?]+)?)", RegexOptions.Compiled | RegexOptions.Multiline);

            if (match.Success)
            {
                var videoId      = match.Groups[1].Value;
                var videoElement = $"<iframe type='text/html' title='YouTube video player' class='youtubePlayer' src='https://www.youtube.com/embed/{videoId}?rel=0' frameborder='0' allowfullscreen='1'></iframe>";

                replacement = new UrlReplacement {
                    ReplacementText = $"<a target='_blank' href='{remoteUrl}'>{favicon}{pageTitle}</a>",
                    Card            = $"<div class='embedded-video'>{videoElement}</div>"
                };
            }

            return(!(replacement is null));
        }
示例#2
0
        public bool TryGetReplacement(string remoteUrl, string pageTitle, string favicon, out UrlReplacement replacement)
        {
            replacement = null;

            var albumMatch   = Regex.Match(remoteUrl, @"imgur.com\/a\/([a-zA-Z0-9]+)?", RegexOptions.Compiled | RegexOptions.Multiline);
            var galleryMatch = Regex.Match(remoteUrl, @"imgur.com\/gallery\/([a-zA-Z0-9]+)?", RegexOptions.Compiled | RegexOptions.Multiline);
            var imageMatch   = Regex.Match(remoteUrl, @"imgur.com\/([a-zA-Z0-9]+)?", RegexOptions.Compiled | RegexOptions.Multiline);

            if (albumMatch.Success)
            {
                var hash = albumMatch.Groups[1].Value;
                replacement = GetReplacementForAlbum(hash, favicon);
            }
            else if (galleryMatch.Success)
            {
                var topLevelGalleries = new List <string> {
                    "hot", "top", "user"
                };
                var hash = galleryMatch.Groups[1].Value;

                // We can't process top level galleries yet.
                if (!topLevelGalleries.Contains(hash))
                {
                    replacement = GetReplacementForGalleryAlbum(hash, favicon);
                }
            }
            else if (imageMatch.Success)
            {
                var hash = imageMatch.Groups[1].Value;
                replacement = GetReplacementForImage(hash, favicon);
            }

            if (replacement is null)
            {
                return(false);
            }

            return(true);
        }