mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-16 20:02:42 +00:00
Add support for Twitch embed projections (#1199)
This commit is contained in:
@@ -31,6 +31,9 @@ public partial record Embed(
|
||||
public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() =>
|
||||
SpotifyTrackEmbedProjection.TryResolve(this);
|
||||
|
||||
public TwitchClipEmbedProjection? TryGetTwitchClip() =>
|
||||
TwitchClipEmbedProjection.TryResolve(this);
|
||||
|
||||
public YouTubeVideoEmbedProjection? TryGetYouTubeVideo() =>
|
||||
YouTubeVideoEmbedProjection.TryResolve(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
public partial record TwitchClipEmbedProjection(string ClipId)
|
||||
{
|
||||
public string Url => $"https://clips.twitch.tv/embed?clip={ClipId}&parent=localhost";
|
||||
}
|
||||
|
||||
public partial record TwitchClipEmbedProjection
|
||||
{
|
||||
private static string? TryParseClipId(string embedUrl)
|
||||
{
|
||||
// https://clips.twitch.tv/SpookyTenuousPidgeonPanicVis
|
||||
{
|
||||
var clipId = Regex
|
||||
.Match(embedUrl, @"clips\.twitch\.tv/(.*?)(?:\?|&|/|$)")
|
||||
.Groups[1]
|
||||
.Value;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(clipId))
|
||||
return clipId;
|
||||
}
|
||||
|
||||
// https://twitch.tv/clip/SpookyTenuousPidgeonPanicVis
|
||||
{
|
||||
var clipId = Regex
|
||||
.Match(embedUrl, @"twitch\.tv/clip/(.*?)(?:\?|&|/|$)")
|
||||
.Groups[1]
|
||||
.Value;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(clipId))
|
||||
return clipId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TwitchClipEmbedProjection? TryResolve(Embed embed)
|
||||
{
|
||||
if (embed.Kind != EmbedKind.Video)
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(embed.Url))
|
||||
return null;
|
||||
|
||||
var clipId = TryParseClipId(embed.Url);
|
||||
if (string.IsNullOrWhiteSpace(clipId))
|
||||
return null;
|
||||
|
||||
return new TwitchClipEmbedProjection(clipId);
|
||||
}
|
||||
}
|
||||
@@ -365,6 +365,15 @@
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
// Twitch embed
|
||||
else if (embed.TryGetTwitchClip() is { } twitchClipEmbed)
|
||||
{
|
||||
<div class="chatlog__embed">
|
||||
<div class="chatlog__embed-twitch-container">
|
||||
<iframe class="chatlog__embed-twitch" src="@twitchClipEmbed.Url" width="400" height="225"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
// YouTube embed
|
||||
else if (embed.TryGetYouTubeVideo() is { } youTubeVideoEmbed)
|
||||
{
|
||||
|
||||
@@ -702,6 +702,10 @@
|
||||
.chatlog__embed-spotify {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.chatlog__embed-twitch {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.chatlog__embed-youtube-container {
|
||||
margin-top: 0.6rem;
|
||||
|
||||
Reference in New Issue
Block a user