Пример #1
0
        public async Task <IUrlReplacement> GetReplacement(string remoteUrl, string favicon)
        {
            var isReaction = remoteUrl.Contains("?forum-reaction");

            if (isReaction)
            {
                remoteUrl = Regex.Replace(remoteUrl, @"\?forum-reaction", string.Empty);
            }

            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);
            var favoriteMatch = Regex.Match(remoteUrl, @"imgur.com\/.+favorites.+\/([a-zA-Z0-9]+)?$", RegexOptions.Compiled | RegexOptions.Multiline);

            IUrlReplacement replacement = null;

            if (albumMatch.Success)
            {
                var hash = albumMatch.Groups[1].Value;
                replacement = await 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 = await GetReplacementForGalleryAlbum(hash, favicon);
                }
            }
            else if (imageMatch.Success)
            {
                var hash = imageMatch.Groups[1].Value;
                replacement = await GetReplacementForImage(hash, favicon, isReaction);
            }
            else if (favoriteMatch.Success)
            {
                var hash = favoriteMatch.Groups[1].Value;
                replacement = await GetReplacementForImage(hash, favicon, isReaction);
            }

            return(replacement);
        }
Пример #2
0
		public IUrlReplacement GetReplacement(string remoteUrl, string pageTitle, string favicon) {
			IUrlReplacement 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 YouTubeUrlReplacement {
					ReplacementText = $"<a target='_blank' href='{remoteUrl}'>{favicon}{pageTitle}</a>",
					Card = $"<div class='embedded-video'>{videoElement}</div>"
				};
			}

			return replacement;
		}