From 1d91a9e2e96219ee32bae23e026a6d51b48512df Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:21:47 -0500 Subject: [PATCH] Account for alternate error message when fetching sub-only VOD without OAuth And some very minor TimeSpanHFormat changes --- TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs | 3 ++- TwitchDownloaderCore/Tools/TimeSpanHFormat.cs | 1 - TwitchDownloaderCore/VideoDownloader.cs | 2 +- TwitchDownloaderWPF/PageVodDownload.xaml.cs | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs b/TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs index ed89b166..8f78db92 100644 --- a/TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs +++ b/TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs @@ -227,8 +227,8 @@ public void ThrowsOnImbalancedQuoteMarkEscaping_WhenHoursUnder24() var exception = Assert.Throws(expectedExceptionType, () => TimeSpanHFormat.ReusableInstance.Format(FORMAT_STRING, timeSpan)); // Ensure the FormatException originated from TimeSpanHFormat and not TimeSpan.ToString() + Assert.IsType(exception); Assert.Equal(EXPECTED_SOURCE_NAME, exception.Source); - Assert.Equal($"Invalid character escaping in the format string: {FORMAT_STRING}", exception.Message); } [Fact] @@ -242,6 +242,7 @@ public void ThrowsOnImbalancedQuoteMarkEscaping_When24HoursOrMore() var exception = Assert.Throws(expectedExceptionType, () => TimeSpanHFormat.ReusableInstance.Format(FORMAT_STRING, timeSpan)); // Ensure the FormatException originated from TimeSpanHFormat and not TimeSpan.ToString() + Assert.IsType(exception); Assert.Equal(EXPECTED_SOURCE_NAME, exception.Source); } } diff --git a/TwitchDownloaderCore/Tools/TimeSpanHFormat.cs b/TwitchDownloaderCore/Tools/TimeSpanHFormat.cs index 531f04cb..de0f0cc5 100644 --- a/TwitchDownloaderCore/Tools/TimeSpanHFormat.cs +++ b/TwitchDownloaderCore/Tools/TimeSpanHFormat.cs @@ -6,7 +6,6 @@ namespace TwitchDownloaderCore.Tools { /// Adds an 'H' parameter to string formatting. The 'H' parameter is equivalent to flooring .. /// - /// This formatter only supports escaping 'H's via '\'. /// For optimal memory performance, resulting strings split about any 'H' parameters should be less than 256. /// public class TimeSpanHFormat : IFormatProvider, ICustomFormatter diff --git a/TwitchDownloaderCore/VideoDownloader.cs b/TwitchDownloaderCore/VideoDownloader.cs index ac8fed2c..674f1441 100644 --- a/TwitchDownloaderCore/VideoDownloader.cs +++ b/TwitchDownloaderCore/VideoDownloader.cs @@ -560,7 +560,7 @@ private static async Task DownloadVideoPartAsync(HttpClient httpClient, Uri base } string[] videoPlaylist = await TwitchHelper.GetVideoPlaylist(downloadOptions.Id, accessToken.data.videoPlaybackAccessToken.value, accessToken.data.videoPlaybackAccessToken.signature); - if (videoPlaylist[0].Contains("vod_manifest_restricted")) + if (videoPlaylist[0].Contains("vod_manifest_restricted") || videoPlaylist[0].Contains("unauthorized_entitlements")) { throw new NullReferenceException("Insufficient access to VOD, OAuth may be required."); } diff --git a/TwitchDownloaderWPF/PageVodDownload.xaml.cs b/TwitchDownloaderWPF/PageVodDownload.xaml.cs index 8e366603..6250a4c3 100644 --- a/TwitchDownloaderWPF/PageVodDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageVodDownload.xaml.cs @@ -14,7 +14,6 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using TwitchDownloaderCore; -using TwitchDownloaderCore.Extensions; using TwitchDownloaderCore.Options; using TwitchDownloaderCore.Tools; using TwitchDownloaderCore.TwitchObjects.Gql; @@ -99,8 +98,6 @@ private async Task GetVideoInfo() throw new NullReferenceException("Invalid VOD, deleted/expired VOD possibly?"); } - Task taskPlaylist = TwitchHelper.GetVideoPlaylist(videoId, taskAccessToken.Result.data.videoPlaybackAccessToken.value, taskAccessToken.Result.data.videoPlaybackAccessToken.signature); - var thumbUrl = taskVideoInfo.Result.data.video.thumbnailURLs.FirstOrDefault(); if (!ThumbnailService.TryGetThumb(thumbUrl, out var image)) { @@ -111,8 +108,9 @@ private async Task GetVideoInfo() comboQuality.Items.Clear(); videoQualities.Clear(); - string[] playlist = await taskPlaylist; - if (playlist[0].Contains("vod_manifest_restricted")) + + var playlist = await TwitchHelper.GetVideoPlaylist(videoId, taskAccessToken.Result.data.videoPlaybackAccessToken.value, taskAccessToken.Result.data.videoPlaybackAccessToken.signature); + if (playlist[0].Contains("vod_manifest_restricted") || playlist[0].Contains("unauthorized_entitlements")) { throw new NullReferenceException(Translations.Strings.InsufficientAccessMayNeedOauth); }