Skip to content

Commit

Permalink
Fix default settings for default renamer config
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Nov 17, 2024
1 parent 79f8073 commit 5559ed4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 49 deletions.
64 changes: 17 additions & 47 deletions Shoko.Server/Databases/BaseDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using NHibernate;
using NLog;
using Shoko.Commons.Extensions;
using Shoko.Commons.Properties;
using Shoko.Models;
using Shoko.Models.Server;
using Shoko.Plugin.Abstractions;
using Shoko.Server.Models;
using Shoko.Server.Renamer;
using Shoko.Server.Repositories;
Expand Down Expand Up @@ -325,56 +328,23 @@ private void CreateInitialRenameScript()
return;
}

var initialScript = new RenamerConfig();

initialScript.Name = Resources.Rename_Default;
initialScript.Type = typeof(WebAOMRenamer);
initialScript.Settings = new WebAOMSettings
var renamerService = Utils.ServiceContainer.GetRequiredService<RenameFileService>();
renamerService.RenamersByKey.TryGetValue("WebAOM", out var renamer);

if (renamer == null)
return;

var defaultSettings = renamer.GetType().GetInterfaces().FirstOrDefault(a => a.IsGenericType && a.GetGenericTypeDefinition() == typeof(IRenamer<>))
?.GetProperties(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(a => a.Name == "DefaultSettings")?.GetMethod?.Invoke(renamer, null);

var config = new RenamerConfig
{
Script =
"// Sample Output: [Coalgirls]_Highschool_of_the_Dead_-_01_(1920x1080_Blu-ray_H264)_[90CC6DC1].mkv" +
Environment.NewLine +
"// Sub group name" + Environment.NewLine +
"DO ADD '[%grp] '" + Environment.NewLine +
"// Anime Name, use english name if it exists, otherwise use the Romaji name" + Environment.NewLine +
"IF I(eng) DO ADD '%eng '" + Environment.NewLine +
"IF I(ann);I(!eng) DO ADD '%ann '" + Environment.NewLine +
"// Episode Number, don't use episode number for movies" + Environment.NewLine +
"IF T(!Movie) DO ADD '- %enr'" + Environment.NewLine +
"// If the file version is v2 or higher add it here" + Environment.NewLine +
"IF F(!1) DO ADD 'v%ver'" + Environment.NewLine +
"// Video Resolution" + Environment.NewLine +
"DO ADD ' (%res'" + Environment.NewLine +
"// Video Source (only if blu-ray or DVD)" + Environment.NewLine +
"IF R(DVD),R(Blu-ray) DO ADD ' %src'" + Environment.NewLine +
"// Video Codec" + Environment.NewLine +
"DO ADD ' %vid'" + Environment.NewLine +
"// Video Bit Depth (only if 10bit)" + Environment.NewLine +
"IF Z(10) DO ADD ' %bitbit'" + Environment.NewLine +
"DO ADD ') '" + Environment.NewLine +
"DO ADD '[%CRC]'" + Environment.NewLine +
string.Empty + Environment.NewLine +
"// Replacement rules (cleanup)" + Environment.NewLine +
"DO REPLACE ' ' '_' // replace spaces with underscores" + Environment.NewLine +
"DO REPLACE 'H264/AVC' 'H264'" + Environment.NewLine +
"DO REPLACE '0x0' ''" + Environment.NewLine +
"DO REPLACE '__' '_'" + Environment.NewLine +
"DO REPLACE '__' '_'" + Environment.NewLine +
string.Empty + Environment.NewLine +
"// Replace all illegal file name characters" + Environment.NewLine +
"DO REPLACE '<' '('" + Environment.NewLine +
"DO REPLACE '>' ')'" + Environment.NewLine +
"DO REPLACE ':' '-'" + Environment.NewLine +
"DO REPLACE '" + (char)34 + "' '`'" + Environment.NewLine +
"DO REPLACE '/' '_'" + Environment.NewLine +
"DO REPLACE '/' '_'" + Environment.NewLine +
"DO REPLACE '\\' '_'" + Environment.NewLine +
"DO REPLACE '|' '_'" + Environment.NewLine +
"DO REPLACE '?' '_'" + Environment.NewLine +
"DO REPLACE '*' '_'" + Environment.NewLine,
Name = "Default",
Type = typeof(WebAOMRenamer),
Settings = defaultSettings,
};

RepoFactory.RenamerConfig.Save(initialScript);
RepoFactory.RenamerConfig.Save(config);
}

public void CreateInitialCustomTags()
Expand Down
16 changes: 14 additions & 2 deletions Shoko.Server/Databases/DatabaseFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
Expand All @@ -11,13 +12,15 @@
using Shoko.Commons.Properties;
using Shoko.Models.Enums;
using Shoko.Models.Server;
using Shoko.Plugin.Abstractions;
using Shoko.Server.Extensions;
using Shoko.Server.Filters.Legacy;
using Shoko.Server.Models;
using Shoko.Server.Models.CrossReference;
using Shoko.Server.Providers.AniDB;
using Shoko.Server.Providers.AniDB.HTTP;
using Shoko.Server.Providers.TMDB;
using Shoko.Server.Renamer;
using Shoko.Server.Repositories;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.Actions;
Expand Down Expand Up @@ -802,12 +805,21 @@ public static void CreateDefaultRenamerConfig()
var existingRenamer = RepoFactory.RenamerConfig.GetByName("Default");
if (existingRenamer != null)
return;

var renamerService = Utils.ServiceContainer.GetRequiredService<RenameFileService>();
renamerService.RenamersByKey.TryGetValue("WebAOM", out var renamer);

if (renamer == null)
return;

var defaultSettings = renamer.GetType().GetInterfaces().FirstOrDefault(a => a.IsGenericType && a.GetGenericTypeDefinition() == typeof(IRenamer<>))
?.GetProperties(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(a => a.Name == "DefaultSettings")?.GetMethod?.Invoke(renamer, null);

var config = new RenamerConfig
{
Name = "Default",
Type = typeof(Renamer.WebAOMRenamer),
Settings = new Renamer.WebAOMSettings(),
Type = typeof(WebAOMRenamer),
Settings = defaultSettings,
};

RepoFactory.RenamerConfig.Save(config);
Expand Down

0 comments on commit 5559ed4

Please sign in to comment.