Skip to content

Commit

Permalink
Fix the last chapter of VODs of currently-airing streams missing a du…
Browse files Browse the repository at this point in the history
…ration value (#1023)
  • Loading branch information
ScrubN authored Mar 31, 2024
1 parent cdd641a commit 55893dc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,14 @@ public static async Task<GqlVideoChapterResponse> GetVideoChapters(int videoId)
response.EnsureSuccessStatusCode();

var chapterResponse = await response.Content.ReadFromJsonAsync<GqlVideoChapterResponse>();
chapterResponse.data.video.moments ??= new VideoMomentConnection
chapterResponse.data.video.moments ??= new VideoMomentConnection { edges = new List<VideoMomentEdge>() };

// When downloading VODs of currently-airing streams, the last chapter lacks a duration
if (chapterResponse.data.video.moments.edges.LastOrDefault() is { } lastEdge && lastEdge.node.durationMilliseconds is 0)
{
edges = new List<VideoMomentEdge>()
};
lastEdge.node.durationMilliseconds = lastEdge.node.video.lengthSeconds * 1000 - lastEdge.node.positionMilliseconds;
}

return chapterResponse;
}

Expand Down

0 comments on commit 55893dc

Please sign in to comment.