replicate alt-text of images

This commit is contained in:
Vincent Cloutier 2023-05-27 15:24:04 -04:00
parent 4def11c2f9
commit d956d49b34
5 changed files with 30 additions and 5 deletions

View file

@ -1,9 +1,14 @@
namespace BirdsiteLive.ActivityPub
using System.Text.Json;
using System.Text.Json.Serialization;
namespace BirdsiteLive.ActivityPub
{
public class Attachment
{
public string type { get; set; }
public string mediaType { get; set; }
public string url { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string name { get; set; }
}
}

View file

@ -137,7 +137,8 @@ namespace BirdsiteLive.Domain
{
type = "Document",
url = x.Url,
mediaType = x.MediaType
mediaType = x.MediaType,
name = x.AltText
};
}).ToArray();
}

View file

@ -4,5 +4,6 @@
{
public string MediaType { get; set; }
public string Url { get; set; }
public string AltText { get; set; }
}
}

View file

@ -272,7 +272,8 @@ namespace BirdsiteLive.Twitter
{
var type = media.GetProperty("type").GetString();
string url = "";
if (type == "video" || type == "animated_gif")
string altText = null;
if (media.TryGetProperty("video_info", out _))
{
var bitrate = -1;
foreach (JsonElement v in media.GetProperty("video_info").GetProperty("variants").EnumerateArray())
@ -291,10 +292,16 @@ namespace BirdsiteLive.Twitter
{
url = media.GetProperty("media_url_https").GetString();
}
if (media.TryGetProperty("ext_alt_text", out JsonElement altNode))
{
altText = altNode.GetString();
}
var m = new ExtractedMedia
{
MediaType = GetMediaType(type, media.GetProperty("media_url_https").GetString()),
MediaType = GetMediaType(type, url),
Url = url,
AltText = altText
};
Media.Add(m);

View file

@ -57,7 +57,7 @@ namespace BirdsiteLive.ActivityPub.Tests
Assert.AreEqual(tweet.Media[0].MediaType, "image/jpeg");
Assert.AreEqual(tweet.Media.Length, 1);
// TODO test alt-text of images
Assert.AreEqual(tweet.Media[0].AltText, "President Obama with Speaker Nancy Pelosi in DC.");
}
[TestMethod]
@ -75,7 +75,18 @@ namespace BirdsiteLive.ActivityPub.Tests
Assert.AreEqual(tweet.Media.Length, 1);
Assert.AreEqual(tweet.Media[0].MediaType, "video/mp4");
Assert.IsNull(tweet.Media[0].AltText);
Assert.IsTrue(tweet.Media[0].Url.StartsWith("https://video.twimg.com/"));
var tweet2 = await _tweetService.GetTweetAsync(1657913781006258178);
Assert.AreEqual(tweet2.MessageContent,
"Coinbase has big international expansion plans\n\nTom Duff Gordon (@tomduffgordon), VP of International Policy @coinbase has the deets");
Assert.AreEqual(tweet2.Media.Length, 1);
Assert.AreEqual(tweet2.Media[0].MediaType, "video/mp4");
Assert.IsNull(tweet2.Media[0].AltText);
Assert.IsTrue(tweet2.Media[0].Url.StartsWith("https://video.twimg.com/"));
}
[Ignore]