Skip to content

Commit

Permalink
Account for alternate error message when fetching sub-only VOD withou…
Browse files Browse the repository at this point in the history
…t OAuth

And some very minor TimeSpanHFormat changes
  • Loading branch information
ScrubN committed Dec 8, 2023
1 parent feefb8a commit 1d91a9e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion TwitchDownloaderCore.Tests/TimeSpanHFormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormatException>(exception);
Assert.Equal(EXPECTED_SOURCE_NAME, exception.Source);
Assert.Equal($"Invalid character escaping in the format string: {FORMAT_STRING}", exception.Message);
}

[Fact]
Expand All @@ -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<FormatException>(exception);
Assert.Equal(EXPECTED_SOURCE_NAME, exception.Source);
}
}
Expand Down
1 change: 0 additions & 1 deletion TwitchDownloaderCore/Tools/TimeSpanHFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace TwitchDownloaderCore.Tools
{
/// <summary>Adds an 'H' parameter to <see cref="TimeSpan"/> string formatting. The 'H' parameter is equivalent to flooring <see cref="TimeSpan"/>.<see cref="TimeSpan.TotalHours"/>.</summary>
/// <remarks>
/// This formatter only supports escaping 'H's via '\'.
/// For optimal memory performance, resulting strings split about any 'H' parameters should be less than 256.
/// </remarks>
public class TimeSpanHFormat : IFormatProvider, ICustomFormatter
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
8 changes: 3 additions & 5 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,8 +98,6 @@ private async Task GetVideoInfo()
throw new NullReferenceException("Invalid VOD, deleted/expired VOD possibly?");
}

Task<string[]> 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))
{
Expand All @@ -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);
}
Expand Down

0 comments on commit 1d91a9e

Please sign in to comment.