Skip to content

Commit

Permalink
Use int64 for video IDs (fixes #1057) (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss authored May 17, 2024
1 parent 7a0f52c commit 850cb25
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion TwitchDownloaderCLI/Modes/DownloadVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp
{
DownloadThreads = inputOptions.DownloadThreads,
ThrottleKib = inputOptions.ThrottleKib,
Id = int.Parse(vodIdMatch.ValueSpan),
Id = long.Parse(vodIdMatch.ValueSpan),
Oauth = inputOptions.Oauth,
Filename = inputOptions.OutputFile,
Quality = Path.GetExtension(inputOptions.OutputFile)!.ToLower() switch
Expand Down
4 changes: 2 additions & 2 deletions TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public async Task DownloadAsync(CancellationToken cancellationToken)

if (downloadType == DownloadType.Video)
{
GqlVideoResponse videoInfoResponse = await TwitchHelper.GetVideoInfo(int.Parse(videoId));
GqlVideoResponse videoInfoResponse = await TwitchHelper.GetVideoInfo(long.Parse(videoId));
if (videoInfoResponse.data.video == null)
{
throw new NullReferenceException("Invalid VOD, deleted/expired VOD possibly?");
Expand All @@ -291,7 +291,7 @@ public async Task DownloadAsync(CancellationToken cancellationToken)
viewCount = videoInfoResponse.data.video.viewCount;
game = videoInfoResponse.data.video.game?.displayName ?? "Unknown";

GqlVideoChapterResponse videoChapterResponse = await TwitchHelper.GetOrGenerateVideoChapters(int.Parse(videoId), videoInfoResponse.data.video);
GqlVideoChapterResponse videoChapterResponse = await TwitchHelper.GetOrGenerateVideoChapters(long.Parse(videoId), videoInfoResponse.data.video);
chatRoot.video.chapters.EnsureCapacity(videoChapterResponse.data.video.moments.edges.Count);
foreach (var responseChapter in videoChapterResponse.data.video.moments.edges)
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/ChatUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private async Task UpdateVideoInfo(int totalSteps, int currentStep, Cancellation

if (chatRoot.video.id.All(char.IsDigit))
{
var videoId = int.Parse(chatRoot.video.id);
var videoId = long.Parse(chatRoot.video.id);
VideoInfo videoInfo = null;
try
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCore/Options/VideoDownloadOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TwitchDownloaderCore.Options
{
public class VideoDownloadOptions
{
public int Id { get; set; }
public long Id { get; set; }
public string Quality { get; set; }
public string Filename { get; set; }
public bool TrimBeginning { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class TwitchHelper
private static readonly HttpClient httpClient = new HttpClient();
private static readonly string[] BttvZeroWidth = { "SoSnowy", "IceCold", "SantaHat", "TopHat", "ReinDeer", "CandyCane", "cvMask", "cvHazmat" };

public static async Task<GqlVideoResponse> GetVideoInfo(int videoId)
public static async Task<GqlVideoResponse> GetVideoInfo(long videoId)
{
var request = new HttpRequestMessage()
{
Expand All @@ -41,7 +41,7 @@ public static async Task<GqlVideoResponse> GetVideoInfo(int videoId)
return await response.Content.ReadFromJsonAsync<GqlVideoResponse>();
}

public static async Task<GqlVideoTokenResponse> GetVideoToken(int videoId, string authToken)
public static async Task<GqlVideoTokenResponse> GetVideoToken(long videoId, string authToken)
{
var request = new HttpRequestMessage()
{
Expand All @@ -57,7 +57,7 @@ public static async Task<GqlVideoTokenResponse> GetVideoToken(int videoId, strin
return await response.Content.ReadFromJsonAsync<GqlVideoTokenResponse>();
}

public static async Task<string> GetVideoPlaylist(int videoId, string token, string sig)
public static async Task<string> GetVideoPlaylist(long videoId, string token, string sig)
{
HttpRequestMessage request;
HttpResponseMessage response;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public static async Task<GqlUserInfoResponse> GetUserInfo(List<string> idList)
}

/// <remarks>When a given video has only 1 chapter, data.video.moments.edges will be empty.</remarks>
public static async Task<GqlVideoChapterResponse> GetVideoChapters(int videoId)
public static async Task<GqlVideoChapterResponse> GetVideoChapters(long videoId)
{
var request = new HttpRequestMessage()
{
Expand All @@ -1056,7 +1056,7 @@ public static async Task<GqlVideoChapterResponse> GetVideoChapters(int videoId)
return chapterResponse;
}

public static async Task<GqlVideoChapterResponse> GetOrGenerateVideoChapters(int videoId, VideoInfo videoInfo)
public static async Task<GqlVideoChapterResponse> GetOrGenerateVideoChapters(long videoId, VideoInfo videoInfo)
{
var chapterResponse = await GetVideoChapters(videoId);

Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private async Task GetVideoInfo()
{
if (downloadType == DownloadType.Video)
{
GqlVideoResponse videoInfo = await TwitchHelper.GetVideoInfo(int.Parse(downloadId));
GqlVideoResponse videoInfo = await TwitchHelper.GetVideoInfo(long.Parse(downloadId));

var thumbUrl = videoInfo.data.video.thumbnailURLs.FirstOrDefault();
if (!ThumbnailService.TryGetThumb(thumbUrl, out var image))
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageChatUpdate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private async void btnBrowse_Click(object sender, RoutedEventArgs e)
{
if (VideoId.All(char.IsDigit))
{
GqlVideoResponse videoInfo = await TwitchHelper.GetVideoInfo(int.Parse(VideoId));
GqlVideoResponse videoInfo = await TwitchHelper.GetVideoInfo(long.Parse(VideoId));
if (videoInfo.data.video == null)
{
AppendLog(Translations.Strings.ErrorLog + Translations.Strings.UnableToFindThumbnail + ": " + Translations.Strings.VodExpiredOrIdCorrupt);
Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace TwitchDownloaderWPF
public partial class PageVodDownload : Page
{
public readonly Dictionary<string, (string url, int bandwidth)> videoQualities = new();
public int currentVideoId;
public long currentVideoId;
public DateTime currentVideoTime;
public TimeSpan vodLength;
public int viewCount;
Expand Down Expand Up @@ -82,7 +82,7 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)

private async Task GetVideoInfo()
{
int videoId = ValidateUrl(textUrl.Text.Trim());
long videoId = ValidateUrl(textUrl.Text.Trim());
if (videoId <= 0)
{
MessageBox.Show(Translations.Strings.InvalidVideoLinkIdMessage.Replace(@"\n", Environment.NewLine), Translations.Strings.InvalidVideoLinkId, MessageBoxButton.OK, MessageBoxImage.Error);
Expand Down Expand Up @@ -275,10 +275,10 @@ public void SetImage(string imageUri, bool isGif)
}
}

private static int ValidateUrl(string text)
private static long ValidateUrl(string text)
{
var vodIdMatch = TwitchRegex.MatchVideoId(text);
if (vodIdMatch is {Success: true} && int.TryParse(vodIdMatch.ValueSpan, out var vodId))
if (vodIdMatch is {Success: true} && long.TryParse(vodIdMatch.ValueSpan, out var vodId))
{
return vodId;
}
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private void EnqueueDataList()
{
Oauth = Settings.Default.OAuth,
TempFolder = Settings.Default.TempPath,
Id = int.Parse(taskData.Id),
Id = long.Parse(taskData.Id),
Quality = (ComboPreferredQuality.SelectedItem as ComboBoxItem)?.Content as string,
FfmpegPath = "ffmpeg",
TrimBeginning = false,
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/WindowUrlList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
{
if (id.All(char.IsDigit))
{
Task<GqlVideoResponse> task = TwitchHelper.GetVideoInfo(int.Parse(id));
Task<GqlVideoResponse> task = TwitchHelper.GetVideoInfo(long.Parse(id));
taskVideoList.Add(task);
taskDict[task.Id] = id;
}
Expand Down

0 comments on commit 850cb25

Please sign in to comment.