parent
ae63373b2b
commit
a85979c2f6
|
@ -239,6 +239,14 @@ namespace NzbDrone.Core.Test.ParserTests
|
||||||
result.Language.Id.Should().Be(Language.Arabic.Id);
|
result.Language.Id.Should().Be(Language.Arabic.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("The Shadow Series S01 E01-08 WebRip Dual Audio [Hindi 5.1 + English 5.1] 720p x264 AAC ESub")]
|
||||||
|
[TestCase("The Final Sonarr (2020) S04 Complete 720p NF WEBRip [Hindi+English] Dual audio")]
|
||||||
|
public void should_parse_language_hindi(string postTitle)
|
||||||
|
{
|
||||||
|
var result = Parser.Parser.ParseTitle(postTitle);
|
||||||
|
result.Language.Id.Should().Be(Language.Hindi.Id);
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase("Title.the.Russian.Series.S01E07.Cold.Action.HDTV.XviD-Droned")]
|
[TestCase("Title.the.Russian.Series.S01E07.Cold.Action.HDTV.XviD-Droned")]
|
||||||
[TestCase("Title.the.Russian.Series.S01E07E08.Cold.Action.HDTV.XviD-Droned")]
|
[TestCase("Title.the.Russian.Series.S01E07E08.Cold.Action.HDTV.XviD-Droned")]
|
||||||
[TestCase("Title.the.Russian.Series.S01.1080p.WEBRip.DDP5.1.x264-Drone")]
|
[TestCase("Title.the.Russian.Series.S01.1080p.WEBRip.DDP5.1.x264-Drone")]
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentMigrator;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Migration(155)]
|
||||||
|
public class add_arabic_and_hindi_languages : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Execute.WithConnection(ConvertProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConvertProfile(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
var updater = new LanguageProfileUpdater128(conn, tran);
|
||||||
|
|
||||||
|
updater.AppendMissing();
|
||||||
|
|
||||||
|
updater.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LanguageProfile128 : ModelBase
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<LanguageProfileItem128> Languages { get; set; }
|
||||||
|
public bool UpgradeAllowed { get; set; }
|
||||||
|
public Language Cutoff { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LanguageProfileItem128
|
||||||
|
{
|
||||||
|
public int Language { get; set; }
|
||||||
|
public bool Allowed { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class LanguageProfileUpdater128
|
||||||
|
{
|
||||||
|
private readonly IDbConnection _connection;
|
||||||
|
private readonly IDbTransaction _transaction;
|
||||||
|
|
||||||
|
private List<LanguageProfile128> _profiles;
|
||||||
|
private HashSet<LanguageProfile128> _changedProfiles = new HashSet<LanguageProfile128>();
|
||||||
|
|
||||||
|
public LanguageProfileUpdater128(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
_connection = conn;
|
||||||
|
_transaction = tran;
|
||||||
|
|
||||||
|
_profiles = GetProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Commit()
|
||||||
|
{
|
||||||
|
foreach (var profile in _changedProfiles)
|
||||||
|
{
|
||||||
|
using (var updateProfileCmd = _connection.CreateCommand())
|
||||||
|
{
|
||||||
|
updateProfileCmd.Transaction = _transaction;
|
||||||
|
updateProfileCmd.CommandText = "UPDATE LanguageProfiles SET Languages = ? WHERE Id = ?";
|
||||||
|
updateProfileCmd.AddParameter(profile.Languages.ToJson());
|
||||||
|
updateProfileCmd.AddParameter(profile.Id);
|
||||||
|
|
||||||
|
updateProfileCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_changedProfiles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendMissing()
|
||||||
|
{
|
||||||
|
foreach (var profile in _profiles)
|
||||||
|
{
|
||||||
|
var hash = new HashSet<int>(profile.Languages.Select(v => v.Language));
|
||||||
|
|
||||||
|
var missing = Language.All.Where(l => !hash.Contains(l.Id))
|
||||||
|
.OrderByDescending(l => l.Name)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (missing.Any())
|
||||||
|
{
|
||||||
|
profile.Languages.InsertRange(0, missing.Select(l => new LanguageProfileItem128 { Language = l.Id, Allowed = false }));
|
||||||
|
|
||||||
|
_changedProfiles.Add(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LanguageProfile128> GetProfiles()
|
||||||
|
{
|
||||||
|
var profiles = new List<LanguageProfile128>();
|
||||||
|
|
||||||
|
using (var getProfilesCmd = _connection.CreateCommand())
|
||||||
|
{
|
||||||
|
getProfilesCmd.Transaction = _transaction;
|
||||||
|
getProfilesCmd.CommandText = @"SELECT Id, Name, Languages, UpgradeAllowed, Cutoff FROM LanguageProfiles";
|
||||||
|
|
||||||
|
using (var profileReader = getProfilesCmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (profileReader.Read())
|
||||||
|
{
|
||||||
|
profiles.Add(new LanguageProfile128
|
||||||
|
{
|
||||||
|
Id = profileReader.GetInt32(0),
|
||||||
|
Name = profileReader.GetString(1),
|
||||||
|
Languages = Json.Deserialize<List<LanguageProfileItem128>>(profileReader.GetString(2)),
|
||||||
|
UpgradeAllowed = profileReader.GetBoolean(3),
|
||||||
|
Cutoff = Language.FindById(profileReader.GetInt32(4))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return profiles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,6 +82,7 @@ namespace NzbDrone.Core.Languages
|
||||||
public static Language Lithuanian { get { return new Language(24, "Lithuanian"); } }
|
public static Language Lithuanian { get { return new Language(24, "Lithuanian"); } }
|
||||||
public static Language Czech { get { return new Language(25, "Czech"); } }
|
public static Language Czech { get { return new Language(25, "Czech"); } }
|
||||||
public static Language Arabic { get { return new Language(26, "Arabic"); } }
|
public static Language Arabic { get { return new Language(26, "Arabic"); } }
|
||||||
|
public static Language Hindi { get { return new Language(27, "Hindi"); } }
|
||||||
|
|
||||||
|
|
||||||
public static List<Language> All
|
public static List<Language> All
|
||||||
|
@ -116,18 +117,19 @@ namespace NzbDrone.Core.Languages
|
||||||
Hebrew,
|
Hebrew,
|
||||||
Lithuanian,
|
Lithuanian,
|
||||||
Czech,
|
Czech,
|
||||||
Arabic
|
Arabic,
|
||||||
|
Hindi
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly Dictionary<int, Language> Lookup = All.ToDictionary(v => v.Id);
|
||||||
|
|
||||||
public static Language FindById(int id)
|
public static Language FindById(int id)
|
||||||
{
|
{
|
||||||
if (id == 0) return Unknown;
|
if (id == 0) return Unknown;
|
||||||
|
|
||||||
Language language = All.FirstOrDefault(v => v.Id == id);
|
if (!Lookup.TryGetValue(id, out var language))
|
||||||
|
|
||||||
if (language == null)
|
|
||||||
{
|
{
|
||||||
throw new ArgumentException("ID does not match a known language", nameof(id));
|
throw new ArgumentException("ID does not match a known language", nameof(id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ namespace NzbDrone.Core.Parser
|
||||||
new IsoLanguage("he", "heb", Language.Hebrew),
|
new IsoLanguage("he", "heb", Language.Hebrew),
|
||||||
new IsoLanguage("lt", "lit", Language.Lithuanian),
|
new IsoLanguage("lt", "lit", Language.Lithuanian),
|
||||||
new IsoLanguage("cs", "ces", Language.Czech),
|
new IsoLanguage("cs", "ces", Language.Czech),
|
||||||
new IsoLanguage("ar", "ara", Language.Arabic)
|
new IsoLanguage("ar", "ara", Language.Arabic),
|
||||||
|
new IsoLanguage("hi", "hin", Language.Hindi)
|
||||||
};
|
};
|
||||||
|
|
||||||
public static IsoLanguage Find(string isoCode)
|
public static IsoLanguage Find(string isoCode)
|
||||||
|
|
|
@ -36,9 +36,6 @@ namespace NzbDrone.Core.Parser
|
||||||
|
|
||||||
var lowerTitle = title.ToLower();
|
var lowerTitle = title.ToLower();
|
||||||
|
|
||||||
if (lowerTitle.Contains("english"))
|
|
||||||
return Language.English;
|
|
||||||
|
|
||||||
if (lowerTitle.Contains("french"))
|
if (lowerTitle.Contains("french"))
|
||||||
return Language.French;
|
return Language.French;
|
||||||
|
|
||||||
|
@ -96,6 +93,9 @@ namespace NzbDrone.Core.Parser
|
||||||
if (lowerTitle.Contains("arabic"))
|
if (lowerTitle.Contains("arabic"))
|
||||||
return Language.Arabic;
|
return Language.Arabic;
|
||||||
|
|
||||||
|
if (lowerTitle.Contains("hindi"))
|
||||||
|
return Language.Hindi;
|
||||||
|
|
||||||
var regexLanguage = RegexLanguage(title);
|
var regexLanguage = RegexLanguage(title);
|
||||||
|
|
||||||
if (regexLanguage != Language.Unknown)
|
if (regexLanguage != Language.Unknown)
|
||||||
|
@ -103,6 +103,9 @@ namespace NzbDrone.Core.Parser
|
||||||
return regexLanguage;
|
return regexLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lowerTitle.Contains("english"))
|
||||||
|
return Language.English;
|
||||||
|
|
||||||
return defaultToEnglish ? Language.English : Language.Unknown;
|
return defaultToEnglish ? Language.English : Language.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,6 @@
|
||||||
<ProjectReference Include="..\NzbDrone.Common\Sonarr.Common.csproj" />
|
<ProjectReference Include="..\NzbDrone.Common\Sonarr.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Growl.Connector">
|
|
||||||
<HintPath>..\Libraries\Growl.Connector.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Growl.CoreLibrary">
|
|
||||||
<HintPath>..\Libraries\Growl.CoreLibrary.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data.SQLite">
|
<Reference Include="System.Data.SQLite">
|
||||||
<HintPath>..\Libraries\Sqlite\System.Data.SQLite.dll</HintPath>
|
<HintPath>..\Libraries\Sqlite\System.Data.SQLite.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
Loading…
Reference in New Issue