From 17f544be36148c6642e3cc9ceadf87086fbbfc15 Mon Sep 17 00:00:00 2001 From: chibidev Date: Tue, 11 Jul 2017 22:32:56 +0200 Subject: [PATCH 1/2] Bugfix/1532 1539 fix manual search circular reference (#1543) * Line endings... * Encoding Encoding in a reasonable way Sadly Encoding contains a self-reference somewhere, which makes it really hard for the json serializer to automatically encode it... Probably there's no value in sending it over especially since no one is using it, however just for the sake of the argument, let's just serialize it in a reasonable way. Maybe someday there will be someone expecting this. Or we clearly separate DTOs and models... - Fixes Jackett/Jackett#1532 - Fixes Jackett/Jackett#1539 * Seriously... Please port this to dotnet Core so that I can use something other than @drunkvs on my MacBook * Fix autofac registration after merge * "Implement" new function of interface in test project --- .../TestIIndexerManagerServiceHelper.cs | 5 + src/Jackett.sln | 20 +- src/Jackett/Indexers/BaseIndexer.cs | 3 + src/Jackett/Jackett.csproj | 1 + src/Jackett/JackettModule.cs | 190 ++++++++++-------- src/Jackett/Utils/JsonUtil.cs | 30 +++ 6 files changed, 164 insertions(+), 85 deletions(-) create mode 100644 src/Jackett/Utils/JsonUtil.cs 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(); + } + } +} From dc38f8c041b0237ca4353d878582a327f577aacd Mon Sep 17 00:00:00 2001 From: chibidev Date: Wed, 12 Jul 2017 06:34:14 +0200 Subject: [PATCH 2/2] Bugfix/fix nyoo indexer (#1547) * Line endings... * Adjusting selectors --- src/Jackett/Definitions/nyoo.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Jackett/Definitions/nyoo.yml b/src/Jackett/Definitions/nyoo.yml index 3bd2d9c0d..7bfd224ea 100644 --- a/src/Jackett/Definitions/nyoo.yml +++ b/src/Jackett/Definitions/nyoo.yml @@ -39,24 +39,24 @@ page: "search" q: "{{ .Query.Keywords}}" rows: - selector: tr.tlistrow + selector: tr.torrent-info fields: title: - selector: td.tlistname a + selector: td.tr-name a category: - selector: td.tlisticon a + selector: td.tr-cat div.nyaa-cat a attribute: href filters: - name: split args: [ "=", -1 ] details: - selector: td.tlistname a + selector: td.tr-name a attribute: href download: - selector: a[title="Magnet Download"] + selector: a[title="Magnet Link"] attribute: href size: - selector: td.tlistsize + selector: td.tr-size # seeders: # text: 0 # seeders: