1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-26 09:48:37 +00:00

AnimeBytes: more fixes

This commit is contained in:
kaso17 2018-04-27 16:52:21 +02:00
parent 08ad94a2f5
commit 2d0e82159d

View file

@ -26,9 +26,6 @@ namespace Jackett.Common.Indexers
public bool AddSynonyms { get { return configData.AddSynonyms.Value; } }
public bool FilterSeasonEpisode { get { return configData.FilterSeasonEpisode.Value; } }
string csrfIndex = null;
string csrfToken = null;
private new ConfigurationDataAnimeBytes configData
{
get { return (ConfigurationDataAnimeBytes)base.configData; }
@ -170,223 +167,226 @@ namespace Jackett.Common.Indexers
if (json["error"] != null)
throw new Exception(json["error"].ToString());
var groups = (JArray)json.Groups;
var Matches = (long)json["Matches"];
foreach (JObject group in groups)
if(Matches > 0)
{
var synonyms = new List<string>();
var groupID = (long)group["ID"];
var Image = (string)group["Image"];
var ImageUrl = (string.IsNullOrWhiteSpace(Image) ? null : new Uri(Image));
var Year = (int)group["Year"];
var GroupName = (string)group["GroupName"];
var SeriesName = (string)group["SeriesName"];
var Artists = (string)group["Artists"];
var groups = (JArray)json.Groups;
var mainTitle = WebUtility.HtmlDecode((string)group["FullName"]);
if (SeriesName != null)
mainTitle = SeriesName;
synonyms.Add(mainTitle);
// If the title contains a comma then we can't use the synonyms as they are comma seperated
if (!mainTitle.Contains(",") && AddSynonyms)
foreach (JObject group in groups)
{
var symnomnNames = WebUtility.HtmlDecode((string)group["Synonymns"]);
var synonyms = new List<string>();
var groupID = (long)group["ID"];
var Image = (string)group["Image"];
var ImageUrl = (string.IsNullOrWhiteSpace(Image) ? null : new Uri(Image));
var Year = (int)group["Year"];
var GroupName = (string)group["GroupName"];
var SeriesName = (string)group["SeriesName"];
var Artists = (string)group["Artists"];
if (!string.IsNullOrWhiteSpace(symnomnNames))
var mainTitle = WebUtility.HtmlDecode((string)group["FullName"]);
if (SeriesName != null)
mainTitle = SeriesName;
synonyms.Add(mainTitle);
// If the title contains a comma then we can't use the synonyms as they are comma seperated
if (!mainTitle.Contains(",") && AddSynonyms)
{
foreach (var name in symnomnNames.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
var symnomnNames = WebUtility.HtmlDecode((string)group["Synonymns"]);
if (!string.IsNullOrWhiteSpace(symnomnNames))
{
var theName = name.Trim();
if (!theName.Contains("&#") && !string.IsNullOrWhiteSpace(theName))
foreach (var name in symnomnNames.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
synonyms.Add(theName);
var theName = name.Trim();
if (!theName.Contains("&#") && !string.IsNullOrWhiteSpace(theName))
{
synonyms.Add(theName);
}
}
}
}
}
List<int> Category = null;
var category = (string)group["CategoryName"];
List<int> Category = null;
var category = (string)group["CategoryName"];
var Description = (string)group["Description"];
var Description = (string)group["Description"];
foreach (JObject torrent in group["Torrents"])
{
var releaseInfo = "S01";
string episode = null;
int? season = null;
var EditionTitle = (string)torrent["EditionData"]["EditionTitle"];
if (!string.IsNullOrWhiteSpace(EditionTitle))
releaseInfo = WebUtility.HtmlDecode(EditionTitle);
Regex SeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled);
var SeasonRegExMatch = SeasonRegEx.Match(releaseInfo);
if (SeasonRegExMatch.Success)
season = ParseUtil.CoerceInt(SeasonRegExMatch.Groups[1].Value);
Regex EpisodeRegEx = new Regex(@"Episode (\d+)", RegexOptions.Compiled);
var EpisodeRegExMatch = EpisodeRegEx.Match(releaseInfo);
if (EpisodeRegExMatch.Success)
episode = EpisodeRegExMatch.Groups[1].Value;
releaseInfo = releaseInfo.Replace("Episode ", "");
releaseInfo = releaseInfo.Replace("Season ", "S");
releaseInfo = releaseInfo.Trim();
int test = 0;
if (InsertSeason && int.TryParse(releaseInfo, out test) && releaseInfo.Length <= 3)
foreach (JObject torrent in group["Torrents"])
{
releaseInfo = "E0" + releaseInfo;
}
var releaseInfo = "S01";
string episode = null;
int? season = null;
var EditionTitle = (string)torrent["EditionData"]["EditionTitle"];
if (!string.IsNullOrWhiteSpace(EditionTitle))
releaseInfo = WebUtility.HtmlDecode(EditionTitle);
if (FilterSeasonEpisode)
{
if (query.Season != 0 && season != null && season != query.Season) // skip if season doesn't match
continue;
if (query.Episode != null && episode != null && episode != query.Episode) // skip if episode doesn't match
continue;
}
var torrentID = (long)torrent["ID"];
logger.Error(torrentID);
var Property = (string)torrent["Property"];
Property = Property.Replace(" | Freeleech", "");
var Link = (string)torrent["Link"];
var LinkUri = new Uri(Link);
var UploadTimeString = (string)torrent["UploadTime"];
var UploadTime = DateTime.ParseExact(UploadTimeString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var PublushDate = DateTime.SpecifyKind(UploadTime, DateTimeKind.Utc).ToLocalTime();
var CommentsLink = TorrentsUrl + "?id=" + groupID.ToString() + "&torrentid=" + torrentID.ToString();
var CommentsLinkUri = new Uri(CommentsLink);
var Size = (long)torrent["Size"];
var Snatched = (long)torrent["Snatched"];
var Seeders = (int)torrent["Seeders"];
var Leechers = (int)torrent["Leechers"];
var FileCount = (long)torrent["FileCount"];
var Peers = Seeders + Leechers;
Regex SeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled);
var SeasonRegExMatch = SeasonRegEx.Match(releaseInfo);
if (SeasonRegExMatch.Success)
season = ParseUtil.CoerceInt(SeasonRegExMatch.Groups[1].Value);
var RawDownMultiplier = (int?)torrent["RawDownMultiplier"];
if (RawDownMultiplier == null)
RawDownMultiplier = 0;
var RawUpMultiplier = (int?)torrent["RawUpMultiplier"];
if (RawUpMultiplier == null)
RawDownMultiplier = 0;
Regex EpisodeRegEx = new Regex(@"Episode (\d+)", RegexOptions.Compiled);
var EpisodeRegExMatch = EpisodeRegEx.Match(releaseInfo);
if (EpisodeRegExMatch.Success)
episode = EpisodeRegExMatch.Groups[1].Value;
if (searchType == "anime")
{
if (category == "TV Series")
Category = new List<int> { TorznabCatType.TVAnime.ID };
releaseInfo = releaseInfo.Replace("Episode ", "");
releaseInfo = releaseInfo.Replace("Season ", "S");
releaseInfo = releaseInfo.Trim();
// Ignore these categories as they'll cause hell with the matcher
// TV Special, OVA, ONA, DVD Special, BD Special
if (category == "Movie")
Category = new List<int> { TorznabCatType.Movies.ID };
if (category == "Manga" || category == "Oneshot" || category == "Anthology" || category == "Manhwa" || category == "Manhua" || category == "Light Novel")
Category = new List<int> { TorznabCatType.BooksComics.ID };
if (category == "Novel" || category == "Artbook")
Category = new List<int> { TorznabCatType.BooksComics.ID };
if (category == "Game" || category == "Visual Novel")
int test = 0;
if (InsertSeason && int.TryParse(releaseInfo, out test) && releaseInfo.Length <= 3)
{
if (Property.Contains(" PSP "))
Category = new List<int> { TorznabCatType.ConsolePSP.ID };
if (Property.Contains("PSX"))
Category = new List<int> { TorznabCatType.ConsoleOther.ID };
if (Property.Contains(" NES "))
Category = new List<int> { TorznabCatType.ConsoleOther.ID };
if (Property.Contains(" PC "))
Category = new List<int> { TorznabCatType.PCGames.ID };
}
}
else if (searchType == "music")
{
if (category == "Single" || category == "EP" || category == "Album" || category == "Compilation" || category == "Soundtrack" || category == "Remix CD" || category == "PV" || category == "Live Album" || category == "Image CD" || category == "Drama CD" || category == "Vocal CD")
{
if (Property.Contains(" Lossless "))
Category = new List<int> { TorznabCatType.AudioLossless.ID };
else if (Property.Contains("MP3"))
Category = new List<int> { TorznabCatType.AudioMP3.ID };
else
Category = new List<int> { TorznabCatType.AudioOther.ID };
}
}
// We dont actually have a release name >.> so try to create one
var releaseTags = Property.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
for (int i = releaseTags.Count - 1; i >= 0; i--)
{
releaseTags[i] = releaseTags[i].Trim();
if (string.IsNullOrWhiteSpace(releaseTags[i]))
releaseTags.RemoveAt(i);
}
var releasegroup = releaseTags.LastOrDefault();
if (releasegroup != null && releasegroup.Contains("(") && releasegroup.Contains(")"))
{
// Skip raws if set
if (releasegroup.ToLowerInvariant().StartsWith("raw") && !AllowRaws)
{
continue;
releaseInfo = "E0" + releaseInfo;
}
var start = releasegroup.IndexOf("(");
releasegroup = "[" + releasegroup.Substring(start + 1, (releasegroup.IndexOf(")") - 1) - start) + "] ";
}
else
{
releasegroup = string.Empty;
}
var infoString = "";
for (int i = 0; i + 1 < releaseTags.Count(); i++)
{
if (releaseTags[i] == "Raw" && !AllowRaws)
continue;
infoString += "[" + releaseTags[i] + "]";
}
var MinimumSeedTime = 259200;
// Additional 5 hours per GB
MinimumSeedTime += (int)((Size / 1000000000) * 18000);
foreach (var title in synonyms)
{
string releaseTitle = null;
if (category == "Movie")
if (FilterSeasonEpisode)
{
var year = 0;
releaseTitle = string.Format("{0} {1} {2}{3}", title, year, group, infoString);
if (query.Season != 0 && season != null && season != query.Season) // skip if season doesn't match
continue;
if (query.Episode != null && episode != null && episode != query.Episode) // skip if episode doesn't match
continue;
}
var torrentID = (long)torrent["ID"];
var Property = (string)torrent["Property"];
Property = Property.Replace(" | Freeleech", "");
var Link = (string)torrent["Link"];
var LinkUri = new Uri(Link);
var UploadTimeString = (string)torrent["UploadTime"];
var UploadTime = DateTime.ParseExact(UploadTimeString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var PublushDate = DateTime.SpecifyKind(UploadTime, DateTimeKind.Utc).ToLocalTime();
var CommentsLink = TorrentsUrl + "?id=" + groupID.ToString() + "&torrentid=" + torrentID.ToString();
var CommentsLinkUri = new Uri(CommentsLink);
var Size = (long)torrent["Size"];
var Snatched = (long)torrent["Snatched"];
var Seeders = (int)torrent["Seeders"];
var Leechers = (int)torrent["Leechers"];
var FileCount = (long)torrent["FileCount"];
var Peers = Seeders + Leechers;
var RawDownMultiplier = (int?)torrent["RawDownMultiplier"];
if (RawDownMultiplier == null)
RawDownMultiplier = 0;
var RawUpMultiplier = (int?)torrent["RawUpMultiplier"];
if (RawUpMultiplier == null)
RawDownMultiplier = 0;
if (searchType == "anime")
{
if (GroupName == "TV Series")
Category = new List<int> { TorznabCatType.TVAnime.ID };
// Ignore these categories as they'll cause hell with the matcher
// TV Special, OVA, ONA, DVD Special, BD Special
if (GroupName == "Movie")
Category = new List<int> { TorznabCatType.Movies.ID };
if (category == "Manga" || category == "Oneshot" || category == "Anthology" || category == "Manhwa" || category == "Manhua" || category == "Light Novel")
Category = new List<int> { TorznabCatType.BooksComics.ID };
if (category == "Novel" || category == "Artbook")
Category = new List<int> { TorznabCatType.BooksComics.ID };
if (category == "Game" || category == "Visual Novel")
{
if (Property.Contains(" PSP "))
Category = new List<int> { TorznabCatType.ConsolePSP.ID };
if (Property.Contains("PSX"))
Category = new List<int> { TorznabCatType.ConsoleOther.ID };
if (Property.Contains(" NES "))
Category = new List<int> { TorznabCatType.ConsoleOther.ID };
if (Property.Contains(" PC "))
Category = new List<int> { TorznabCatType.PCGames.ID };
}
}
else if (searchType == "music")
{
if (category == "Single" || category == "EP" || category == "Album" || category == "Compilation" || category == "Soundtrack" || category == "Remix CD" || category == "PV" || category == "Live Album" || category == "Image CD" || category == "Drama CD" || category == "Vocal CD")
{
if (Property.Contains(" Lossless "))
Category = new List<int> { TorznabCatType.AudioLossless.ID };
else if (Property.Contains("MP3"))
Category = new List<int> { TorznabCatType.AudioMP3.ID };
else
Category = new List<int> { TorznabCatType.AudioOther.ID };
}
}
// We dont actually have a release name >.> so try to create one
var releaseTags = Property.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
for (int i = releaseTags.Count - 1; i >= 0; i--)
{
releaseTags[i] = releaseTags[i].Trim();
if (string.IsNullOrWhiteSpace(releaseTags[i]))
releaseTags.RemoveAt(i);
}
var releasegroup = releaseTags.LastOrDefault();
if (releasegroup != null && releasegroup.Contains("(") && releasegroup.Contains(")"))
{
// Skip raws if set
if (releasegroup.ToLowerInvariant().StartsWith("raw") && !AllowRaws)
{
continue;
}
var start = releasegroup.IndexOf("(");
releasegroup = "[" + releasegroup.Substring(start + 1, (releasegroup.IndexOf(")") - 1) - start) + "] ";
}
else
{
releaseTitle = string.Format("{0}{1} {2} {3}", releasegroup, title, releaseInfo, infoString);
releasegroup = string.Empty;
}
var release = new ReleaseInfo();
release.MinimumRatio = 1;
release.MinimumSeedTime = MinimumSeedTime;
release.Title = releaseTitle;
release.Comments = CommentsLinkUri;
release.Guid = new Uri(CommentsLinkUri + "&nh=" + StringUtil.Hash(title)); // Sonarr should dedupe on this url - allow a url per name.
release.Link = LinkUri;
release.BannerUrl = ImageUrl;
release.PublishDate = PublushDate;
release.Category = Category;
release.Description = Description;
release.Size = Size;
release.Seeders = Seeders;
release.Peers = Peers;
release.Grabs = Snatched;
release.Files = FileCount;
release.DownloadVolumeFactor = RawDownMultiplier;
release.UploadVolumeFactor = RawUpMultiplier;
var infoString = "";
releases.Add(release);
for (int i = 0; i + 1 < releaseTags.Count(); i++)
{
if (releaseTags[i] == "Raw" && !AllowRaws)
continue;
infoString += "[" + releaseTags[i] + "]";
}
var MinimumSeedTime = 259200;
// Additional 5 hours per GB
MinimumSeedTime += (int)((Size / 1000000000) * 18000);
foreach (var title in synonyms)
{
string releaseTitle = null;
if (GroupName == "Movie")
{
releaseTitle = string.Format("{0} {1} {2}{3}", title, Year, releasegroup, infoString);
}
else
{
releaseTitle = string.Format("{0}{1} {2} {3}", releasegroup, title, releaseInfo, infoString);
}
var release = new ReleaseInfo();
release.MinimumRatio = 1;
release.MinimumSeedTime = MinimumSeedTime;
release.Title = releaseTitle;
release.Comments = CommentsLinkUri;
release.Guid = new Uri(CommentsLinkUri + "&nh=" + StringUtil.Hash(title)); // Sonarr should dedupe on this url - allow a url per name.
release.Link = LinkUri;
release.BannerUrl = ImageUrl;
release.PublishDate = PublushDate;
release.Category = Category;
release.Description = Description;
release.Size = Size;
release.Seeders = Seeders;
release.Peers = Peers;
release.Grabs = Snatched;
release.Files = FileCount;
release.DownloadVolumeFactor = RawDownMultiplier;
release.UploadVolumeFactor = RawUpMultiplier;
releases.Add(release);
}
}
}
}