Skip to content

Commit

Permalink
Fix clip downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Dec 23, 2019
1 parent 730340e commit b429694
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
7 changes: 3 additions & 4 deletions TwitchDownloaderWPF/InfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ public static async Task<JObject> GetClipInfoChat(object clipId)
}
}

public static async Task<JObject> GetClipLinks(object clipId)
public static async Task<JArray> GetClipLinks(object clipId)
{
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
//API is deprecated - hopefully keeps working for a while. Can genereate full url from thumbnail but fails ocasionally https://discuss.dev.twitch.tv/t/clips-api-does-not-expose-video-url/15763/2
string response = await client.DownloadStringTaskAsync(String.Format("https://clips.twitch.tv/api/v2/clips/{0}/status", clipId));
JObject result = JObject.Parse(response);
string response = await client.UploadStringTaskAsync(new Uri("https://gql.twitch.tv/gql", UriKind.Absolute), "[{\"operationName\":\"VideoAccessToken_Clip\",\"variables\":{\"slug\":\"" + clipId + "\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"9bfcc0177bffc730bd5a5a89005869d2773480cf1738c592143b5173634b7d15\"}}}]");
JArray result = JArray.Parse(response);
return result;
}
}
Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/PageClipDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
btnGetInfo.IsEnabled = false;
comboQuality.Items.Clear();
Task<JObject> taskInfo = InfoHelper.GetClipInfo(clipId);
Task<JObject> taskLinks = InfoHelper.GetClipLinks(clipId);
Task<JArray> taskLinks = InfoHelper.GetClipLinks(clipId);
await Task.WhenAll(taskInfo, taskLinks);

JToken clipData = taskInfo.Result["data"][0];
Expand All @@ -59,9 +59,9 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
textCreatedAt.Text = clipData["created_at"].ToString();
textTitle.Text = clipData["title"].ToString();

foreach (var quality in taskLinks.Result["quality_options"])
foreach (var quality in taskLinks.Result[0]["data"]["clip"]["videoQualities"])
{
comboQuality.Items.Add(new TwitchClip(quality["quality"].ToString(), quality["frame_rate"].ToString(), quality["source"].ToString()));
comboQuality.Items.Add(new TwitchClip(quality["quality"].ToString(), quality["frameRate"].ToString(), quality["sourceURL"].ToString()));
}

comboQuality.SelectedIndex = 0;
Expand All @@ -72,7 +72,7 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
catch (Exception ex)
{
MessageBox.Show("Unable to get Clip information. Please double check Clip Slug and try again", "Unable to get info", MessageBoxButton.OK, MessageBoxImage.Error);
AppendLog("ERROR: " + ex.Message);
AppendLog("ERROR: " + ex);
btnGetInfo.IsEnabled = true;
}
}
Expand Down
31 changes: 29 additions & 2 deletions TwitchDownloaderWPF/TwitchDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -251,17 +266,28 @@
<ItemGroup>
<Resource Include="icon_zps_icon.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Accord.3.8.0\build\Accord.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.3.8.0\build\Accord.targets'))" />
<Error Condition="!Exists('..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets'))" />
<Error Condition="!Exists('..\packages\SkiaSharp.1.68.0\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.68.0\build\net45\SkiaSharp.targets'))" />
<Error Condition="!Exists('..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets'))" />
</Target>
<Import Project="..\packages\Accord.3.8.0\build\Accord.targets" Condition="Exists('..\packages\Accord.3.8.0\build\Accord.targets')" />
<Import Project="..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets" Condition="Exists('..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets')" />
<Import Project="..\packages\SkiaSharp.1.68.0\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.0\build\net45\SkiaSharp.targets')" />
<PropertyGroup>
<PostBuildEvent>RMDIR "$(TargetDir)de/" /S /Q
Expand All @@ -278,4 +304,5 @@ RMDIR "$(TargetDir)pt-BR/" /S /Q
RMDIR "$(TargetDir)zh-Hans/" /S /Q
RMDIR "$(TargetDir)zh-Hant/" /S /Q</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets" Condition="Exists('..\packages\Accord.Video.FFMPEG.x64.3.8.0\build\Accord.Video.FFMPEG.x64.targets')" />
</Project>

0 comments on commit b429694

Please sign in to comment.