diff --git a/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs b/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs index 9dc538dd4..086547dd5 100644 --- a/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs +++ b/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs @@ -28,6 +28,11 @@ namespace JackettTest throw new NotImplementedException(); } + public IWebIndexer GetWebIndexer(string name) + { + throw new NotImplementedException(); + } + public void InitIndexers() { throw new NotImplementedException(); diff --git a/src/Jackett.sln b/src/Jackett.sln index 8452eab09..4078be628 100644 --- a/src/Jackett.sln +++ b/src/Jackett.sln @@ -96,11 +96,25 @@ Global $2.SpacesBeforeBrackets = False $2.scope = text/x-csharp $2.IndentSwitchSection = True + $2.NewLinesForBracesInProperties = True + $2.NewLinesForBracesInAccessors = True + $2.NewLinesForBracesInAnonymousMethods = True + $2.NewLinesForBracesInControlBlocks = True + $2.NewLinesForBracesInAnonymousTypes = True + $2.NewLinesForBracesInObjectCollectionArrayInitializers = True + $2.NewLinesForBracesInLambdaExpressionBody = True + $2.NewLineForElse = True + $2.NewLineForCatch = True + $2.NewLineForFinally = True + $2.NewLineForMembersInObjectInit = True + $2.NewLineForMembersInAnonymousTypes = True + $2.NewLineForClausesInQuery = True $2.SpacingAfterMethodDeclarationName = False $2.SpaceAfterMethodCallName = False $2.SpaceBeforeOpenSquareBracket = False - $0.DotNetNamingPolicy = $3 - $3.DirectoryNamespaceAssociation = PrefixedHierarchical - $0.StandardHeader = $4 + $0.TextStylePolicy = $3 + $3.FileWidth = 80 + $3.TabsToSpaces = True + $3.scope = text/plain EndGlobalSection EndGlobal diff --git a/src/Jackett/Indexers/BaseIndexer.cs b/src/Jackett/Indexers/BaseIndexer.cs index 03d2d2e12..760234d9d 100644 --- a/src/Jackett/Indexers/BaseIndexer.cs +++ b/src/Jackett/Indexers/BaseIndexer.cs @@ -12,6 +12,7 @@ using Jackett.Utils.Clients; using AutoMapper; using Jackett.Models.IndexerConfig; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace Jackett.Indexers { @@ -691,6 +692,8 @@ namespace Jackett.Indexers } public override TorznabCapabilities TorznabCaps { get; protected set; } + + [JsonConverter(typeof(EncodingJsonConverter))] public Encoding Encoding { get; protected set; } private List categoryMapping = new List(); diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index 2cf721c26..8c5337c4a 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -377,6 +377,7 @@ + diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index 73a56fe9d..31d8cc9b0 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -18,68 +18,79 @@ namespace Jackett { public class JackettModule : Autofac.Module { - protected override void Load (ContainerBuilder builder) + protected override void Load(ContainerBuilder builder) { // Just register everything! - var thisAssembly = typeof (JackettModule).Assembly; - builder.RegisterAssemblyTypes (thisAssembly) - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () - .Except () + var thisAssembly = typeof(JackettModule).Assembly; + builder.RegisterAssemblyTypes(thisAssembly) + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() + .Except() .Except() - .AsImplementedInterfaces ().SingleInstance (); - builder.RegisterApiControllers (thisAssembly).InstancePerRequest (); - builder.RegisterType (); + .AsImplementedInterfaces().SingleInstance(); + builder.RegisterApiControllers(thisAssembly).InstancePerRequest(); + builder.RegisterType(); // Register the best web client for the platform or the override - switch (Startup.ClientOverride) { - case "httpclient": - builder.RegisterType ().As (); - break; - case "httpclient2": - builder.RegisterType ().As (); - break; - case "safecurl": - builder.RegisterType ().As (); - break; - case "libcurl": - builder.RegisterType ().As (); - break; - case "automatic": - default: - if (System.Environment.OSVersion.Platform == PlatformID.Unix) { - var usehttpclient = false; - try { - Type monotype = Type.GetType ("Mono.Runtime"); - if (monotype != null) { - MethodInfo displayName = monotype.GetMethod ("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); - if (displayName != null) { - var monoVersion = displayName.Invoke (null, null).ToString (); - var monoVersionO = new Version (monoVersion.Split (' ') [0]); - if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5) { - // check if btls is supported - var monoSecurity = Assembly.Load ("Mono.Security"); - Type monoTlsProviderFactory = monoSecurity.GetType ("Mono.Security.Interface.MonoTlsProviderFactory"); - if (monoTlsProviderFactory != null) { - MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod ("IsProviderSupported"); - if (isProviderSupported != null) { - var btlsSupported = (bool)isProviderSupported.Invoke (null, new string [] { "btls" }); - if (btlsSupported) { - // initialize btls - MethodInfo initialize = monoTlsProviderFactory.GetMethod ("Initialize", new [] { typeof (string) }); - if (initialize != null) { - initialize.Invoke (null, new string [] { "btls" }); - usehttpclient = true; + switch (Startup.ClientOverride) + { + case "httpclient": + builder.RegisterType().As(); + break; + case "httpclient2": + builder.RegisterType().As(); + break; + case "safecurl": + builder.RegisterType().As(); + break; + case "libcurl": + builder.RegisterType().As(); + break; + case "automatic": + default: + if (System.Environment.OSVersion.Platform == PlatformID.Unix) + { + var usehttpclient = false; + try + { + Type monotype = Type.GetType("Mono.Runtime"); + if (monotype != null) + { + MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); + if (displayName != null) + { + var monoVersion = displayName.Invoke(null, null).ToString(); + var monoVersionO = new Version(monoVersion.Split(' ')[0]); + if ((monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) || monoVersionO.Major >= 5) + { + // check if btls is supported + var monoSecurity = Assembly.Load("Mono.Security"); + Type monoTlsProviderFactory = monoSecurity.GetType("Mono.Security.Interface.MonoTlsProviderFactory"); + if (monoTlsProviderFactory != null) + { + MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod("IsProviderSupported"); + if (isProviderSupported != null) + { + var btlsSupported = (bool)isProviderSupported.Invoke(null, new string[] { "btls" }); + if (btlsSupported) + { + // initialize btls + MethodInfo initialize = monoTlsProviderFactory.GetMethod("Initialize", new[] { typeof(string) }); + if (initialize != null) + { + initialize.Invoke(null, new string[] { "btls" }); + usehttpclient = true; + } } } } @@ -87,45 +98,60 @@ namespace Jackett } } } - } catch (Exception e) { - Console.Out.WriteLine ("Error while deciding which HttpWebClient to use: " + e); - } + catch (Exception e) + { + Console.Out.WriteLine("Error while deciding which HttpWebClient to use: " + e); + } - if (usehttpclient) - builder.RegisterType ().As (); + if (usehttpclient) + builder.RegisterType().As(); + else + builder.RegisterType().As(); + } else - builder.RegisterType ().As (); - } else { - builder.RegisterType ().As (); - } - break; + { + builder.RegisterType().As(); + } + break; } // Register indexers - var indexerTypes = thisAssembly.GetTypes ().Where (p => typeof (IIndexer).IsAssignableFrom (p) && !p.IsInterface && !p.IsInNamespace ("Jackett.Indexers.Meta")); - foreach (var indexer in indexerTypes) { - builder.RegisterType (indexer).Named (BaseIndexer.GetIndexerID (indexer)); + var allTypes = thisAssembly.GetTypes(); + var allIndexerTypes = allTypes.Where(p => typeof(IIndexer).IsAssignableFrom(p)); + var allInstantiatableIndexerTypes = allIndexerTypes.Where(p => !p.IsInterface && !p.IsAbstract); + var allNonMetaInstantiatableIndexerTypes = allInstantiatableIndexerTypes.Where(p => !typeof(BaseMetaIndexer).IsAssignableFrom(p)); + var indexerTypes = allNonMetaInstantiatableIndexerTypes.Where(p => p.Name != "CardigannIndexer"); + foreach (var indexer in indexerTypes) + { + builder.RegisterType(indexer).Named(BaseIndexer.GetIndexerID(indexer)); } - Mapper.CreateMap ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((be, str) => { - str.Content = Encoding.UTF8.GetString (be.Content); + Mapper.CreateMap().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((be, str) => + { + str.Content = Encoding.UTF8.GetString(be.Content); }); - Mapper.CreateMap ().ForMember (x => x.Content, opt => opt.Ignore ()).AfterMap ((str, be) => { - if (!string.IsNullOrEmpty (str.Content)) { - be.Content = Encoding.UTF8.GetBytes (str.Content); + Mapper.CreateMap().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((str, be) => + { + if (!string.IsNullOrEmpty(str.Content)) + { + be.Content = Encoding.UTF8.GetBytes(str.Content); } }); - Mapper.CreateMap (); - Mapper.CreateMap (); - Mapper.CreateMap (); + Mapper.CreateMap(); + Mapper.CreateMap(); + Mapper.CreateMap(); - Mapper.CreateMap ().AfterMap ((r, t) => { - if (r.Category != null) { - var CategoryDesc = string.Join (", ", r.Category.Select (x => TorznabCatType.GetCatDesc (x)).Where (x => !string.IsNullOrEmpty (x))); + Mapper.CreateMap().AfterMap((r, t) => + { + if (r.Category != null) + { + var CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x))); t.CategoryDesc = CategoryDesc; - } else { + } + else + { t.CategoryDesc = ""; } }); diff --git a/src/Jackett/Utils/JsonUtil.cs b/src/Jackett/Utils/JsonUtil.cs new file mode 100644 index 000000000..9718faeee --- /dev/null +++ b/src/Jackett/Utils/JsonUtil.cs @@ -0,0 +1,30 @@ +using System; +using System.Text; +using Newtonsoft.Json; + +namespace Jackett.Utils +{ + public class EncodingJsonConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return true; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var obj = value as Encoding; + writer.WriteValue(obj.WebName); + } + + public override bool CanRead + { + get { return false; } + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } +}