Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Jan 21, 2024
1 parent 51becdf commit 7761d37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions TwitchDownloaderCore/Extensions/M3U8Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ public static M3U8.Stream GetStreamOfQuality(this M3U8 m3u8, string qualityStrin
/// </returns>
public static string GetResolutionFramerateString(this M3U8.Stream stream)
{
const string RESOLUTION_FRAMERATE_PATTERN = /*lang=regex*/@"\d{3,4}p\d{2,3}";

var mediaInfo = stream.MediaInfo;
if (mediaInfo.Name.Contains("audio", StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(mediaInfo.Name, @"\d{3,4}p\d{2,3}"))
if (mediaInfo.Name.Contains("audio", StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(mediaInfo.Name, RESOLUTION_FRAMERATE_PATTERN))
{
return mediaInfo.Name;
}

var streamInfo = stream.StreamInfo;
if (Regex.IsMatch(streamInfo.Video, @"\d{3,4}p\d{2,3}"))
if (Regex.IsMatch(streamInfo.Video, RESOLUTION_FRAMERATE_PATTERN))
{
return streamInfo.Video;
}

if (Regex.IsMatch(mediaInfo.GroupId, @"\d{3,4}p\d{2,3}"))
if (Regex.IsMatch(mediaInfo.GroupId, RESOLUTION_FRAMERATE_PATTERN))
{
return mediaInfo.GroupId;
}
Expand Down Expand Up @@ -144,9 +146,7 @@ public static string GetResolutionFramerateString(this M3U8.Stream stream)
/// </summary>
public static M3U8.Stream BestQualityStream(this M3U8 m3u8)
{
var source = Array.Find(
m3u8.Streams, x => x.MediaInfo.Name.Contains("source", StringComparison.OrdinalIgnoreCase) ||
x.MediaInfo.GroupId.Equals("chunked", StringComparison.OrdinalIgnoreCase));
var source = Array.Find(m3u8.Streams, x => x.IsSource());
return source ?? m3u8.Streams.MaxBy(x => x.StreamInfo.Resolution.Width * x.StreamInfo.Resolution.Height * x.StreamInfo.Framerate);
}

Expand Down

0 comments on commit 7761d37

Please sign in to comment.