CategoryMapping: Add support for the tracker category description

This commit is contained in:
kaso17
2016-12-17 16:42:50 +01:00
parent 7b2dd93f2f
commit 5fc7fca5c6
4 changed files with 29 additions and 10 deletions

View File

@@ -118,7 +118,6 @@ namespace Jackett.Indexers
{ {
if (null != input) if (null != input)
{ {
input = input.ToLowerInvariant();
var mapping = categoryMapping.Where(m => m.TrackerCategory.ToLowerInvariant() == input.ToLowerInvariant()).FirstOrDefault(); var mapping = categoryMapping.Where(m => m.TrackerCategory.ToLowerInvariant() == input.ToLowerInvariant()).FirstOrDefault();
if (mapping != null) if (mapping != null)
{ {
@@ -128,6 +127,19 @@ namespace Jackett.Indexers
return 0; return 0;
} }
protected int MapTrackerCatDescToNewznab(string input)
{
if (null != input)
{
var mapping = categoryMapping.Where(m => m.TrackerCategoryDesc.ToLowerInvariant() == input.ToLowerInvariant()).FirstOrDefault();
if (mapping != null)
{
return mapping.NewzNabCategory;
}
}
return 0;
}
public static string GetIndexerID(Type type) public static string GetIndexerID(Type type)
{ {
return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant()); return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant());
@@ -484,16 +496,16 @@ namespace Jackett.Indexers
} }
} }
protected void AddCategoryMapping(string trackerCategory, TorznabCategory newznabCategory) protected void AddCategoryMapping(string trackerCategory, TorznabCategory newznabCategory, string trackerCategoryDesc = null)
{ {
categoryMapping.Add(new CategoryMapping(trackerCategory, newznabCategory.ID)); categoryMapping.Add(new CategoryMapping(trackerCategory, trackerCategoryDesc, newznabCategory.ID));
if (!TorznabCaps.Categories.Contains(newznabCategory)) if (!TorznabCaps.Categories.Contains(newznabCategory))
TorznabCaps.Categories.Add(newznabCategory); TorznabCaps.Categories.Add(newznabCategory);
} }
protected void AddCategoryMapping(int trackerCategory, TorznabCategory newznabCategory) protected void AddCategoryMapping(int trackerCategory, TorznabCategory newznabCategory, string trackerCategoryDesc = null)
{ {
AddCategoryMapping(trackerCategory.ToString(), newznabCategory); AddCategoryMapping(trackerCategory.ToString(), newznabCategory, trackerCategoryDesc);
} }
protected void AddMultiCategoryMapping(TorznabCategory newznabCategory, params int[] trackerCategories) protected void AddMultiCategoryMapping(TorznabCategory newznabCategory, params int[] trackerCategories)

View File

@@ -166,7 +166,7 @@ namespace Jackett.Indexers
protected void AddResultCategoryMapping(string trackerCategory, TorznabCategory newznabCategory) protected void AddResultCategoryMapping(string trackerCategory, TorznabCategory newznabCategory)
{ {
resultMapping.Add(new CategoryMapping(trackerCategory.ToString(), newznabCategory.ID)); resultMapping.Add(new CategoryMapping(trackerCategory.ToString(), null, newznabCategory.ID));
if (!TorznabCaps.Categories.Contains(newznabCategory)) if (!TorznabCaps.Categories.Contains(newznabCategory))
TorznabCaps.Categories.Add(newznabCategory); TorznabCaps.Categories.Add(newznabCategory);
} }

View File

@@ -8,13 +8,15 @@ namespace Jackett.Models
{ {
class CategoryMapping class CategoryMapping
{ {
public CategoryMapping(string trackerCat, int newzCat) public CategoryMapping(string trackerCat, string trackerCatDesc, int newzCat)
{ {
TrackerCategory = trackerCat; TrackerCategory = trackerCat;
TrackerCategoryDesc = trackerCatDesc;
NewzNabCategory = newzCat; NewzNabCategory = newzCat;
} }
public string TrackerCategory { get; private set; } public string TrackerCategory { get; private set; }
public string TrackerCategoryDesc { get; private set; }
public int NewzNabCategory { get; private set; } public int NewzNabCategory { get; private set; }
} }
} }

View File

@@ -13,6 +13,13 @@ namespace Jackett.Utils
{ {
public static string RFC1123ZPattern = "ddd, dd MMM yyyy HH':'mm':'ss z"; public static string RFC1123ZPattern = "ddd, dd MMM yyyy HH':'mm':'ss z";
public static DateTime UnixTimestampToDateTime(long unixTime)
{
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dt = dt.AddSeconds(unixTime).ToLocalTime();
return dt;
}
public static DateTime UnixTimestampToDateTime(double unixTime) public static DateTime UnixTimestampToDateTime(double unixTime)
{ {
DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
@@ -170,9 +177,7 @@ namespace Jackett.Utils
{ {
// try parsing the str as an unix timestamp // try parsing the str as an unix timestamp
var unixTimeStamp = long.Parse(str); var unixTimeStamp = long.Parse(str);
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); return UnixTimestampToDateTime(unixTimeStamp);
dt = dt.AddSeconds(unixTimeStamp).ToLocalTime();
return dt;
} }
catch (FormatException) catch (FormatException)
{ {