Skip to content

Commit

Permalink
v0.5.9.8-alpha
Browse files Browse the repository at this point in the history
Fixed Remove Words Filter
Fixed Replace Words Filter
  • Loading branch information
MattMcManis committed Feb 23, 2019
1 parent 0f263ac commit d3ef917
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.9.6-alpha
0.5.9.8-alpha
64 changes: 23 additions & 41 deletions source/Tanto/Tanto/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public static String FilterFileName(MainWindow mainwindow, string filename)
&& mainwindow.cbxFilterHyphens.IsChecked == true)
{
// remove dash, preserve hyphens
//filename = Regex.Replace(filename, @"((?<=[\s\.])\-+)|(\-+(?=[\s\.]))", "").Trim();
filename = Regex.Replace(filename, @"\b(-+)\b|-", "$1").Trim();
// multiple dashes to single dash
filename = Regex.Replace(filename, "[-]{2,}", "").Trim();
Expand All @@ -131,20 +130,6 @@ public static String FilterFileName(MainWindow mainwindow, string filename)
filename = Regex.Replace(filename, @"(\((1|2)\d?\d?\d?\))", "");
}

//// -------------------------
//// Remove Episode Numbering
//// -------------------------
//if (mainwindow.cbxFilterRemoveEpisodeNumbering.IsChecked == true)
//{
// //S000E000, EP000, E000, 000x000, 000v000, 000, 000v0-9
// filename = Regex.Replace(
// filename
// , @"(?i)\b(S\d\d\d?E\d\d\d?|(EP|EP((\s*)|-))\d\d\d?|E\d\d\d?|(?<![.])\d\d?\d?|(E(\s*)|EP(\s*))?(?<![.])\d\d?\d?(x|v)\d\d?\d?)\b"
// , ""
// , RegexOptions.IgnoreCase
// );
//}

