CouchPotato - Change prefilter to allow results with no year #158

This commit is contained in:
KZ 2015-08-31 20:52:15 +01:00
parent 1fa36925ad
commit 1e3de38db7
1 changed files with 86 additions and 63 deletions

View File

@ -1,63 +1,86 @@
using Jackett.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Jackett.Utils
{
public class TorznabUtil
{
static Regex reduceSpacesRegex = new Regex("\\s{2,}", RegexOptions.Compiled);
public static TorznabCapabilities CreateDefaultTorznabTVCaps()
{
var caps = new TorznabCapabilities();
caps.Categories.AddRange(new[] {
TorznabCatType.TV,
TorznabCatType.TVSD,
TorznabCatType.TVHD
});
return caps;
}
public static IEnumerable<ReleaseInfo> FilterResultsToTitle(IEnumerable<ReleaseInfo> results, string name, int year)
{
if (string.IsNullOrWhiteSpace(name))
return results;
name = CleanTitle(name);
var filteredResults = new List<ReleaseInfo>();
foreach (var result in results)
{
if (result.Title == null)
continue;
if (CleanTitle(result.Title).Contains(name) &&
(year ==0 || result.Title.Contains(year.ToString())))
{
filteredResults.Add(result);
}
}
return filteredResults;
}
public static IEnumerable<ReleaseInfo> FilterResultsToImdb(IEnumerable<ReleaseInfo> results, string imdb)
{
if (string.IsNullOrWhiteSpace(imdb))
return results;
// Filter out releases that do have a valid imdb ID, that is not equal to the one we're searching for.
return
results.Where(
result => !result.Imdb.HasValue || result.Imdb.Value == 0 || ("tt" + result.Imdb.Value).Equals(imdb));
}
private static string CleanTitle(string title)
{
title = title.Replace(':', ' ').Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Replace('+', ' ');
return reduceSpacesRegex.Replace(title, " ").ToLowerInvariant();
}
}
}
using Jackett.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Jackett.Utils
{
public class TorznabUtil
{
static Regex reduceSpacesRegex = new Regex("\\s{2,}", RegexOptions.Compiled);
static Regex findYearRegex = new Regex(@"(?<=\[|\(|\s)(\d{4})(?=\]|\)|\s)", RegexOptions.Compiled);
public static TorznabCapabilities CreateDefaultTorznabTVCaps()
{
var caps = new TorznabCapabilities();
caps.Categories.AddRange(new[] {
TorznabCatType.TV,
TorznabCatType.TVSD,
TorznabCatType.TVHD
});
return caps;
}
private static int GetYearFromTitle(string title)
{
var match = findYearRegex.Match(title);
if (match.Success)
{
var year = ParseUtil.CoerceInt(match.Value);
if(year>1850 && year < 2100)
{
return year;
}
}
return 0;
}
public static IEnumerable<ReleaseInfo> FilterResultsToTitle(IEnumerable<ReleaseInfo> results, string name, int imdbYear)
{
if (string.IsNullOrWhiteSpace(name))
return results;
name = CleanTitle(name);
var filteredResults = new List<ReleaseInfo>();
foreach (var result in results)
{
if (result.Title == null)
continue;
// Match on title
if (CleanTitle(result.Title).Contains(name))
{
// Match on year
var titleYear = GetYearFromTitle(result.Title);
if (imdbYear == 0 || titleYear == 0 || titleYear == imdbYear)
{
filteredResults.Add(result);
}
}
}
return filteredResults;
}
public static IEnumerable<ReleaseInfo> FilterResultsToImdb(IEnumerable<ReleaseInfo> results, string imdb)
{
if (string.IsNullOrWhiteSpace(imdb))
return results;
// Filter out releases that do have a valid imdb ID, that is not equal to the one we're searching for.
return
results.Where(
result => !result.Imdb.HasValue || result.Imdb.Value == 0 || ("tt" + result.Imdb.Value).Equals(imdb));
}
private static string CleanTitle(string title)
{
title = title.Replace(':', ' ').Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Replace('+', ' ');
return reduceSpacesRegex.Replace(title, " ").ToLowerInvariant();
}
}
}