Skip to content

Commit

Permalink
feat: support automatic subtitle synchronization
Browse files Browse the repository at this point in the history
- Implement SubSyncService to manage FFsubsync binary operations
- Add methods for bootstrapping, executing, and shutting down the service
- Integrate download functionality for FFsubsync binary
- Update SettingsWindow to include SubSync settings and download options
- Enhance UI with status indicators for SubSync binary installation
  • Loading branch information
qwqcode committed Nov 14, 2024
1 parent 0cf1dbd commit 22e7ea8
Show file tree
Hide file tree
Showing 21 changed files with 796 additions and 45 deletions.
4 changes: 2 additions & 2 deletions SubRenamer/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="/Assets/Lang/zh-Hans.axaml" />
<ResourceInclude Source="avares://LoadingIndicators.Avalonia/LoadingIndicators.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
Expand Down
33 changes: 29 additions & 4 deletions SubRenamer/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
Expand Down Expand Up @@ -61,6 +62,7 @@ public override void OnFrameworkInitializationCompleted()
services.AddSingleton<IClipboardService>(x => new ClipboardService(desktop.MainWindow));
services.AddSingleton<IImportService>(x => new ImportService(desktop.MainWindow));
services.AddSingleton<IRenameService>(x => new RenameService(desktop.MainWindow));
services.AddSingleton<ISubSyncService>(x => new SubSyncService(desktop.MainWindow));
services.AddSingleton<IWindowService>(x => new WindowService(desktop.MainWindow, OnSetTopmost));

Services = services.BuildServiceProvider();
Expand Down Expand Up @@ -126,7 +128,7 @@ private void MenuSetting_OnClick(object? sender, EventArgs e)
Current?.Services?.GetService<IDialogService>()?.OpenSettings();
}

private static void _afterInitTasks(MainViewModel? mainWindowStore)
private static void _afterInitTasks(MainViewModel store)
{
IssueReporter.CheckCrashAndShowDialog();

Expand All @@ -139,10 +141,10 @@ private static void _afterInitTasks(MainViewModel? mainWindowStore)
try
{
var updateSrc = await Updater.GetUpdatesAsync();
if (updateSrc != null && mainWindowStore != null)
if (updateSrc != null)
{
mainWindowStore.CurrVersionText += " " + Application.Current.GetResource<string>("App.Strings.MenuUpdateAlert");
mainWindowStore.CurrVersionBtnLink = updateSrc;
store.CurrVersionText += " " + Application.Current.GetResource<string>("App.Strings.MenuUpdateAlert");
store.CurrVersionBtnLink = updateSrc;
}
}
catch (Exception e)
Expand All @@ -165,6 +167,29 @@ private static void _afterInitTasks(MainViewModel? mainWindowStore)
Console.WriteLine(e);
}
});

