Skip to content

Commit

Permalink
Always sort source quality to the top of the list regardless of video…
Browse files Browse the repository at this point in the history
… metadata
  • Loading branch information
ScrubN committed Jan 20, 2024
1 parent bc5c391 commit a5b910c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions TwitchDownloaderCore/Extensions/M3U8Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@ public static M3U8.Stream BestQualityStream(this M3U8 m3u8)
x.MediaInfo.GroupId.Equals("chunked", StringComparison.OrdinalIgnoreCase));
return source ?? m3u8.Streams.MaxBy(x => x.StreamInfo.Resolution.Width * x.StreamInfo.Resolution.Height * x.StreamInfo.Framerate);
}

internal static bool IsSource(this M3U8.Stream stream)
=> stream.MediaInfo.Name.Contains("source", StringComparison.OrdinalIgnoreCase) ||
stream.MediaInfo.GroupId.Equals("chunked", StringComparison.OrdinalIgnoreCase);
}
}
4 changes: 4 additions & 0 deletions TwitchDownloaderCore/Tools/M3U8StreamQualityComparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using TwitchDownloaderCore.Extensions;

namespace TwitchDownloaderCore.Tools
{
Expand All @@ -14,6 +15,9 @@ public int Compare(M3U8.Stream x, M3U8.Stream y)

if (y?.StreamInfo is null) return 1;

if (x.IsSource()) return -1;
if (y.IsSource()) return 1;

var xResolution = x.StreamInfo.Resolution;
var yResolution = y.StreamInfo.Resolution;
var xTotalPixels = xResolution.Width * xResolution.Height;
Expand Down

0 comments on commit a5b910c

Please sign in to comment.