Skip to content

Commit

Permalink
Downgrade API version
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed May 7, 2020
1 parent b47d88b commit 36cd7f4
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 296 deletions.
15 changes: 2 additions & 13 deletions TwitchDownloaderWPF/InfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public static async Task<JObject> GetVideoInfo(int videoId)
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json");
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
string response = await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/videos?id=" + videoId);
string response = await client.DownloadStringTaskAsync("https://api.twitch.tv/kraken/videos/" + videoId);
JObject result = JObject.Parse(response);
return result;
}
Expand Down Expand Up @@ -61,18 +62,6 @@ public static async Task<string[]> GetVideoPlaylist(int videoId, string token, s
}

public static async Task<JObject> GetClipInfo(object clipId)
{
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
string response = await client.DownloadStringTaskAsync(String.Format("https://api.twitch.tv/helix/clips?id={0}", clipId));
JObject result = JObject.Parse(response);
return result;
}
}

public static async Task<JObject> GetClipInfoChat(object clipId)
{
using (WebClient client = new WebClient())
{
Expand Down
2 changes: 2 additions & 0 deletions TwitchDownloaderWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<!-- <ColumnDefinition Width="*"/> -->
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnVodDownload" Margin="5" Grid.Row="1" Grid.Column="1" Content="VOD Downloader" Click="btnVodDownload_Click" />
<Button x:Name="btnClipDownload" Margin="5" Grid.Row="1" Grid.Column="2" Content="Clip Downloader" Click="btnClipDownload_Click" />
<Button x:Name="btnChatDownload" Margin="5" Grid.Row="1" Grid.Column="3" Content="Chat Downloader" Click="btnChatDownload_Click" />
<Button x:Name="btnChatRender" Margin="5" Grid.Row="1" Grid.Column="4" Content="Chat Render" Click="btnChatRender_Click" />
<!-- <Button x:Name="btnQueue" Margin="5" Grid.Row="1" Grid.Column="5" Content="Task Queue" Click="btnQueue_Click" /> -->
<Frame Focusable="False" x:Name="Main" Grid.Column="0" Grid.ColumnSpan="6" Grid.Row="2" NavigationUIVisibility="Hidden"/>

</Grid>
Expand Down
7 changes: 7 additions & 0 deletions TwitchDownloaderWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TwitchDownloader;
using Xabe.FFmpeg;

namespace TwitchDownloaderWPF
Expand All @@ -27,6 +28,7 @@ public partial class MainWindow : Window
PageClipDownload pageClipDownload = new PageClipDownload();
PageChatDownload pageChatDownload = new PageChatDownload();
PageChatRender pageChatRender = new PageChatRender();
PageQueue pageQueue = new PageQueue();
public MainWindow()
{
InitializeComponent();
Expand All @@ -53,6 +55,11 @@ private void btnChatRender_Click(object sender, RoutedEventArgs e)
Main.Content = pageChatRender;
}

private void btnQueue_Click(object sender, RoutedEventArgs e)
{
Main.Content = pageQueue;
}

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
Main.Content = pageVodDownload;
Expand Down
17 changes: 8 additions & 9 deletions TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
Task<JObject> taskInfo = InfoHelper.GetVideoInfo(Int32.Parse(downloadId));
await Task.WhenAll(taskInfo);

JToken clipData = taskInfo.Result;
videoData = taskInfo.Result;
string thumbUrl = videoData["data"][0]["thumbnail_url"].ToString().Replace("%{width}", 512.ToString()).Replace("%{height}", 290.ToString());
string thumbUrl = taskInfo.Result["preview"]["medium"].ToString();
Task<BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl);

try
Expand All @@ -99,16 +98,16 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
}
if (!taskThumb.IsFaulted)
imgThumbnail.Source = taskThumb.Result;
textTitle.Text = taskInfo.Result["data"][0]["title"].ToString();
textStreamer.Text = taskInfo.Result["data"][0]["user_name"].ToString();
textCreatedAt.Text = taskInfo.Result["data"][0]["created_at"].ToString();
streamerId = taskInfo.Result["data"][0]["user_id"].ToObject<int>();
textTitle.Text = taskInfo.Result["title"].ToString();
textStreamer.Text = taskInfo.Result["channel"]["display_name"].ToString();
textCreatedAt.Text = taskInfo.Result["created_at"].ToString();
streamerId = taskInfo.Result["channel"]["_id"].ToObject<int>();
SetEnabled(true, false);
}
else if (downloadType == DownloadType.Clip)
{
string clipId = downloadId;
Task<JObject> taskInfo = InfoHelper.GetClipInfoChat(clipId);
Task<JObject> taskInfo = InfoHelper.GetClipInfo(clipId);
await Task.WhenAll(taskInfo);

JToken clipData = taskInfo.Result;
Expand Down Expand Up @@ -313,10 +312,10 @@ private void btnDownload_Click(object sender, RoutedEventArgs e)
}
else
{
TimeSpan vodLength = GenerateTimespan(((JValue)videoData["data"][0]["duration"]).ToString(CultureInfo.InvariantCulture));
TimeSpan vodLength = TimeSpan.FromSeconds(videoData["length"].ToObject<int>());
duration = (int)Math.Ceiling(vodLength.TotalSeconds);
}
info = new ChatDownloadInfo(downloadType, textUrl.Text, saveFileDialog.FileName, videoData["data"][0]["id"].ToString(), startTime, duration, (bool)radioJson.IsChecked, textStreamer.Text, streamerId);
info = new ChatDownloadInfo(downloadType, textUrl.Text, saveFileDialog.FileName, videoData["_id"].ToString().Substring(1), startTime, duration, (bool)radioJson.IsChecked, textStreamer.Text, streamerId);
}
else
info = new ChatDownloadInfo(downloadType, textUrl.Text, saveFileDialog.FileName, videoData["vod"]["id"].ToString(), videoData["vod"]["offset"].ToObject<int>(), videoData["duration"].ToObject<double>(), (bool)radioJson.IsChecked, textStreamer.Text, streamerId);
Expand Down
6 changes: 3 additions & 3 deletions TwitchDownloaderWPF/PageClipDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
Task<JArray> taskLinks = InfoHelper.GetClipLinks(clipId);
await Task.WhenAll(taskInfo, taskLinks);

