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 class NewpctRelease : ReleaseInfo
{ {
public string SerieName; public ReleaseType NewpctReleaseType;
public string SeriesName;
public int? Season; public int? Season;
public int? Episode; public int? Episode;
public int? EpisodeTo; 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 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 _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 _titleClassicRegex = new Regex(@"(\[[^\]]*\])?\[Cap\.(\d{1,2})(\d{2})([_-](\d{1,2})(\d{2}))?\]", RegexOptions.IgnoreCase);
private Regex _titleClassicTvQualityRegex = new Regex(@"\[([^\]]*HDTV[^\]]*)", RegexOptions.IgnoreCase); private Regex _titleClassicTvQualityRegex = new Regex(@"\[([^\]]*HDTV[^\]]*)", RegexOptions.IgnoreCase);
@ -45,6 +65,9 @@ namespace Jackett.Common.Indexers
private int _maxEpisodesListPages = 100; private int _maxEpisodesListPages = 100;
private int[] _allTvCategories = TorznabCatType.TV.SubCategories.Select(c => c.ID).ToArray(); 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 _dailyUrl = "/ultimas-descargas/pg/{0}";
private string[] _seriesLetterUrls = new string[] { "/series/letter/{0}", "/series-hd/letter/{0}" }; private string[] _seriesLetterUrls = new string[] { "/series/letter/{0}", "/series-hd/letter/{0}" };
private string[] _seriesVOLetterUrls = new string[] { "/series-vo/letter/{0}" }; private string[] _seriesVOLetterUrls = new string[] { "/series-vo/letter/{0}" };
@ -110,6 +133,13 @@ namespace Jackett.Common.Indexers
{ {
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
lock (cache)
{
CleanCache();
}
_dailyNow = DateTime.Now;
_dailyResultIdx = 0;
bool rssMode = string.IsNullOrEmpty(query.SanitizedSearchTerm); bool rssMode = string.IsNullOrEmpty(query.SanitizedSearchTerm);
if (rssMode) if (rssMode)
@ -130,7 +160,7 @@ namespace Jackett.Common.Indexers
bool recentFound = _mostRecentRelease != null && bool recentFound = _mostRecentRelease != null &&
items.Any(r => r.Title == _mostRecentRelease.Title && r.Link.AbsoluteUri == _mostRecentRelease.Link.AbsoluteUri); items.Any(r => r.Title == _mostRecentRelease.Title && r.Link.AbsoluteUri == _mostRecentRelease.Link.AbsoluteUri);
if (pg == 1) if (pg == 1)
_mostRecentRelease = (ReleaseInfo)items.First().Clone(); _mostRecentRelease = (NewpctRelease)items.First().Clone();
if (recentFound) if (recentFound)
break; break;
@ -153,7 +183,7 @@ namespace Jackett.Common.Indexers
private async Task<IEnumerable<ReleaseInfo>> TvSearch(TorznabQuery query) private async Task<IEnumerable<ReleaseInfo>> TvSearch(TorznabQuery query)
{ {
var newpctReleases = new List<ReleaseInfo>(); List<ReleaseInfo> newpctReleases = null;
string seriesName = query.SanitizedSearchTerm; string seriesName = query.SanitizedSearchTerm;
int? season = query.Season > 0 ? (int?)query.Season : null; int? season = query.Season > 0 ? (int?)query.Season : null;
@ -174,22 +204,17 @@ namespace Jackett.Common.Indexers
} }
//Try to reuse cache //Try to reuse cache
bool cacheFound = false;
lock (cache) lock (cache)
{ {
CleanCache();
var cachedResult = cache.FirstOrDefault(i => i.Query == seriesName.ToLower()); var cachedResult = cache.FirstOrDefault(i => i.Query == seriesName.ToLower());
if (cachedResult != null && cachedResult.Results != null) if (cachedResult != null)
{ newpctReleases = cachedResult.Results.Select(r => (ReleaseInfo)r.Clone()).ToList();
cacheFound = true;
newpctReleases = cachedResult.Results.Where(r => (r as NewpctRelease) != null).ToList();
if (!newpctReleases.Any() && cachedResult.Results.Any())
cacheFound = false;
}
} }
if (!cacheFound) if (newpctReleases == null)
{ {
newpctReleases = new List<ReleaseInfo>();
//Search series url //Search series url
foreach (Uri seriesListUrl in SeriesListUris(seriesName)) foreach (Uri seriesListUrl in SeriesListUris(seriesName))
{ {
@ -288,7 +313,11 @@ namespace Jackett.Common.Indexers
foreach (var row in rows) foreach (var row in rows)
{ {
var anchor = row.QuerySelector("a"); 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 detailsUrl = anchor.GetAttribute("href");
var span = row.QuerySelector("span"); var span = row.QuerySelector("span");
@ -298,16 +327,17 @@ namespace Jackett.Common.Indexers
var div = row.QuerySelector("div"); var div = row.QuerySelector("div");
var language = div.ChildNodes[1].TextContent.Trim(); var language = div.ChildNodes[1].TextContent.Trim();
_dailyResultIdx++;
NewpctRelease newpctRelease; NewpctRelease newpctRelease;
if (releaseType == ReleaseType.TV) if (releaseType == ReleaseType.TV)
newpctRelease = GetReleaseFromData(releaseType, newpctRelease = GetReleaseFromData(releaseType,
string.Format("Serie {0} - {1} Calidad [{2}]", title, language, quality), 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 else
newpctRelease = GetReleaseFromData(releaseType, newpctRelease = GetReleaseFromData(releaseType,
string.Format("{0} [{1}][{2}]", title, quality, language), 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); 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 GetReleaseFromData(ReleaseType releaseType, string title, string detailsUrl, string quality, string language, long size, DateTime publishDate)
{ {
NewpctRelease result = new NewpctRelease(); NewpctRelease result = new NewpctRelease();
result.NewpctReleaseType = releaseType;
//Sanitize //Sanitize
title = title.Replace("\t", "").Replace("\x2013", "-"); title = title.Replace("\t", "").Replace("\x2013", "-");
@ -398,30 +429,30 @@ namespace Jackett.Common.Indexers
Match match = _titleListRegex.Match(title); Match match = _titleListRegex.Match(title);
if (match.Success) if (match.Success)
{ {
result.SerieName = match.Groups[1].Value.Trim(' ', '-'); result.SeriesName = match.Groups[2].Value.Trim(' ', '-');
result.Season = int.Parse(match.Groups[4].Success ? match.Groups[4].Value.Trim() : "1"); result.Season = int.Parse(match.Groups[5].Success ? match.Groups[5].Value.Trim() : "1");
result.Episode = int.Parse(match.Groups[7].Value.Trim().PadLeft(2, '0')); result.Episode = int.Parse(match.Groups[8].Value.Trim().PadLeft(2, '0'));
result.EpisodeTo = match.Groups[10].Success ? (int?)int.Parse(match.Groups[10].Value.Trim()) : null; result.EpisodeTo = match.Groups[11].Success ? (int?)int.Parse(match.Groups[11].Value.Trim()) : null;
string audioQuality = match.Groups[12].Value.Trim(' ', '[', ']'); string audioQuality = match.Groups[13].Value.Trim(' ', '[', ']');
quality = match.Groups[13].Value.Trim(' ', '[', ']'); quality = match.Groups[14].Value.Trim(' ', '[', ']');
string seasonText = result.Season.ToString(); string seasonText = result.Season.ToString();
string episodeText = seasonText + result.Episode.ToString().PadLeft(2, '0'); string episodeText = seasonText + result.Episode.ToString().PadLeft(2, '0');
string episodeToText = result.EpisodeTo.HasValue ? "_" + seasonText + result.EpisodeTo.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.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 else
{ {
Match matchClassic = _titleClassicRegex.Match(title); Match matchClassic = _titleClassicRegex.Match(title);
if (matchClassic.Success) if (matchClassic.Success)
{ {
result.Season = matchClassic.Groups[2].Success ? (int?)int.Parse(matchClassic.Groups[2].Value) : null; result.Season = matchClassic.Groups[3].Success ? (int?)int.Parse(matchClassic.Groups[3].Value) : null;
result.Episode = 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[6].Success ? (int?)int.Parse(matchClassic.Groups[6].Value) : null; result.EpisodeTo = matchClassic.Groups[7].Success ? (int?)int.Parse(matchClassic.Groups[7].Value) : null;
if (matchClassic.Groups[1].Success) if (matchClassic.Groups[2].Success)
quality = matchClassic.Groups[1].Value; quality = matchClassic.Groups[2].Value;
} }
result.Title = title; result.Title = title;
@ -454,27 +485,30 @@ namespace Jackett.Common.Indexers
private string FixedTitle(NewpctRelease release, string quality) 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("-")) 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)) if (String.IsNullOrEmpty(quality))
{ {
quality = "HDTV"; 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>(); var titleParts = new List<string>();
titleParts.Add(release.SerieName); titleParts.Add(release.SeriesName);
titleParts.Add(seasonAndEpisode); 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("]", "")); titleParts.Add(quality.Replace("[", "").Replace("]", ""));
if (release.Title.ToLower().Contains("esp") || release.Title.ToLower().Contains("cast")) 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, protected ReleaseInfo(ReleaseInfo copyFrom)
Guid = Guid, {
Link = Link, Title = copyFrom.Title;
Comments = Comments, Guid = copyFrom.Guid;
PublishDate = PublishDate, Link = copyFrom.Link;
Category = Category, Comments = copyFrom.Comments;
Size = Size, PublishDate = copyFrom.PublishDate;
Files = Files, Category = copyFrom.Category;
Grabs = Grabs, Size = copyFrom.Size;
Description = Description, Files = copyFrom.Files;
RageID = RageID, Grabs = copyFrom.Grabs;
Imdb = Imdb, Description = copyFrom.Description;
TMDb = TMDb, RageID = copyFrom.RageID;
Seeders = Seeders, Imdb = copyFrom.Imdb;
Peers = Peers, TMDb = copyFrom.TMDb;
BannerUrl = BannerUrl, Seeders = copyFrom.Seeders;
InfoHash = InfoHash, Peers = copyFrom.Peers;
MagnetUri = MagnetUri, BannerUrl = copyFrom.BannerUrl;
MinimumRatio = MinimumRatio, InfoHash = copyFrom.InfoHash;
MinimumSeedTime = MinimumSeedTime, MagnetUri = copyFrom.MagnetUri;
DownloadVolumeFactor = DownloadVolumeFactor, MinimumRatio = copyFrom.MinimumRatio;
UploadVolumeFactor = UploadVolumeFactor MinimumSeedTime = copyFrom.MinimumSeedTime;
}; DownloadVolumeFactor = copyFrom.DownloadVolumeFactor;
UploadVolumeFactor = copyFrom.UploadVolumeFactor;
}
public virtual object Clone()
{
return new ReleaseInfo(this);
} }
// ex: " 3.5 gb " // ex: " 3.5 gb "