Skip to content

Commit

Permalink
Add 7tv emotes support (#193)
Browse files Browse the repository at this point in the history
* feat: add 7tv support (probably)

* Add 7tv and it's cli argument to README's

Also in main README make the cli README link relative

* Add missing pieces to 7tv support

It should now fully support 7tv emotes
  • Loading branch information
IS2511 authored Jul 2, 2021
1 parent afcfefa commit 4ea57e6
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Twitch VOD/Clip/Chat downloader and chat renderer I wrote.
- Download Twitch VODs
- Download Twitch Clips
- Download chat for VODS and Clips, in either a [JSON with all the information](https://pastebin.com/raw/YDgRe6X4) or a [simple text file](https://pastebin.com/raw/016azeQX)
- Use a previously generated JSON chat file to render the chat with FFZ and BTTV support (including GIFS)
- Use a previously generated JSON chat file to render the chat with FFZ, BTTV and 7TV support (including GIFS)

## Things still to be done
- Fix bugs that slipped by
Expand All @@ -32,7 +32,7 @@ Sorry, the GUI version is only avaliable for Windows :(

The CLI is cross platform and performs the main functions of the program. It works on Windows and Linux, but has not been tested on MacOS.

[Documentation here](https://github.com/lay295/TwitchDownloader/blob/master/TwitchDownloaderCLI/README.md).
[Documentation here](TwitchDownloaderCLI/README.md).

I've never really made a command line utility before so things may change in the future. If you're on Linux, make sure `fontconfig` and `libfontconfig1` are installed `(apt-get install fontconfig libfontconfig1)`.

Expand Down
2 changes: 2 additions & 0 deletions TwitchDownloaderCLI/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Options
public bool BttvEmotes { get; set; }
[Option("ffz", Default = true, HelpText = "Enable FFZ emotes in chat render.")]
public bool FfzEmotes { get; set; }
[Option("stv", Default = true, HelpText = "Enable 7tv emotes in chat render.")]
public bool StvEmotes { get; set; }
[Option("outline", Default = false, HelpText = "Enable outline in chat render.")]
public bool Outline { get; set; }
[Option("sub-messages", Default = true, HelpText = "Enable sub messages.")]
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private static void RenderChat(Options inputOptions)
renderOptions.ChatWidth = inputOptions.ChatWidth;
renderOptions.BttvEmotes = inputOptions.BttvEmotes;
renderOptions.FfzEmotes = inputOptions.FfzEmotes;
renderOptions.StvEmotes = inputOptions.StvEmotes;
renderOptions.Outline = inputOptions.Outline;
renderOptions.OutlineSize = inputOptions.OutlineSize;
renderOptions.Font = inputOptions.Font;
Expand Down
3 changes: 3 additions & 0 deletions TwitchDownloaderCLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Path to JSON chat file input.
**-\-ffz**
(Default: true) Enable FFZ emotes.

**-\-stv**
(Default: true) Enable 7TV emotes.

**-\-sub-messages**
(Default: true) Enable sub/re-sub messages.

Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task RenderVideoAsync(IProgress<ProgressReport> progress, Cancellat
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Emotes" });
List<TwitchEmote> chatEmotes = await Task.Run(() => TwitchHelper.GetEmotes(chatJson.comments, cacheFolder, chatJson.emotes, true));
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching 3rd Party Emotes" });
List<TwitchEmote> thirdPartyEmotes = await Task.Run(() => TwitchHelper.GetThirdPartyEmotes(chatJson.streamer.id, cacheFolder, chatJson.emotes, renderOptions.BttvEmotes, renderOptions.FfzEmotes));
List<TwitchEmote> thirdPartyEmotes = await Task.Run(() => TwitchHelper.GetThirdPartyEmotes(chatJson.streamer.id, cacheFolder, chatJson.emotes, renderOptions.BttvEmotes, renderOptions.FfzEmotes, renderOptions.StvEmotes));
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Cheer Emotes" });
List<CheerEmote> cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder));
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Emojis" });
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCore/Options/ChatRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ChatRenderOptions
public int ChatWidth { get; set; }
public bool BttvEmotes { get; set; }
public bool FfzEmotes { get; set; }
public bool StvEmotes { get; set; }
public bool Outline { get; set; }
public double OutlineSize { get; set; }
public string Font { get; set; }
Expand Down
60 changes: 59 additions & 1 deletion TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ public static async Task<JArray> GetClipLinks(object clipId)
}
}

public static List<TwitchEmote> GetThirdPartyEmotes(int streamerId, string cacheFolder, Emotes embededEmotes = null, bool bttv = true, bool ffz = true)
public static List<TwitchEmote> GetThirdPartyEmotes(int streamerId, string cacheFolder, Emotes embededEmotes = null, bool bttv = true, bool ffz = true, bool stv = true)
{
List<TwitchEmote> returnList = new List<TwitchEmote>();
List<string> alreadyAdded = new List<string>();

string bttvFolder = Path.Combine(cacheFolder, "bttv");
string ffzFolder = Path.Combine(cacheFolder, "ffz");
string stvFolder = Path.Combine(cacheFolder, "stv");

if (embededEmotes != null)
{
Expand Down Expand Up @@ -245,6 +246,63 @@ public static List<TwitchEmote> GetThirdPartyEmotes(int streamerId, string cache
}
catch { }
}

if (stv)
{
if (!Directory.Exists(stvFolder))
Directory.CreateDirectory(stvFolder);

//Global 7tv Emotes
JArray STV = JArray.Parse(client.DownloadString("https://api.7tv.app/v2/emotes/global"));
foreach (var emote in STV)
{
string id = emote["id"].ToString();
string name = emote["name"].ToString();
string url2x = emote["urls"][1][1].ToString(); // 2x
if (alreadyAdded.Contains(name))
continue;
byte[] bytes;
string fileName = Path.Combine(stvFolder, id + "_2x.png");
if (File.Exists(fileName))
bytes = File.ReadAllBytes(fileName);
else
{
bytes = client.DownloadData(url2x);
File.WriteAllBytes(fileName, bytes);
}

MemoryStream ms = new MemoryStream(bytes);
returnList.Add(new TwitchEmote(new List<SKBitmap>() { SKBitmap.Decode(bytes) }, SKCodec.Create(ms), name, emote["mime"].ToString().Split('/')[1], id, 2, bytes));
alreadyAdded.Add(name);
}

//Channel specific 7tv emotes
try
{
JArray STV_channel = JArray.Parse(client.DownloadString(String.Format("https://api.7tv.app/v2/users/{0}/emotes", streamerId)));
foreach (var emote in STV_channel)
{
string id = emote["id"].ToString();
string name = emote["name"].ToString();
string url2x = emote["urls"][1][1].ToString(); // 2x
if (alreadyAdded.Contains(name))
continue;
byte[] bytes;
string fileName = Path.Combine(stvFolder, id + "_2x.png");
if (File.Exists(fileName))
bytes = File.ReadAllBytes(fileName);
else
{
bytes = client.DownloadData(url2x);
File.WriteAllBytes(fileName, bytes);
}
MemoryStream ms = new MemoryStream(bytes);
returnList.Add(new TwitchEmote(new List<SKBitmap>() { SKBitmap.Decode(bytes) }, SKCodec.Create(ms), name, emote["mime"].ToString().Split('/')[1], id, 2, bytes));
alreadyAdded.Add(name);
}
}
catch { }
}
}

return returnList;
Expand Down
3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<setting name="BTTVEmotes" serializeAs="String">
<value>True</value>
</setting>
<setting name="STVEmotes" serializeAs="String">
<value>True</value>
</setting>
<setting name="BackgroundColorR" serializeAs="String">
<value>17</value>
</setting>
Expand Down
2 changes: 2 additions & 0 deletions TwitchDownloaderWPF/PageChatRender.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<TextBlock Text="Timestamp:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="FFZ Emotes:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="BTTV Emotes:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="7TV Emotes:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ComboBox x:Name="comboFont" MinWidth="100" SelectionChanged="UpdateFont"/>
Expand All @@ -46,6 +47,7 @@
<CheckBox x:Name="checkTimestamp" Margin="0,6,0,0" Checked="UpdateCheckbox" Unchecked="UpdateCheckbox"/>
<CheckBox x:Name="checkFFZ" IsChecked="True" Margin="0,6,0,0"/>
<CheckBox x:Name="checkBTTV" IsChecked="True" Margin="0,6,0,0"/>
<CheckBox x:Name="checkSTV" IsChecked="True" Margin="0,6,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,5,0">
<TextBlock Text="Background Color:" HorizontalAlignment="Right"/>
Expand Down
4 changes: 3 additions & 1 deletion TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private async void btnRender_Click(object sender, RoutedEventArgs e)
ChatWidth = Int32.Parse(textWidth.Text),
BttvEmotes = (bool)checkBTTV.IsChecked,
FfzEmotes = (bool)checkFFZ.IsChecked,
StvEmotes = (bool)checkSTV.IsChecked,
Outline = (bool)checkOutline.IsChecked,
Font = (string)comboFont.SelectedItem,
FontSize = Double.Parse(textFontSize.Text),
Expand Down Expand Up @@ -219,6 +220,7 @@ private void SaveSettings()
Settings.Default.BackgroundColorA = colorBackground.SelectedColor.Value.A;
Settings.Default.FFZEmotes = (bool)checkFFZ.IsChecked;
Settings.Default.BTTVEmotes = (bool)checkBTTV.IsChecked;
Settings.Default.STVEmotes = (bool)checkSTV.IsChecked;
Settings.Default.FontColorR = colorFont.SelectedColor.Value.R;
Settings.Default.FontColorG = colorFont.SelectedColor.Value.G;
Settings.Default.FontColorB = colorFont.SelectedColor.Value.B;
Expand Down Expand Up @@ -430,4 +432,4 @@ public override string ToString()
return Name;
}
}
}
}
5 changes: 4 additions & 1 deletion TwitchDownloaderWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<Setting Name="BTTVEmotes" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="STVEmotes" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="BackgroundColorR" Type="System.Int32" Scope="User">
<Value Profile="(Default)">17</Value>
</Setting>
Expand Down Expand Up @@ -99,4 +102,4 @@
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>

0 comments on commit 4ea57e6

Please sign in to comment.