Task.Run(async () =>
{
var subSyncService = Current?.Services?.GetService<ISubSyncService>()!;
subSyncService.OnBootstrapped += () =>
{
store.SubSyncAvailable = true;
};
subSyncService.OnShutdown += () =>
{
store.SubSyncAvailable = false;
store.SubSyncEnabled = false;
};
try
{
await subSyncService.Bootstrap();
}
catch (Exception)
{
store.SubSyncAvailable = false;
store.SubSyncEnabled = false;
}
});
}
}
}
19 changes: 18 additions & 1 deletion SubRenamer/Assets/Lang/en-US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<system:String x:Key="App.Strings.OpRules">Rules</system:String>
<system:String x:Key="App.Strings.OpSettings">Settings</system:String>
<system:String x:Key="App.Strings.OpPreview">Preview</system:String>
<system:String x:Key="App.Strings.OpSubSync">Sync</system:String>
<system:String x:Key="App.Strings.OpRename">Rename</system:String>
<system:String x:Key="App.Strings.NativeMenuSettings">Settings...</system:String>
<system:String x:Key="App.Strings.NativeMenuQuit">Quit SubRenamer</system:String>
Expand All @@ -32,6 +33,8 @@
<system:String x:Key="App.Strings.ContextMenuRevealVideo">Reveal Video in Folder</system:String>
<system:String x:Key="App.Strings.ContextMenuRevealSubtitle">Reveal Subtitle in Folder</system:String>
<system:String x:Key="App.Strings.ContextMenuCopyRenameCommands">Copy Rename Commands to Clipboard</system:String>
<system:String x:Key="App.Strings.ContextMenuPerformSubSync">Perform Subtitle Timeline Synchronization</system:String>
<system:String x:Key="App.Strings.ContextMenuExitPreviewMode">Exit Preview Mode</system:String>
<system:String x:Key="App.Strings.DataGridMatch">Match</system:String>
<system:String x:Key="App.Strings.DataGridVideo">Video</system:String>
<system:String x:Key="App.Strings.DataGridSubtitle">Subtitle</system:String>
Expand Down Expand Up @@ -110,7 +113,13 @@ It can be modified to: "[Steins;Gate][$$]*.sc.ass"</system:String>
<system:String x:Key="App.Strings.SettingsVideoFormatExtension">Video Format Extension</system:String>
<system:String x:Key="App.Strings.SettingsVideoFormatWatermark">e.g., mkv</system:String>
<system:String x:Key="App.Strings.SettingsUpdateCheck">Check for Program Updates</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ Hi! This is an open-source program</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncProgram">Automatic Subtitles Sync: </system:String>
<system:String x:Key="App.Strings.SettingsSubSyncInstalled">Installed</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncNotInstalled">Not installed</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDesc">Support FFsubsync + FFmpeg automatic subtitles timeline synchronization, additional download is required, and the ffsubsync_bin file in the current program directory is read by default</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDownload">Download</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncViewReadme">View Readme</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ Hi! SubRenamer is an open-source program</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar1">You can find the source code on</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar2">GitHub</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar3">, please consider giving it a star 🌟, it would help us a lot!</system:String>
Expand All @@ -123,4 +132,12 @@ It can be modified to: "[Steins;Gate][$$]*.sc.ass"</system:String>
<system:String x:Key="App.Strings.OpenFileDialogTitle">Select and Import Files</system:String>
<system:String x:Key="App.Strings.OpenFolderDialogTitle">Import Folder</system:String>
<system:String x:Key="App.Strings.SaveFileDialogTitle">Save File</system:String>
<system:String x:Key="App.Strings.SubSyncTasksComplete">All tasks have been completed.</system:String>
<system:String x:Key="App.Strings.SubSyncTasksFail">Task execution failed.</system:String>
<system:String x:Key="App.Strings.SubSyncTasksDuration">Duration</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadTitle">FFsubsync automatic timeline synchronization</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDesc">Downloading FFsubsync...</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDone">FFsubsync download successful</system:String>
<system:String x:Key="App.Strings.ProgressDialogCancel">Cancel</system:String>
<system:String x:Key="App.Strings.ProgressDialogDone">Done</system:String>
</ResourceDictionary>
19 changes: 18 additions & 1 deletion SubRenamer/Assets/Lang/ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<system:String x:Key="App.Strings.OpRules">ルール</system:String>
<system:String x:Key="App.Strings.OpSettings">設定</system:String>
<system:String x:Key="App.Strings.OpPreview">プレビュー</system:String>
<system:String x:Key="App.Strings.OpSubSync">同期</system:String>
<system:String x:Key="App.Strings.OpRename">リネーム</system:String>
<system:String x:Key="App.Strings.NativeMenuSettings">設定...</system:String>
<system:String x:Key="App.Strings.NativeMenuQuit">SubRenamerを終了</system:String>
Expand All @@ -32,6 +33,8 @@
<system:String x:Key="App.Strings.ContextMenuRevealVideo">フォルダでビデオファイルを見つける</system:String>
<system:String x:Key="App.Strings.ContextMenuRevealSubtitle">フォルダで字幕ファイルを見つける</system:String>
<system:String x:Key="App.Strings.ContextMenuCopyRenameCommands">リネームコマンドをクリップボードにコピー</system:String>
<system:String x:Key="App.Strings.ContextMenuPerformSubSync">字幕タイムライン同期を実行する</system:String>
<system:String x:Key="App.Strings.ContextMenuExitPreviewMode">レビューモードを終了</system:String>
<system:String x:Key="App.Strings.DataGridMatch">マッチ</system:String>
<system:String x:Key="App.Strings.DataGridVideo">ビデオ</system:String>
<system:String x:Key="App.Strings.DataGridSubtitle">字幕</system:String>
Expand Down Expand Up @@ -110,7 +113,13 @@
<system:String x:Key="App.Strings.SettingsVideoFormatExtension">ビデオフォーマット拡張</system:String>
<system:String x:Key="App.Strings.SettingsVideoFormatWatermark">例: mkv</system:String>
<system:String x:Key="App.Strings.SettingsUpdateCheck">プログラムの更新チェック</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ こんにちは!これはオープンソースプログラムです</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncProgram">自動タイムライン同期: </system:String>
<system:String x:Key="App.Strings.SettingsSubSyncInstalled">インストール済み</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncNotInstalled">インストールされていません</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDesc">FFsubsync + FFmpeg 自動軸調整をサポートし、追加のダウンロードが必要で、デフォルトで現在のプログラム ディレクトリにある ffsubsync_bin ファイルを読み取ります</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDownload">ダウンロード</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncViewReadme">手順を表示</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ こんにちは! SubRenamer はオープン ソース プログラムです。</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar1">あなたは</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar2">GitHub</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar3">でソースコードを見つけることができます。Star 🌟を付けていただけると嬉しいです!</system:String>
Expand All @@ -123,4 +132,12 @@
<system:String x:Key="App.Strings.OpenFileDialogTitle">ファイルを選択してインポート</system:String>
<system:String x:Key="App.Strings.OpenFolderDialogTitle">フォルダをインポート</system:String>
<system:String x:Key="App.Strings.SaveFileDialogTitle">ファイルを保存</system:String>
<system:String x:Key="App.Strings.SubSyncTasksComplete">すべてのタスクが完了しました。</system:String>
<system:String x:Key="App.Strings.SubSyncTasksFail">タスクの実行に失敗しました。</system:String>
<system:String x:Key="App.Strings.SubSyncTasksDuration">処理時間</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadTitle">FFsubsync の自動タイムライン同期</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDesc">FFsubsync をダウンロードしています...</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDone">FFsubsync のダウンロードに成功しました</system:String>
<system:String x:Key="App.Strings.ProgressDialogCancel">キャンセル</system:String>
<system:String x:Key="App.Strings.ProgressDialogDone">完了</system:String>
</ResourceDictionary>
19 changes: 18 additions & 1 deletion SubRenamer/Assets/Lang/zh-Hans.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<system:String x:Key="App.Strings.OpRules">规则</system:String>
<system:String x:Key="App.Strings.OpSettings">设置</system:String>
<system:String x:Key="App.Strings.OpPreview">预览</system:String>
<system:String x:Key="App.Strings.OpSubSync">调轴</system:String>
<system:String x:Key="App.Strings.OpRename">一键改名</system:String>
<system:String x:Key="App.Strings.NativeMenuSettings">设置...</system:String>
<system:String x:Key="App.Strings.NativeMenuQuit">退出 SubRenamer</system:String>
Expand All @@ -32,6 +33,8 @@
<system:String x:Key="App.Strings.ContextMenuRevealVideo">在文件夹中找到视频文件</system:String>
<system:String x:Key="App.Strings.ContextMenuRevealSubtitle">在文件夹中找到字幕文件</system:String>
<system:String x:Key="App.Strings.ContextMenuCopyRenameCommands">复制改名命令至剪切板</system:String>
<system:String x:Key="App.Strings.ContextMenuPerformSubSync">执行字幕自动调轴程序</system:String>
<system:String x:Key="App.Strings.ContextMenuExitPreviewMode">退出预览模式</system:String>
<system:String x:Key="App.Strings.DataGridMatch">匹配</system:String>
<system:String x:Key="App.Strings.DataGridVideo">视频</system:String>
<system:String x:Key="App.Strings.DataGridSubtitle">字幕</system:String>
Expand Down Expand Up @@ -110,7 +113,13 @@
<system:String x:Key="App.Strings.SettingsVideoFormatExtension">视频格式扩充</system:String>
<system:String x:Key="App.Strings.SettingsVideoFormatWatermark">例如:mkv</system:String>
<system:String x:Key="App.Strings.SettingsUpdateCheck">程序升级检查</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ 嗨!这是开源程序</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncProgram">自动调轴程序:</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncInstalled">已安装</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncNotInstalled">未安装</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDesc">支持 FFsubsync + FFmpeg 自动调轴,需额外下载,默认读取当前程序目录的 ffsubsync_bin 文件</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncDownload">下载</system:String>
<system:String x:Key="App.Strings.SettingsSubSyncViewReadme">查看说明</system:String>
<system:String x:Key="App.Strings.SettingsOpenSourceProgram">|´・ω・)ノ 嗨!SubRenamer 是开源程序</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar1">你可以在</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar2">GitHub</system:String>
<system:String x:Key="App.Strings.SettingsConsiderStar3">找到源代码,请考虑点个 Star 🌟这会对我们很有帮助!</system:String>
Expand All @@ -123,4 +132,12 @@
<system:String x:Key="App.Strings.OpenFileDialogTitle">选择并导入文件</system:String>
<system:String x:Key="App.Strings.OpenFolderDialogTitle">导入文件夹</system:String>
<system:String x:Key="App.Strings.SaveFileDialogTitle">保存文件</system:String>
<system:String x:Key="App.Strings.SubSyncTasksComplete">所有任务已完成。</system:String>
<system:String x:Key="App.Strings.SubSyncTasksFail">任务执行失败。</system:String>
<system:String x:Key="App.Strings.SubSyncTasksDuration">执行耗时:</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadTitle">FFsubsync 自动调轴程序</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDesc">正在下载 FFsubsync...</system:String>
<system:String x:Key="App.Strings.SubSyncBinDownloadDone">FFsubsync 下载成功</system:String>
<system:String x:Key="App.Strings.ProgressDialogCancel">取消</system:String>
<system:String x:Key="App.Strings.ProgressDialogDone">完成</system:String>
</ResourceDictionary>
Loading

0 comments on commit 22e7ea8

Please sign in to comment.