From 1d584b0df3ee768f85eaf19a1c269e2c02f4ad67 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 13 Jan 2021 23:57:48 -0500 Subject: [PATCH] expand URL, fix #31 --- src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs | 4 ++++ src/BirdsiteLive.Twitter/TwitterService.cs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs index 2cb7dde..1d27ddb 100644 --- a/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs +++ b/src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs @@ -45,6 +45,10 @@ namespace BirdsiteLive.Twitter.Extractors message = message.Replace("RT", "[RT]"); } + // Expand URLs + foreach (var url in tweet.Urls.OrderByDescending(x => x.URL.Length)) + message = message.Replace(url.URL, url.ExpandedURL); + return message; } diff --git a/src/BirdsiteLive.Twitter/TwitterService.cs b/src/BirdsiteLive.Twitter/TwitterService.cs index 47f799c..b4fdd92 100644 --- a/src/BirdsiteLive.Twitter/TwitterService.cs +++ b/src/BirdsiteLive.Twitter/TwitterService.cs @@ -43,11 +43,16 @@ namespace BirdsiteLive.Twitter _statisticsHandler.CalledUserApi(); if (user == null) return null; + // Expand URLs + var description = user.Description; + foreach (var descriptionUrl in user.Entities?.Description?.Urls?.OrderByDescending(x => x.URL.Length)) + description = description.Replace(descriptionUrl.URL, descriptionUrl.ExpandedURL); + return new TwitterUser { Acct = username, Name = user.Name, - Description = user.Description, + Description = description, Url = $"https://twitter.com/{username}", ProfileImageUrl = user.ProfileImageUrlFullSize, ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps,