@cosmetic Added Parsing Library: A dotnet library that "exports" our parsing interface.

pull/3378/head
Leonardo Galli 5 years ago
parent 9bc50749ae
commit 4015ff08a6

@ -83,7 +83,9 @@ namespace NzbDrone.Core.CustomFormats
var tuple = Value as (long, long)? ?? (0, 0);
return size > tuple.Item1 && size < tuple.Item2;
case TagType.Indexer:
#if !LIBRARY
return (movieInfo.ExtraInfo.GetValueOrDefault("IndexerFlags") as IndexerFlags?)?.HasFlag((IndexerFlags) Value) == true;
#endif
default:
return false;
}
@ -188,6 +190,7 @@ namespace NzbDrone.Core.CustomFormats
Value = Parser.LanguageParser.ParseLanguages(value).First();
break;
case "i":
#if !LIBRARY
TagType = TagType.Indexer;
var flagValues = Enum.GetValues(typeof(IndexerFlags));
@ -198,7 +201,7 @@ namespace NzbDrone.Core.CustomFormats
Value = flagValue;
break;
}
#endif
break;
case "g":
TagType = TagType.Size;

@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !LIBRARY
using NzbDrone.Common.EnsureThat;
#endif
namespace NzbDrone.Core
{
@ -10,8 +12,9 @@ namespace NzbDrone.Core
{
public static string WithDefault(this string actual, object defaultValue)
{
#if !LIBRARY
Ensure.That(defaultValue, () => defaultValue).IsNotNull();
#endif
if (string.IsNullOrWhiteSpace(actual))
{
return defaultValue.ToString();

@ -142,7 +142,9 @@ namespace NzbDrone.Core.Parser
{
try
{
#if !LIBRARY
Logger.Debug("Parsing language from subtitle file: {0}", fileName);
#endif
var simpleFilename = Path.GetFileNameWithoutExtension(fileName);
var languageMatch = SubtitleLanguageRegex.Match(simpleFilename);
@ -154,12 +156,15 @@ namespace NzbDrone.Core.Parser
return isoLanguage?.Language ?? Language.Unknown;
}
#if !LIBRARY
Logger.Debug("Unable to parse langauge from subtitle file: {0}", fileName);
#endif
}
catch (Exception ex)
{
#if !LIBRARY
Logger.Debug("Failed parsing langauge from subtitle file: {0}", fileName);
#endif
}
return Language.Unknown;

@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Parser.Model
@ -39,14 +38,39 @@ namespace NzbDrone.Core.Parser.Model
public int Year { get; set; }
public string ImdbId { get; set; }
public ParsedMovieInfo()
public override string ToString()
{
return String.Format("{0} - {1} {2}", MovieTitle, Year, Quality);
}
public override string ToString()
#if LIBRARY
public static ParsedMovieInfo ParseMovieInfo(string title)
{
return string.Format("{0} - {1} {2}", MovieTitle, Year, Quality);
var parsedMovie = Parser.ParseMovieTitle(title, false);
if (parsedMovie == null) return null;
parsedMovie.Languages = LanguageParser.ParseLanguages(parsedMovie.SimpleReleaseTitle);
parsedMovie.Quality = QualityParser.ParseQuality(parsedMovie.SimpleReleaseTitle);
if (parsedMovie.Edition.IsNullOrWhiteSpace())
{
parsedMovie.Edition = Parser.ParseEdition(parsedMovie.SimpleReleaseTitle);
}
parsedMovie.ReleaseGroup = Parser.ParseReleaseGroup(parsedMovie.SimpleReleaseTitle);
parsedMovie.ImdbId = Parser.ParseImdbId(parsedMovie.SimpleReleaseTitle);
parsedMovie.Languages =
LanguageParser.EnhanceLanguages(parsedMovie.SimpleReleaseTitle, parsedMovie.Languages);
parsedMovie.Quality.Quality = Qualities.Quality.FindByInfo(parsedMovie.Quality.Source, parsedMovie.Quality.Resolution,
parsedMovie.Quality.Modifier);
return parsedMovie;
}
#endif
}
}

@ -4,13 +4,15 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Parser.Model;
using NLog;
using NzbDrone.Common.Instrumentation;
#if !LIBRARY
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Movies;
using TinyIoC;
#endif
namespace NzbDrone.Core.Parser
{
@ -463,27 +465,6 @@ namespace NzbDrone.Core.Parser
return title;
}
private static SeriesTitleInfo GetSeriesTitleInfo(string title)
{
var seriesTitleInfo = new SeriesTitleInfo();
seriesTitleInfo.Title = title;
var match = YearInTitleRegex.Match(title);
if (!match.Success)
{
seriesTitleInfo.TitleWithoutYear = title;
}
else
{
seriesTitleInfo.TitleWithoutYear = match.Groups["title"].Value;
seriesTitleInfo.Year = Convert.ToInt32(match.Groups["year"].Value);
}
return seriesTitleInfo;
}
private static ParsedMovieInfo ParseMovieMatchCollection(MatchCollection matchCollection)
{
if (!matchCollection[0].Groups["title"].Success || matchCollection[0].Groups["title"].Value == "(")

@ -147,7 +147,7 @@ namespace NzbDrone.Core.Qualities
{
AllLookup[quality.Id] = quality;
}
#if !LIBRARY
DefaultQualityDefinitions = new HashSet<QualityDefinition>
{
new QualityDefinition(Quality.Unknown) { Weight = 1, MinSize = 0, MaxSize = 100 },
@ -182,14 +182,16 @@ namespace NzbDrone.Core.Qualities
new QualityDefinition(Quality.BRDISK) { Weight = 25, MinSize = 0, MaxSize = null },
new QualityDefinition(Quality.RAWHD) { Weight = 26, MinSize = 0, MaxSize = null }
};
#endif
}
public static readonly List<Quality> All;
public static readonly Quality[] AllLookup;
#if !LIBRARY
public static readonly HashSet<QualityDefinition> DefaultQualityDefinitions;
#endif
public static Quality FindById(int id)
{
if (id == 0) return Unknown;

@ -90,6 +90,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogentriesNLog", "Logentrie
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CurlSharp", "ExternalModules\CurlSharp\CurlSharp\CurlSharp.csproj", "{74420A79-CC16-442C-8B1E-7C1B913844F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParsingLibrary", "ParsingLibrary\ParsingLibrary.csproj", "{BAC762EF-4627-49C8-BC99-EB9D20682FA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@ -276,6 +278,12 @@ Global
{74420A79-CC16-442C-8B1E-7C1B913844F0}.Mono|x86.Build.0 = Release|Any CPU
{74420A79-CC16-442C-8B1E-7C1B913844F0}.Release|x86.ActiveCfg = Release|Any CPU
{74420A79-CC16-442C-8B1E-7C1B913844F0}.Release|x86.Build.0 = Release|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Debug|x86.ActiveCfg = Debug|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Debug|x86.Build.0 = Debug|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Mono|x86.ActiveCfg = Debug|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Mono|x86.Build.0 = Debug|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Release|x86.ActiveCfg = Release|Any CPU
{BAC762EF-4627-49C8-BC99-EB9D20682FA4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,18 @@
using System;
using NLog;
namespace NzbDrone.Common.Instrumentation
{
public static class NzbDroneLogger
{
public static Logger GetLogger(Type type)
{
return LogManager.GetLogger(type.Name.Replace("NzbDrone.", ""));
}
public static Logger GetLogger(object obj)
{
return GetLogger(obj.GetType());
}
}
}

@ -0,0 +1,95 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD2_0;LIBRARY;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;RELEASE;NETSTANDARD;NETSTANDARD2_0;LIBRARY</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\NzbDrone.Common\Exceptions\NzbDroneException.cs">
<Link>NzbDroneException.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Common\Extensions\DictionaryExtensions.cs">
<Link>DictionaryExtensions.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Common\Extensions\IEnumerableExtensions.cs">
<Link>IEnumerableExtensions.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Common\Extensions\Int64Extensions.cs">
<Link>Int64Extensions.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Common\Extensions\StringExtensions.cs">
<Link>StringExtensions.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\CustomFormats\CustomFormat.cs">
<Link>CustomFormat.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\CustomFormats\FormatTag.cs">
<Link>FormatTag.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Datastore\IEmbeddedDocument.cs">
<Link>IEmbeddedDocument.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Datastore\ModelBase.cs">
<Link>ModelBase.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Fluent.cs">
<Link>Fluent.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\MediaFiles\MediaFileExtensions.cs">
<Link>MediaFileExtensions.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\InvalidDateException.cs">
<Link>InvalidDateException.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\IsoLanguage.cs">
<Link>IsoLanguage.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\IsoLanguages.cs">
<Link>IsoLanguages.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\Language.cs">
<Link>Language.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\LanguageParser.cs">
<Link>LanguageParser.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\Model\ParsedMovieInfo.cs">
<Link>ParsedMovieInfo.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\Parser.cs">
<Link>Parser.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\QualityParser.cs">
<Link>QualityParser.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Parser\SceneChecker.cs">
<Link>SceneChecker.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Qualities\Quality.cs">
<Link>Quality.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Qualities\QualityModel.cs">
<Link>QualityModel.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Qualities\QualitySource.cs">
<Link>QualitySource.cs</Link>
</Compile>
<Compile Include="..\NzbDrone.Core\Qualities\Revision.cs">
<Link>Revision.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="NLog" Version="4.5.11" />
</ItemGroup>
</Project>

@ -0,0 +1,12 @@
using System.IO;
namespace NzbDrone.Common.Extensions
{
public static class PathExtensions
{
public static bool ContainsInvalidPathChars(this string text)
{
return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0;
}
}
}
Loading…
Cancel
Save