JToken clipData = taskInfo.Result["data"][0];
string thumbUrl = clipData["thumbnail_url"].ToString();
JToken clipData = taskInfo.Result;
string thumbUrl = clipData["thumbnails"]["medium"].ToString();
Task<BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl);
await Task.WhenAll(taskThumb);

imgThumbnail.Source = taskThumb.Result;
textStreamer.Text = clipData["broadcaster_name"].ToString();
textStreamer.Text = clipData["broadcaster"]["display_name"].ToString();
textCreatedAt.Text = clipData["created_at"].ToString();
textTitle.Text = clipData["title"].ToString();

Expand Down
21 changes: 21 additions & 0 deletions TwitchDownloaderWPF/PageQueue.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Page x:Class="TwitchDownloader.PageQueue"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TwitchDownloader"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="PageQueue">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
</Grid>
</Page>
28 changes: 28 additions & 0 deletions TwitchDownloaderWPF/PageQueue.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TwitchDownloader
{
/// <summary>
/// Interaction logic for PageQueue.xaml
/// </summary>
public partial class PageQueue : Page
{
public PageQueue()
{
InitializeComponent();
}
}
}
3 changes: 2 additions & 1 deletion TwitchDownloaderWPF/PageVodDownload.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
</StackPanel>
</StackPanel>
</StackPanel>
<Button x:Name="btnDownload" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="Download" Height="50" Width="100" Click="btnDownload_Click" Margin="0,0,0,10" VerticalAlignment="Bottom"/>
<Button x:Name="btnDownload" Content="Download" Height="50" Width="100" Click="btnDownload_Click" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0,0,0,10" VerticalAlignment="Bottom"/>
<!-- <Button x:Name="btnQueue" Content="Queue" Height="25" Width="60" Margin="5,4,0,10" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Center"/> -->
<!-- RIGHT -->
<StackPanel Grid.Column="4" Grid.Row="2" Grid.RowSpan="2">
<TextBlock Text="Log:"/>
Expand Down
Loading

1 comment on commit 36cd7f4

@lay295
Copy link
Owner Author

@lay295 lay295 commented on 36cd7f4 May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some unfinished stuff I was working on, didn't wanna deal with creating another branch

Please sign in to comment.