fix video embeds
This commit is contained in:
parent
2290c2a121
commit
97f982903e
2 changed files with 37 additions and 4 deletions
|
@ -224,10 +224,31 @@ namespace BirdsiteLive.Twitter
|
||||||
{
|
{
|
||||||
foreach (JsonElement media in extendedEntities.GetProperty("media").EnumerateArray())
|
foreach (JsonElement media in extendedEntities.GetProperty("media").EnumerateArray())
|
||||||
{
|
{
|
||||||
|
var type = media.GetProperty("type").GetString();
|
||||||
|
string url = "";
|
||||||
|
if (type == "video")
|
||||||
|
{
|
||||||
|
var bitrate = 0;
|
||||||
|
foreach (JsonElement v in media.GetProperty("video_info").GetProperty("variants").EnumerateArray())
|
||||||
|
{
|
||||||
|
if (v.GetProperty("content_type").GetString() != "video/mp4")
|
||||||
|
continue;
|
||||||
|
int vBitrate = v.GetProperty("bitrate").GetInt32();
|
||||||
|
if (vBitrate > bitrate)
|
||||||
|
{
|
||||||
|
bitrate = vBitrate;
|
||||||
|
url = v.GetProperty("url").GetString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
url = media.GetProperty("media_url_https").GetString();
|
||||||
|
}
|
||||||
var m = new ExtractedMedia
|
var m = new ExtractedMedia
|
||||||
{
|
{
|
||||||
MediaType = GetMediaType(media.GetProperty("type").GetString(), media.GetProperty("media_url_https").GetString()),
|
MediaType = GetMediaType(type, media.GetProperty("media_url_https").GetString()),
|
||||||
Url = media.GetProperty("media_url_https").GetString(),
|
Url = url,
|
||||||
};
|
};
|
||||||
Media.Add(m);
|
Media.Add(m);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace BirdsiteLive.ActivityPub.Tests
|
||||||
{
|
{
|
||||||
var logger1 = new Mock<ILogger<TwitterAuthenticationInitializer>>(MockBehavior.Strict);
|
var logger1 = new Mock<ILogger<TwitterAuthenticationInitializer>>(MockBehavior.Strict);
|
||||||
var logger2 = new Mock<ILogger<TwitterUserService>>(MockBehavior.Strict);
|
var logger2 = new Mock<ILogger<TwitterUserService>>(MockBehavior.Strict);
|
||||||
var logger3 = new Mock<ILogger<TwitterTweetsService>>(MockBehavior.Strict);
|
var logger3 = new Mock<ILogger<TwitterTweetsService>>();
|
||||||
var stats = new Mock<ITwitterStatisticsHandler>();
|
var stats = new Mock<ITwitterStatisticsHandler>();
|
||||||
ITwitterAuthenticationInitializer auth = new TwitterAuthenticationInitializer(logger1.Object);
|
ITwitterAuthenticationInitializer auth = new TwitterAuthenticationInitializer(logger1.Object);
|
||||||
ITwitterUserService user = new TwitterUserService(auth, stats.Object, logger2.Object);
|
ITwitterUserService user = new TwitterUserService(auth, stats.Object, logger2.Object);
|
||||||
|
@ -37,7 +37,8 @@ namespace BirdsiteLive.ActivityPub.Tests
|
||||||
var tweet = await _tweetService.GetTweetAsync(1593344577385160704);
|
var tweet = await _tweetService.GetTweetAsync(1593344577385160704);
|
||||||
Assert.AreEqual(tweet.MessageContent, "Speaker Nancy Pelosi will go down as one of most accomplished legislators in American history—breaking barriers, opening doors for others, and working every day to serve the American people. I couldn’t be more grateful for her friendship and leadership.");
|
Assert.AreEqual(tweet.MessageContent, "Speaker Nancy Pelosi will go down as one of most accomplished legislators in American history—breaking barriers, opening doors for others, and working every day to serve the American people. I couldn’t be more grateful for her friendship and leadership.");
|
||||||
|
|
||||||
// TODO validate media type and length
|
// TODO validate media type
|
||||||
|
Assert.AreEqual(tweet.Media.Length, 1);
|
||||||
// TODO test alt-text of images
|
// TODO test alt-text of images
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,5 +48,16 @@ namespace BirdsiteLive.ActivityPub.Tests
|
||||||
var tweet = await _tweetService.GetTweetAsync(1602618920996945922);
|
var tweet = await _tweetService.GetTweetAsync(1602618920996945922);
|
||||||
Assert.AreEqual(tweet.MessageContent, "#Linux 6.2 Expands Support For More #Qualcomm #Snapdragon SoCs, #Apple M1 Pro/Ultra/Max\n\nhttps://www.phoronix.com/news/Linux-6.2-Arm-SoC-Updates");
|
Assert.AreEqual(tweet.MessageContent, "#Linux 6.2 Expands Support For More #Qualcomm #Snapdragon SoCs, #Apple M1 Pro/Ultra/Max\n\nhttps://www.phoronix.com/news/Linux-6.2-Arm-SoC-Updates");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task SimpleTextAndSingleVideoTweet()
|
||||||
|
{
|
||||||
|
var tweet = await _tweetService.GetTweetAsync(1604231025311129600);
|
||||||
|
Assert.AreEqual(tweet.MessageContent, "Falcon 9’s first stage has landed on the Just Read the Instructions droneship, completing the 15th launch and landing of this booster!");
|
||||||
|
|
||||||
|
Assert.AreEqual(tweet.Media.Length, 1);
|
||||||
|
Assert.AreEqual(tweet.Media[0].MediaType, "video/mp4");
|
||||||
|
Assert.IsTrue(tweet.Media[0].Url.StartsWith("https://video.twimg.com/"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue