Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/qwqcode/SubRenamer

🎞 字幕文件批量改名工具 | Batch Rename Subtitle Files to Match Video Names with One Click
https://github.com/qwqcode/SubRenamer

anime avalonia bangumi bilibili dotnet renamer srt subtitle subtitle-conversion subtitle-correction subtitle-files subtitles tools video video-player youtube-video

Last synced: 13 days ago
JSON representation

🎞 字幕文件批量改名工具 | Batch Rename Subtitle Files to Match Video Names with One Click

Awesome Lists containing this project

README

        

# SubRenamer

🎞 One-click batch subtitle renaming tool

A Tool for Batch Rename Subtitle Files to Match Video Names with One Click.

**Why?** If the video and subtitle filenames match, any video player can automatically load the subtitles.

**Goal?** Rename external subtitle files to match the video filenames.

[![](https://img.shields.io/github/release/qwqcode/SubRenamer.svg?style=flat-square)](https://github.com/qwqcode/SubRenamer/releases/latest) [![](https://img.shields.io/github/downloads/qwqcode/SubRenamer/total.svg?style=flat-square)](https://github.com/qwqcode/SubRenamer/releases) [![](https://img.shields.io/github/issues/qwqcode/SubRenamer.svg?style=flat-square)](https://github.com/qwqcode/SubRenamer/issues)

## What sets SubRenamer apart from regular batch renaming software?

SubRenamer specializes in renaming subtitle files and is straightforward to use.

For most video and subtitle files, simply drag them into the program for automatic and precise recognition, allowing one-click renaming without the complex settings of typical renaming software.

## How to get SubRenamer?

Click the links below to download the latest version:

| [](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_windows_amd64.zip) | [](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_macos_arm64.zip) | [](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_linux_amd64.tar.gz) |
|-|-|-|
| [Windows (x86)](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_windows_amd64.zip) | [macOS (M1)](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_macos_arm64.zip) | [Linux (x86)](https://github.com/qwqcode/SubRenamer/releases/latest/download/SubRenamer_linux_amd64.tar.gz) |

You can find historical versions and changelogs on the [Release](https://github.com/qwqcode/SubRenamer/releases) page.

## Features

- **Automatic Matching**: One-click matching with automatic recognition algorithms.
- **Drag & Drop Import**: Quickly import files and folders via drag and drop.
- **Multi-language Matching**: Supports multi-language subtitle matching (one-to-many mapping).
- **Language Filtering**: Automatically detects and filters subtitles of specified languages before import.
- **Multiple Matching Rules**: Supports manual matching for complex filename formats.
- **Manual Matching Editor**: Customizable rules with simple wildcards.
- **Regex Editor**: Includes a regex matching test tool.
- **Match Fine-tuning**: Allows fine-tuning of matching results.
- **Rename Commands**: Quickly copy Linux rename commands to clipboard via right-click.
- **Subtitle Backup**: Automatically backs up subtitle files before renaming.
- **Append Suffix**: Supports adding custom suffixes before file extensions.
- **File Recognition**: Automatically distinguishes between video and subtitle files by extension, with customization support.
- **Shortcuts**: Supports keyboard shortcuts for efficiency.
- **Dark Mode**: Follows system settings for dark mode.
- **Always on Top**: Keeps the window on top for easy operation.
- **I18n**: Supports multiple languages, including Chinese and English.
- **Cross-platform**: Supports Windows, macOS, and Linux.
- **Small Size**: Around 15MB.

> [!IMPORTANT]\
> Rewrite Note: The first version of SubRenamer was released in 2019, developed with WinForm and only supported Windows. In 2024, SubRenamer was rewritten and released as v2.0, using AvaloniaUI + .NET 8, now supporting cross-platform functionality on Windows, macOS, and Linux (not using Electron.js).

| Match Editor | Custom Matching Rules |
|-|-|
| | |

| Manual Matching Rule Editor | Regex Rule Editor |
|-|-|
| | |

| Dark Mode | Subtitle Language Filtering |
|-|-|
| | |

| Right-click Menu | Shortcut Support | Settings Interface |
|-|-|-|
| | | |

**Drag & Drop Import**

[Drag & Drop Import Video Demo](https://github.com/qwqcode/SubRenamer/assets/22412567/9de8fa00-6010-4b3a-83a6-2c976dc97090)

## Renaming Instructions

If the video and subtitle files are in **different** folders, the renaming process will **copy** the subtitle files to the video folder without altering the original subtitle files, so no backup is needed.

Conversely, if the video and subtitle files are in the **same** folder, the renaming process will directly modify the subtitle filenames (you can enable backup in settings to save the original subtitle files in the SubBackup directory).

The renamed subtitle filenames will match the video filenames.

## Algorithm Principle

### Automatic Matching Mode

The automatic matching mode determines the episode (extract) by comparing the differences (diff) between filenames and automatically associates video and subtitle files (mapping) to achieve automatic matching.

To perform automatic matching, you need to import at least two video files and two subtitle files with consistent naming formats.

- Algorithm Code: [SubRenamer.Core](https://github.com/qwqcode/SubRenamer/tree/main/SubRenamer.Core) (entry function in [Matcher.cs](https://github.com/qwqcode/SubRenamer/blob/main/SubRenamer.Core/Matcher.cs))
- Unit Test Code: [SubRenamer.Tests](https://github.com/qwqcode/SubRenamer/tree/main/SubRenamer.Tests)
- Test Case Data: [TopLevelTests.json](https://github.com/qwqcode/SubRenamer/blob/main/SubRenamer.Tests/MatcherTests/TopLevelTests.json) (**contains example data for the automatic matching algorithm**)

### Manual Matching Mode

The automatic matching mode may fail with complex filename formats, in which case you can switch to manual matching mode. Manual mode allows you to define rules (supporting simple wildcards and regular expressions). The program provides a simple editor for quickly writing matching rules.

## FAQ

**macOS can't open, says it's damaged**

There are many solutions online. Here's one method: open the terminal and enter the following command:

```bash
sudo xattr -d com.apple.quarantine /Applications/SubRenamer.app
```

The reason is it isn't signed by an Apple developer, which requires a $99/year developer account.

**No scaling on Linux Wayland desktop environment?**

This is an upstream issue. AvaloniaUI may not scale correctly on Wayland, resulting in small text. You can set the environment variable to manually set the scaling factor at startup.

```bash
AVALONIA_SCREEN_SCALE_FACTORS="eDP-1=2;" ./SubRenamer
```

- https://github.com/AvaloniaUI/Avalonia/issues/9390
- https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI

## Multi-Language Translation (I18n)

SubRenamer supports multiple languages. Currently available languages include:

- English
- 简体中文 (Simplified Chinese)
- 繁體中文 (Traditional Chinese)
- 日本語 (Japanese)

Language files are located in the [SubRenamer/Assets/Lang](https://github.com/qwqcode/SubRenamer/blob/main/SubRenamer/Assets/Lang) directory. You can add or improve translations by editing the XAML files. Contributions are welcome, feel free to submit a PR to add more language translations.

## Found a BUG?

Report it on the [issues page](https://github.com/qwqcode/SubRenamer/issues).

## Stargazers over time

[![Stargazers over time](https://starchart.cc/qwqcode/SubRenamer.svg)](https://starchart.cc/qwqcode/SubRenamer)

## Compilation Instructions

It is recommended to use JetBrains Rider or Visual Studio 2022 to open the project.

### Prerequisites

**Windows**

- Visual Studio 2022, including .NET 8 & Desktop development with C++ workload.
- Alternatively, you can install JetBrains Rider to build the project. (Recommended).

**Fedora (36+)**

```bash
sudo dnf group install "C Development Tools and Libraries" "Development Tools"

sudo dnf install dotnet-sdk-8.0 libicu-devel cmake zlib-devel -y
```

**Ubuntu (20.04+)**

```bash
sudo apt-get install dotnet-sdk-8.0 libicu-dev cmake zlib1g-dev -y
```

**macOS (12+)**

```bash
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install xcode command line tools
xcode-select --install

# Install dependencies
brew install dotnet-sdk8 icu4c cmake zlib
```

****

### Unit Testing

```bash
dotnet test SubRenamer.Tests --verbosity normal
```

Unit test code is in the [SubRenamer.Tests](https://github.com/qwqcode/SubRenamer/tree/main/SubRenamer.Tests) directory. It is recommended to use Rider's built-in visual tool to run tests and view results.

**Test Data**

The [TopLevelTests.json](https://github.com/qwqcode/SubRenamer/blob/main/SubRenamer.Tests/MatcherTests/TopLevelTests.json) file contains test case data, including various subtitle and video filename lists for testing the matching algorithm. Feel free to submit a PR to add more test cases. After modifying the file, run the unit test command to view the results.

Each code submission will trigger unit tests via GitHub Actions to ensure code quality.

### Building a Single File

On Windows, to build a single exe file with statically linked dependencies (without additional dynamic link DLL dependencies), download [these DLL files](https://github.com/qwqcode/qwqcode/releases/tag/dotnet-lib) and place them in the `native` directory. Then add the environment variable `ENABLE_NATIVE_LIBS=true` before compiling.

- https://github.com/qwqcode/SubRenamer/blob/main/.github/workflows/dotnet-desktop.yml
- https://github.com/AvaloniaUI/Avalonia/issues/9503
- https://github.com/qwqcode/SubRenamer/blob/main/SubRenamer/SubRenamer.csproj

### Publish with NativeAOT

```bash
dotnet publish -r -c Release

# Build for Windows example
dotnet publish -r win-x64 -c Release
```

### Build the installer with NSIS

NSIS installer `~13MB size`

```bash
pwsh ./publish.ps1
```

> If you build the installer with NSIS, you can ignore UPX compression for better startup performance.

## Technical Implementation

- AOT compilation, single file publishing
- Multi-platform packaging and distribution
- Cross-platform adaptation handling
- IoC container, dependency injection, MVVM, LINQ
- JSON source generator
- Multithreading, coroutines
- Global exception handling
- Error log reporting
- JSON configuration management
- Version management, update checking
- Usage statistics
- GitHub API
- GitHub Actions CI/CD
- Unit testing
- Multi-language, internationalization
- HiDPI support

## License

This project is open-sourced under the GPL-2.0 license. See the [LICENSE](./LICENSE) file for details.