Derivation plus Newpct minor changes (#3691)

* Make ReleaseInflo class derivation friendly

* Improve releaseinfo inheritance
Ensure provider order is respected
Some season numbers were not parsed in rss mode
Remove s00e00 from movies results
This commit is contained in:
snamds 2018-08-29 11:21:07 +02:00 committed by flightlevel
parent 76a3e7cd85
commit ae7c139452
2 changed files with 107 additions and 67 deletions

View File

@ -28,16 +28,36 @@ namespace Jackett.Common.Indexers
class NewpctRelease : ReleaseInfo
{
public string SerieName;
public ReleaseType NewpctReleaseType;
public string SeriesName;
public int? Season;
public int? Episode;
public int? EpisodeTo;
public NewpctRelease()
{
}
public NewpctRelease(NewpctRelease copyFrom):
base(copyFrom)
{
NewpctReleaseType = copyFrom.NewpctReleaseType;
SeriesName = copyFrom.SeriesName;
Season = copyFrom.Season;
Episode = copyFrom.Episode;
EpisodeTo = copyFrom.EpisodeTo;
}
public override object Clone()
{
return new NewpctRelease(this);
}
}
private static Uri SiteLinkUri = new Uri("http://www.tvsinpagar.com/");
private ReleaseInfo _mostRecentRelease;
private NewpctRelease _mostRecentRelease;
private Regex _searchStringRegex = new Regex(@"(.+?)S0?(\d+)(E0?(\d+))?$", RegexOptions.IgnoreCase);
private Regex _titleListRegex = new Regex(@"Serie(.+?)(Temporada(.+?)(\d+)(.+?))?Capitulos?(.+?)(\d+)((.+?)(\d+))?(.+?)-(.+?)Calidad(.*)", RegexOptions.IgnoreCase);
private Regex _titleListRegex = new Regex(@"Serie( *Descargar)?(.+?)(Temporada(.+?)(\d+)(.+?))?Capitulos?(.+?)(\d+)((.+?)(\d+))?(.+?)-(.+?)Calidad(.*)", RegexOptions.IgnoreCase);
private Regex _titleClassicRegex = new Regex(@"(\[[^\]]*\])?\[Cap\.(\d{1,2})(\d{2})([_-](\d{1,2})(\d{2}))?\]", RegexOptions.IgnoreCase);
private Regex _titleClassicTvQualityRegex = new Regex(@"\[([^\]]*HDTV[^\]]*)", RegexOptions.IgnoreCase);
@ -45,6 +65,9 @@ namespace Jackett.Common.Indexers
private int _maxEpisodesListPages = 100;
private int[] _allTvCategories = TorznabCatType.TV.SubCategories.Select(c => c.ID).ToArray();
private DateTime _dailyNow;
private int _dailyResultIdx;
private string _dailyUrl = "/ultimas-descargas/pg/{0}";
private string[] _seriesLetterUrls = new string[] { "/series/letter/{0}", "/series-hd/letter/{0}" };
private string[] _seriesVOLetterUrls = new string[] { "/series-vo/letter/{0}" };
@ -110,6 +133,13 @@ namespace Jackett.Common.Indexers
{
var releases = new List<ReleaseInfo>();
lock (cache)
{
CleanCache();
}
_dailyNow = DateTime.Now;
_dailyResultIdx = 0;
bool rssMode = string.IsNullOrEmpty(query.SanitizedSearchTerm);
if (rssMode)
@ -130,7 +160,7 @@ namespace Jackett.Common.Indexers
bool recentFound = _mostRecentRelease != null &&
items.Any(r => r.Title == _mostRecentRelease.Title && r.Link.AbsoluteUri == _mostRecentRelease.Link.AbsoluteUri);
if (pg == 1)
_mostRecentRelease = (ReleaseInfo)items.First().Clone();
_mostRecentRelease = (NewpctRelease)items.First().Clone();
if (recentFound)
break;
@ -153,7 +183,7 @@ namespace Jackett.Common.Indexers
private async Task<IEnumerable<ReleaseInfo>> TvSearch(TorznabQuery query)
{
var newpctReleases = new List<ReleaseInfo>();
List<ReleaseInfo> newpctReleases = null;
string seriesName = query.SanitizedSearchTerm;
int? season = query.Season > 0 ? (int?)query.Season : null;
@ -174,22 +204,17 @@ namespace Jackett.Common.Indexers
}
//Try to reuse cache
bool cacheFound = false;
lock (cache)
{
CleanCache();
var cachedResult = cache.FirstOrDefault(i => i.Query == seriesName.ToLower());
if (cachedResult != null && cachedResult.Results != null)
{
cacheFound = true;
newpctReleases = cachedResult.Results.Where(r => (r as NewpctRelease) != null).ToList();
if (!newpctReleases.Any() && cachedResult.Results.Any())
cacheFound = false;
}
if (cachedResult != null)
newpctReleases = cachedResult.Results.Select(r => (ReleaseInfo)r.Clone()).ToList();
}
if (!cacheFound)
if (newpctReleases == null)
{
newpctReleases = new List<ReleaseInfo>();
//Search series url
foreach (Uri seriesListUrl in SeriesListUris(seriesName))
{
@ -288,7 +313,11 @@ namespace Jackett.Common.Indexers
foreach (var row in rows)
{
var anchor = row.QuerySelector("a");
var title = anchor.TextContent.Replace("\t", "").Trim();
var title = Regex.Replace(anchor.TextContent, @"\s+", " ").Trim();
var title2 = Regex.Replace(anchor.GetAttribute("title"), @"\s+", " ").Trim();
if (title2.Length >= title.Length)
title = title2;
var detailsUrl = anchor.GetAttribute("href");
var span = row.QuerySelector("span");
@ -298,16 +327,17 @@ namespace Jackett.Common.Indexers
var div = row.QuerySelector("div");
var language = div.ChildNodes[1].TextContent.Trim();
_dailyResultIdx++;
NewpctRelease newpctRelease;
if (releaseType == ReleaseType.TV)
newpctRelease = GetReleaseFromData(releaseType,
string.Format("Serie {0} - {1} Calidad [{2}]", title, language, quality),
detailsUrl, quality, language, ReleaseInfo.GetBytes(sizeText), DateTime.Now);
detailsUrl, quality, language, ReleaseInfo.GetBytes(sizeText), _dailyNow - TimeSpan.FromMilliseconds(_dailyResultIdx));
else
newpctRelease = GetReleaseFromData(releaseType,
string.Format("{0} [{1}][{2}]", title, quality, language),
detailsUrl, quality, language, ReleaseInfo.GetBytes(sizeText), DateTime.Now);
detailsUrl, quality, language, ReleaseInfo.GetBytes(sizeText), _dailyNow - TimeSpan.FromMilliseconds(_dailyResultIdx));
releases.Add(newpctRelease);
}
@ -391,6 +421,7 @@ namespace Jackett.Common.Indexers
NewpctRelease GetReleaseFromData(ReleaseType releaseType, string title, string detailsUrl, string quality, string language, long size, DateTime publishDate)
{
NewpctRelease result = new NewpctRelease();
result.NewpctReleaseType = releaseType;
//Sanitize
title = title.Replace("\t", "").Replace("\x2013", "-");
@ -398,30 +429,30 @@ namespace Jackett.Common.Indexers
Match match = _titleListRegex.Match(title);
if (match.Success)
{
result.SerieName = match.Groups[1].Value.Trim(' ', '-');
result.Season = int.Parse(match.Groups[4].Success ? match.Groups[4].Value.Trim() : "1");
result.Episode = int.Parse(match.Groups[7].Value.Trim().PadLeft(2, '0'));
result.EpisodeTo = match.Groups[10].Success ? (int?)int.Parse(match.Groups[10].Value.Trim()) : null;
string audioQuality = match.Groups[12].Value.Trim(' ', '[', ']');
quality = match.Groups[13].Value.Trim(' ', '[', ']');
result.SeriesName = match.Groups[2].Value.Trim(' ', '-');
result.Season = int.Parse(match.Groups[5].Success ? match.Groups[5].Value.Trim() : "1");
result.Episode = int.Parse(match.Groups[8].Value.Trim().PadLeft(2, '0'));
result.EpisodeTo = match.Groups[11].Success ? (int?)int.Parse(match.Groups[11].Value.Trim()) : null;
string audioQuality = match.Groups[13].Value.Trim(' ', '[', ']');
quality = match.Groups[14].Value.Trim(' ', '[', ']');
string seasonText = result.Season.ToString();
string episodeText = seasonText + result.Episode.ToString().PadLeft(2, '0');
string episodeToText = result.EpisodeTo.HasValue ? "_" + seasonText + result.EpisodeTo.ToString().PadLeft(2, '0') : "";
result.Title = string.Format("{0} - Temporada {1} [{2}][Cap.{3}{4}][{5}]",
result.SerieName, seasonText, quality, episodeText, episodeToText, audioQuality);
result.SeriesName, seasonText, quality, episodeText, episodeToText, audioQuality);
}
else
{
Match matchClassic = _titleClassicRegex.Match(title);
if (matchClassic.Success)
{
result.Season = matchClassic.Groups[2].Success ? (int?)int.Parse(matchClassic.Groups[2].Value) : null;
result.Episode = matchClassic.Groups[3].Success ? (int?)int.Parse(matchClassic.Groups[3].Value) : null;
result.EpisodeTo = matchClassic.Groups[6].Success ? (int?)int.Parse(matchClassic.Groups[6].Value) : null;
if (matchClassic.Groups[1].Success)
quality = matchClassic.Groups[1].Value;
result.Season = matchClassic.Groups[3].Success ? (int?)int.Parse(matchClassic.Groups[3].Value) : null;
result.Episode = matchClassic.Groups[4].Success ? (int?)int.Parse(matchClassic.Groups[4].Value) : null;
result.EpisodeTo = matchClassic.Groups[7].Success ? (int?)int.Parse(matchClassic.Groups[7].Value) : null;
if (matchClassic.Groups[2].Success)
quality = matchClassic.Groups[2].Value;
}
result.Title = title;
@ -454,27 +485,30 @@ namespace Jackett.Common.Indexers
private string FixedTitle(NewpctRelease release, string quality)
{
if (String.IsNullOrEmpty(release.SerieName))
if (String.IsNullOrEmpty(release.SeriesName))
{
release.SerieName = release.Title;
release.SeriesName = release.Title;
if (release.Title.Contains("-"))
{
release.SerieName = release.Title.Substring(0, release.Title.IndexOf('-') - 1);
release.SeriesName = release.Title.Substring(0, release.Title.IndexOf('-') - 1);
}
}
if (String.IsNullOrEmpty(quality))
{
quality = "HDTV";
}
var seasonAndEpisode = "S" + release.Season.ToString().PadLeft(2, '0');
seasonAndEpisode += "E" + release.Episode.ToString().PadLeft(2, '0');
if (release.EpisodeTo != release.Episode && release.EpisodeTo != null && release.EpisodeTo != 0)
{
seasonAndEpisode += "-" + release.EpisodeTo.ToString().PadLeft(2, '0');
}
var titleParts = new List<string>();
titleParts.Add(release.SerieName);
titleParts.Add(seasonAndEpisode);
titleParts.Add(release.SeriesName);
if (release.NewpctReleaseType == ReleaseType.TV)
{
var seasonAndEpisode = "S" + release.Season.ToString().PadLeft(2, '0');
seasonAndEpisode += "E" + release.Episode.ToString().PadLeft(2, '0');
if (release.EpisodeTo != release.Episode && release.EpisodeTo != null && release.EpisodeTo != 0)
{
seasonAndEpisode += "-" + release.EpisodeTo.ToString().PadLeft(2, '0');
}
titleParts.Add(seasonAndEpisode);
}
titleParts.Add(quality.Replace("[", "").Replace("]", ""));
if (release.Title.ToLower().Contains("esp") || release.Title.ToLower().Contains("cast"))
{

View File

@ -45,33 +45,39 @@ namespace Jackett.Common.Models
}
}
public object Clone()
public ReleaseInfo()
{
return new ReleaseInfo()
{
Title = Title,
Guid = Guid,
Link = Link,
Comments = Comments,
PublishDate = PublishDate,
Category = Category,
Size = Size,
Files = Files,
Grabs = Grabs,
Description = Description,
RageID = RageID,
Imdb = Imdb,
TMDb = TMDb,
Seeders = Seeders,
Peers = Peers,
BannerUrl = BannerUrl,
InfoHash = InfoHash,
MagnetUri = MagnetUri,
MinimumRatio = MinimumRatio,
MinimumSeedTime = MinimumSeedTime,
DownloadVolumeFactor = DownloadVolumeFactor,
UploadVolumeFactor = UploadVolumeFactor
};
}
protected ReleaseInfo(ReleaseInfo copyFrom)
{
Title = copyFrom.Title;
Guid = copyFrom.Guid;
Link = copyFrom.Link;
Comments = copyFrom.Comments;
PublishDate = copyFrom.PublishDate;
Category = copyFrom.Category;
Size = copyFrom.Size;
Files = copyFrom.Files;
Grabs = copyFrom.Grabs;
Description = copyFrom.Description;
RageID = copyFrom.RageID;
Imdb = copyFrom.Imdb;
TMDb = copyFrom.TMDb;
Seeders = copyFrom.Seeders;
Peers = copyFrom.Peers;
BannerUrl = copyFrom.BannerUrl;
InfoHash = copyFrom.InfoHash;
MagnetUri = copyFrom.MagnetUri;
MinimumRatio = copyFrom.MinimumRatio;
MinimumSeedTime = copyFrom.MinimumSeedTime;
DownloadVolumeFactor = copyFrom.DownloadVolumeFactor;
UploadVolumeFactor = copyFrom.UploadVolumeFactor;
}
public virtual object Clone()
{
return new ReleaseInfo(this);
}
// ex: " 3.5 gb "