// -------------------------
// Remove Double Spaces
// -------------------------
Expand Down Expand Up @@ -190,10 +175,9 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
// -------------------------
if (mainwindow.cbxFilterRemoveEpisodeNumbering.IsChecked == true)
{
//S000E000, EP000, E000, 000x000, 000v000, 000, 000v0-9
// S000E000, EP000, E000, 000x000, 000v000, 000, 000v0-9
filename = Regex.Replace(
filename
//, @"(?i)\b(S\d\d\d?E\d\d\d?|(EP|EP((\s*)|-))\d\d\d?|E\d\d\d?|(?<![.])\d\d?\d?|(E(\s*)|EP(\s*))?(?<![.])^\d\d?\d?(x|v)\d\d?\d?)\b" //old
, @"(?i)\b(S\d+E\d+)|(Episode(\s*)|(EP|EP((\s*)|-))\d+|E\d+|(?<![.])^\d+|(E(\s*)|EP(\s*))?(?<![.])\d\d?\d?(x|v)\d\d?\d?)\b"
, ""
, RegexOptions.IgnoreCase
Expand All @@ -203,15 +187,15 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
// -------------------------
// Remove Words
// -------------------------
if (mainwindow.tbxRemoveWords.Text != string.Empty)
if (!string.IsNullOrWhiteSpace(mainwindow.tbxRemoveWords.Text))
{
try
{
string words = mainwindow.tbxRemoveWords.Text.Replace(",", "|");

string regex = @"\b(" + words + @")\b";

filename = Regex.Replace(filename, Regex.Escape(regex), "");
filename = Regex.Replace(filename, regex, "");
}
catch
{
Expand All @@ -225,14 +209,10 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
// -------------------------
// Remove Characters
// -------------------------
if (mainwindow.tbxRemoveChars.Text != string.Empty)
if (!string.IsNullOrWhiteSpace(mainwindow.tbxRemoveChars.Text))
{
try
{
//string characters = mainwindow.tbxRemoveChars.Text.Replace(",", "|");
//string regex = characters;
//filename = Regex.Replace(filename, Regex.Escape(regex), "");

List<string> removeChars = new List<string>(mainwindow.tbxRemoveChars.Text.Split(','));

List<string> removeCharsEscaped = new List<string>();
Expand Down Expand Up @@ -264,8 +244,10 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
// -------------------------
// Remove Between Characters
// -------------------------
if (mainwindow.tbxRemoveRangeStart.Text != string.Empty
&& mainwindow.tbxRemoveRangeEnd.Text != string.Empty)
//if (mainwindow.tbxRemoveRangeStart.Text != string.Empty
// && mainwindow.tbxRemoveRangeEnd.Text != string.Empty)
if (!string.IsNullOrWhiteSpace(mainwindow.tbxRemoveRangeStart.Text) &&
!string.IsNullOrWhiteSpace(mainwindow.tbxRemoveRangeEnd.Text))
{
try
{
Expand All @@ -292,7 +274,7 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
{
filename = Regex.Replace(
filename
, @"(?i)(\[).*?(\])|(\(*)(480p|576p|720p|1080p|2k|4k|8k|60fps|DVD|BD|BRD|Bluray|Blu-Ray|WebDL|Web-DL|WebRip|Web-Rip|RAW|HEVC|(h|x)(265|264)|AV1|VP8|VP9|Theora|AAC|AC3|Vorbis|Opus|FLAC|MP3|(DTS\s?|DD\s?)(5\.1|7\.1)(\s?CH)?|(2|6|5\.1|7\.1)\s?CH|Dual-Audio|Multi-Sub|English Dub)(\)*)(\,*)"
, @"(?i)(\[).*?(\])|(\(*)(480p|576p|720p|1080p|2k|4k|8k|60fps|DVD|BD|BRD|Bluray|Blu-Ray|BrRip|WebDL|Web-DL|WebRip|Web-Rip|RAW|HEVC|(h|x)(265|264)|AV1|VP8|VP9|Theora|AAC|AC3|Vorbis|Opus|FLAC|MP3|(DTS\s?|DD\s?)(5\.1|7\.1)(\s?CH)?|(2|6|5\.1|7\.1)\s?CH|Dual-Audio|Multi-Sub|English Dub)(\)*)(\,*)"
, ""
, RegexOptions.IgnoreCase
);
Expand Down Expand Up @@ -322,50 +304,50 @@ public static String FilterRemove(MainWindow mainwindow, string filename)
/// </remarks>
public static String FilterReplace(MainWindow mainwindow, string filename)
{
// Replace These Words With
if (mainwindow.tbxReplaceWords.Text != string.Empty)
// Replace These Characters With
if (!string.IsNullOrWhiteSpace(mainwindow.tbxReplaceChars.Text))
{
try
{
string words = mainwindow.tbxReplaceWords.Text.Replace(",", "|");
string replacement = mainwindow.tbxReplaceWordsWith.Text;
string characters = mainwindow.tbxReplaceChars.Text.Replace(",", "|");
string replacement = mainwindow.tbxReplaceCharsWith.Text;

string regex = @"\b(" + words + @")\b";
string regex = characters;

filename = Regex.Replace(filename, Regex.Escape(regex), Regex.Escape(replacement));
}
catch
{
MessageBox.Show("Could not replace words.",
MessageBox.Show("Could not replace characters.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

// Replace These Characters With
if (mainwindow.tbxReplaceChars.Text != string.Empty)
// Replace These Words With
if (!string.IsNullOrWhiteSpace(mainwindow.tbxReplaceWords.Text))
{
try
{
string characters = mainwindow.tbxReplaceChars.Text.Replace(",", "|");
string replacement = mainwindow.tbxReplaceCharsWith.Text;
string words = mainwindow.tbxReplaceWords.Text.Replace(",", "|");
string replacement = mainwindow.tbxReplaceWordsWith.Text;

string regex = characters;
string regex = @"\b(" + words + @")\b";

filename = Regex.Replace(filename, Regex.Escape(regex), Regex.Escape(replacement));
filename = Regex.Replace(filename, regex, replacement);
}
catch
{
MessageBox.Show("Could not replace characters.",
MessageBox.Show("Could not replace words.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

// Replace Spaces With
if (mainwindow.tbxReplaceSpacesWith.Text != string.Empty)
if (!string.IsNullOrWhiteSpace(mainwindow.tbxReplaceSpacesWith.Text))
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions source/Tanto/Tanto/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.9.7")]
[assembly: AssemblyFileVersion("0.5.9.7")]
[assembly: AssemblyVersion("0.5.9.8")]
[assembly: AssemblyFileVersion("0.5.9.8")]

0 comments on commit d3ef917

Please sign in to comment.