mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
Create adult text classifier ML Model wip - starting to write PTN in c# More work on season, show and movie parsing Remove ML project
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
namespace Producer.Features.ParseTorrentTitle;
|
|
|
|
public static partial class AudioChannelsParser
|
|
{
|
|
[GeneratedRegex(@"\b(?<eight>7.?[01])\b", RegexOptions.IgnoreCase, "en-GB")]
|
|
private static partial Regex EightChannelExp();
|
|
[GeneratedRegex(@"\b(?<six>(6[\W]0(?:ch)?)(?=[^\d]|$)|(5[\W][01](?:ch)?)(?=[^\d]|$)|5ch|6ch)\b", RegexOptions.IgnoreCase, "en-GB")]
|
|
private static partial Regex SixChannelExp();
|
|
[GeneratedRegex(@"(?<stereo>((2[\W]0(?:ch)?)(?=[^\d]|$))|(stereo))", RegexOptions.IgnoreCase, "en-GB")]
|
|
private static partial Regex StereoChannelExp();
|
|
[GeneratedRegex(@"(?<mono>(1[\W]0(?:ch)?)(?=[^\d]|$)|(mono)|(1ch))", RegexOptions.IgnoreCase, "en-GB")]
|
|
private static partial Regex MonoChannelExp();
|
|
|
|
private static readonly Regex ChannelExp = new(string.Join("|", EightChannelExp(), SixChannelExp(), StereoChannelExp(), MonoChannelExp()), RegexOptions.IgnoreCase);
|
|
|
|
public static void Parse(string title, out AudioChannels? channels, out string? source)
|
|
{
|
|
channels = null;
|
|
source = null;
|
|
|
|
var channelResult = ChannelExp.Match(title);
|
|
if (!channelResult.Success)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var groups = channelResult.Groups;
|
|
|
|
if (groups["eight"].Success)
|
|
{
|
|
channels = AudioChannels.SEVEN;
|
|
source = groups["eight"].Value;
|
|
}
|
|
else if (groups["six"].Success)
|
|
{
|
|
channels = AudioChannels.SIX;
|
|
source = groups["six"].Value;
|
|
}
|
|
else if (groups["stereo"].Success)
|
|
{
|
|
channels = AudioChannels.STEREO;
|
|
source = groups["stereo"].Value;
|
|
}
|
|
else if (groups["mono"].Success)
|
|
{
|
|
channels = AudioChannels.MONO;
|
|
source = groups["mono"].Value;
|
|
}
|
|
}
|
|
} |