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