├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.spec ├── image ├── icon.icns ├── icon.ico ├── icon.png ├── logo.png └── screenshot.png ├── main.py ├── requirements.txt ├── src ├── __init__.py ├── core.py ├── font │ └── Study-Bold.otf ├── function.py ├── gui │ ├── __init__.py │ ├── about.py │ ├── mainwindow.py │ └── setting.py ├── module │ ├── __init__.py │ ├── config.py │ ├── counter.py │ ├── detectsub.py │ ├── resource.py │ ├── theme.py │ └── version.py └── style │ ├── style_dark.qss │ ├── style_light.qss │ ├── table_dark.qss │ └── table_light.qss ├── version.py └── version.txt /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | tags: 7 | - '*' 8 | 9 | jobs: 10 | build: 11 | name: Build App 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: [ windows-latest, ubuntu-latest, macos-13, macos-14 ] 16 | 17 | steps: 18 | - name: Check out 19 | uses: actions/checkout@v4 20 | 21 | - name: Set up Python 22 | uses: actions/setup-python@v5 23 | with: 24 | python-version: "3.10" 25 | 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install -r requirements.txt 30 | pip install pyinstaller 31 | 32 | - name: Build 33 | run: pyinstaller build.spec 34 | 35 | - name: Zip (Windows) 36 | if: matrix.os == 'windows-latest' 37 | run: | 38 | cd dist 39 | 7z a -r SubtitleRenamer_windows.zip * 40 | 41 | - name: Zip (macOS-x64) 42 | if: matrix.os == 'macos-13' 43 | run: | 44 | cd dist 45 | zip -9 -r SubtitleRenamer_macos_x64.zip ./SubtitleRenamer.app 46 | 47 | - name: Zip (macOS-arm64) 48 | if: matrix.os == 'macos-14' 49 | run: | 50 | cd dist 51 | zip -9 -r SubtitleRenamer_macos_arm64.zip ./SubtitleRenamer.app 52 | 53 | - name: Zip (Linux) 54 | if: matrix.os == 'ubuntu-latest' 55 | run: | 56 | cd dist 57 | zip -9 -r SubtitleRenamer_linux.zip ./* 58 | 59 | - name: Upload 60 | uses: actions/upload-artifact@v4 61 | with: 62 | name: ${{ matrix.os }}-build 63 | path: dist/*.zip 64 | 65 | release: 66 | needs: build 67 | runs-on: ubuntu-latest 68 | steps: 69 | - name: Download 70 | uses: actions/download-artifact@v4 71 | with: 72 | merge-multiple: true 73 | path: asset 74 | 75 | - name: dist 76 | run: | 77 | mkdir -p dist 78 | cp -r asset/* dist/ 79 | cd dist && ls 80 | 81 | - name: Release 82 | uses: softprops/action-gh-release@v1 83 | env: 84 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 85 | with: 86 | tag_name: tag 87 | draft: true 88 | files: dist/* 89 | name: 🎉 90 | body: | 91 | ## 新增 92 | - 新增内容 93 | 94 | ## 优化 95 | - 优化内容 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | 3 | # PyCharm 4 | .idea 5 | 6 | # Byte-compiled / optimized / DLL files 7 | .DS_Store 8 | 9 | __pycache__/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | downloads/ 22 | eggs/ 23 | .eggs/ 24 | lib/ 25 | lib64/ 26 | parts/ 27 | sdist/ 28 | var/ 29 | wheels/ 30 | share/python-wheels/ 31 | *.egg-info/ 32 | .installed.cfg 33 | *.egg 34 | MANIFEST 35 | 36 | # PyInstaller 37 | # Usually these files are written by a python script from a template 38 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 39 | *.manifest 40 | 41 | # Installer logs 42 | pip-log.txt 43 | pip-delete-this-directory.txt 44 | 45 | # Unit test / coverage reports 46 | htmlcov/ 47 | .tox/ 48 | .nox/ 49 | .coverage 50 | .coverage.* 51 | .cache 52 | nosetests.xml 53 | coverage.xml 54 | *.cover 55 | *.py,cover 56 | .hypothesis/ 57 | .pytest_cache/ 58 | cover/ 59 | 60 | # Translations 61 | *.mo 62 | *.pot 63 | 64 | # Django stuff: 65 | *.log 66 | local_settings.py 67 | db.sqlite3 68 | db.sqlite3-journal 69 | 70 | # Flask stuff: 71 | instance/ 72 | .webassets-cache 73 | 74 | # Scrapy stuff: 75 | .scrapy 76 | 77 | # Sphinx documentation 78 | docs/_build/ 79 | 80 | # PyBuilder 81 | .pybuilder/ 82 | target/ 83 | 84 | # Jupyter Notebook 85 | .ipynb_checkpoints 86 | 87 | # IPython 88 | profile_default/ 89 | ipython_config.py 90 | 91 | # pyenv 92 | # For a library or package, you might want to ignore these files since the code is 93 | # intended to run in multiple environments; otherwise, check them in: 94 | # .python-version 95 | 96 | # pipenv 97 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 98 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 99 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 100 | # install all needed dependencies. 101 | #Pipfile.lock 102 | 103 | # poetry 104 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 105 | # This is especially recommended for binary packages to ensure reproducibility, and is more 106 | # commonly ignored for libraries. 107 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 108 | #poetry.lock 109 | 110 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 111 | __pypackages__/ 112 | 113 | # Celery stuff 114 | celerybeat-schedule 115 | celerybeat.pid 116 | 117 | # SageMath parsed files 118 | *.sage.py 119 | 120 | # Environments 121 | .env 122 | .venv 123 | env/ 124 | venv/ 125 | ENV/ 126 | env.bak/ 127 | venv.bak/ 128 | 129 | # Spyder project settings 130 | .spyderproject 131 | .spyproject 132 | 133 | # Rope project settings 134 | .ropeproject 135 | 136 | # mkdocs documentation 137 | /site 138 | 139 | # mypy 140 | .mypy_cache/ 141 | .dmypy.json 142 | dmypy.json 143 | 144 | # Pyre type checker 145 | .pyre/ 146 | 147 | # pytype static type analyzer 148 | .pytype/ 149 | 150 | # Cython debug symbols 151 | cython_debug/ 152 | 153 | # PyCharm 154 | # JetBrains specific template is maintainted in a separate JetBrains.gitignore that can 155 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 156 | # and can be added to the global gitignore or merged into this file. For a more nuclear 157 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 158 | #.idea/ 159 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | SubtitleRenamer 3 |
4 |

5 | Platform 6 | Stars 7 | Downloads 8 | License 9 |
10 |

11 | 12 | 13 | 14 | ## 介绍 15 | 16 | 世界上又多了一个基于 Python 的视频字幕批量重命名工具,**用于重命名动画与电影字幕**。 17 | 18 |

19 | SubtitleRenamer 20 |

21 | 22 | ## 特色 23 | 24 | - 多平台支持,开箱即用 25 | - 优雅的 GUI 界面(使用 [PyQt-Fluent-Widgets](https://github.com/zhiyiYo/PyQt-Fluent-Widgets) 主题组件) 26 | - 自动识别简繁字幕文件 27 | - 自定义简繁后缀 ( `.sc` or `.tc` ) 28 | - (可选)删除未命名的字幕 29 | - (可选)复制或剪切字幕至视频目录 30 | - (可选)转换字幕编码至 UTF-8 或 UTF-8-SIG 31 | 32 | ## 格式支持 33 | 34 | #### 字幕 35 | - ass 36 | - ssa 37 | - srt 38 | 39 | #### 视频 40 | - mkv 41 | - mp4 42 | - avi 43 | - flv 44 | - mov 45 | - 等等(支持手动添加非常用的视频格式) 46 | 47 | ## 使用 48 | 49 | 1. 拖入待更名的视频与字幕文件,需保持字幕与视频数量相等 50 | 2. 使用左下角的`简体`或`繁体`来选择字幕语言 51 | 3. 在设置中配置重命名时的可选项 52 | 4. 点击`重命名` 53 | 5. 完成! 54 | 55 | **注意:** 请在`重命名`开始前确保结果准确无误,`重命名`开始后,**操作不可撤销**。 56 | 57 | ## 反馈 58 | 59 | 如需要更多功能支持,请在 Issues 中提出,酌情添加。 60 | 61 | 如遇到程序错误,请在 Issues 中详细描述,并告知所用操作系统(Windows 11 or macOS 13.4)。 62 | 63 | ## 免责 64 | 65 | 本项目代码仅供学习交流,不得用于商业用途,若侵权请联系。 66 | -------------------------------------------------------------------------------- /build.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | 4 | block_cipher = None 5 | 6 | 7 | a = Analysis( 8 | ['main.py'], 9 | pathex=[], 10 | binaries=[], 11 | datas=[('src/style', 'src/style'), ('src/font', 'src/font'), ('image/icon.png', 'image'), ('image/logo.png', 'image')], 12 | hiddenimports=[], 13 | hookspath=[], 14 | hooksconfig={}, 15 | runtime_hooks=[], 16 | excludes=[], 17 | win_no_prefer_redirects=False, 18 | win_private_assemblies=False, 19 | cipher=block_cipher, 20 | noarchive=False, 21 | ) 22 | pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) 23 | 24 | exe = EXE( 25 | pyz, 26 | a.scripts, 27 | a.binaries, 28 | a.zipfiles, 29 | a.datas, 30 | [], 31 | name='SubtitleRenamer', 32 | debug=False, 33 | bootloader_ignore_signals=False, 34 | strip=False, 35 | upx=True, 36 | upx_exclude=[], 37 | runtime_tmpdir=None, 38 | console=False, 39 | disable_windowed_traceback=False, 40 | argv_emulation=False, 41 | target_arch=None, 42 | codesign_identity=None, 43 | entitlements_file=None, 44 | version='version.txt', 45 | icon=['image\\icon.ico'], 46 | ) 47 | app = BUNDLE( 48 | exe, 49 | name='SubtitleRenamer.app', 50 | icon='image/icon.icns', 51 | bundle_identifier=None, 52 | version='1.8.2', 53 | ) 54 | -------------------------------------------------------------------------------- /image/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/image/icon.icns -------------------------------------------------------------------------------- /image/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/image/icon.ico -------------------------------------------------------------------------------- /image/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/image/icon.png -------------------------------------------------------------------------------- /image/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/image/logo.png -------------------------------------------------------------------------------- /image/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/image/screenshot.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import platform 3 | import multiprocessing 4 | from PySide6.QtWidgets import QApplication 5 | 6 | from src.core import MyMainWindow 7 | 8 | 9 | if __name__ == "__main__": 10 | multiprocessing.freeze_support() 11 | 12 | # macOS 中使用 fork 速度快一些 13 | if platform.system() == "Darwin": 14 | multiprocessing.set_start_method("fork") 15 | 16 | app = QApplication(sys.argv) 17 | window = MyMainWindow() 18 | window.show() 19 | app.exec() 20 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PySide6~=6.4.2 2 | PySide6-Fluent-Widgets~=1.5.5 3 | chardet~=5.1.0 4 | ass~=0.5.3 5 | hanzidentifier~=1.1.0 6 | Send2Trash~=1.8.2 7 | joblib~=1.2.0 8 | requests 9 | natsort~=8.4.0 10 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/src/__init__.py -------------------------------------------------------------------------------- /src/core.py: -------------------------------------------------------------------------------- 1 | import time 2 | import send2trash 3 | import subprocess 4 | import threading 5 | import multiprocessing 6 | from natsort import natsorted 7 | from PySide6.QtWidgets import QMainWindow, QTableWidgetItem, QDialog 8 | from PySide6.QtCore import Qt, QPoint, QCoreApplication, QUrl 9 | from PySide6.QtGui import QDesktopServices 10 | from qfluentwidgets import (Theme, setTheme, MessageBox, InfoBar, InfoBarPosition, RoundMenu, Action, FluentIcon, 11 | setThemeColor, qconfig) 12 | 13 | from src.gui.mainwindow import MainWindow 14 | from src.gui.about import AboutWindow 15 | from src.gui.setting import SettingWindow 16 | from src.function import * 17 | from src.module.config import * 18 | from src.module.counter import * 19 | from src.module.theme import StyleSheet 20 | from src.module.version import newVersion 21 | 22 | 23 | class MyMainWindow(QMainWindow, MainWindow): 24 | def __init__(self): 25 | super().__init__() 26 | self.setupUI(self) 27 | self.initUI() 28 | self.initList() 29 | self.pool = multiprocessing.Pool() # 创建常驻进程池 30 | self.checkVersion() 31 | self.config = readConfig() 32 | self.loadConfig() 33 | self.setTheme() 34 | 35 | # 软件关闭时销毁进程池 36 | def __del__(self): 37 | self.pool.close() 38 | self.pool.join() 39 | 40 | def initUI(self): 41 | StyleSheet.WINDOW.apply(self) # 应用主题样式表 42 | 43 | addOpenTimes(readConfig(), configPath()) 44 | 45 | self.table.setContextMenuPolicy(Qt.CustomContextMenu) 46 | self.table.customContextMenuRequested.connect(self.showMenu) 47 | 48 | self.allowSc.stateChanged.connect(self.saveCheckBox) 49 | self.allowTc.stateChanged.connect(self.saveCheckBox) 50 | 51 | self.newVersionButton.clicked.connect(self.openRelease) 52 | self.aboutButton.clicked.connect(self.openAbout) 53 | self.settingButton.clicked.connect(self.openSetting) 54 | self.removeButton.clicked.connect(self.justRemoveSub) 55 | self.clearButton.clicked.connect(self.initList) 56 | self.renameButton.clicked.connect(self.startRename) 57 | 58 | def initList(self): 59 | self.file_list = [] 60 | self.video_list = [] 61 | self.sc_list = [] 62 | self.tc_list = [] 63 | self.table.clearContents() 64 | self.table.setRowCount(0) 65 | 66 | def checkVersion(self): 67 | thread = threading.Thread(target=self.checkVersionThread) 68 | thread.start() 69 | thread.join() 70 | 71 | def checkVersionThread(self): 72 | if newVersion(): 73 | self.newVersionButton.setVisible(True) 74 | 75 | def setTheme(self): 76 | # 从配置中读取主题样式 77 | theme = self.config.get("Application", "theme") 78 | if theme == "0": 79 | setTheme(Theme.AUTO) 80 | if qconfig.theme == Theme.LIGHT: 81 | setThemeColor("#1B96DE") 82 | elif qconfig.theme == Theme.DARK: 83 | setThemeColor("#4EC8FA") 84 | elif theme == "1": 85 | setTheme(Theme.LIGHT) 86 | setThemeColor("#1B96DE") 87 | elif theme == "2": 88 | setTheme(Theme.DARK) 89 | setThemeColor("#4EC8FA") 90 | 91 | def saveCheckBox(self): 92 | self.config.set("Application", "sc", str(self.allowSc.isChecked()).lower()) 93 | self.config.set("Application", "tc", str(self.allowTc.isChecked()).lower()) 94 | 95 | with open(configPath()[1], "w", encoding="utf-8") as content: 96 | self.config.write(content) 97 | 98 | def openRelease(self): 99 | url = QUrl("https://github.com/nuthx/subtitle-renamer/releases/latest") 100 | QDesktopServices.openUrl(url) 101 | 102 | def openAbout(self): 103 | about = MyAboutWindow() 104 | about.exec() 105 | 106 | def openSetting(self): 107 | setting = MySettingWindow() 108 | setting.exec() 109 | 110 | def dragEnterEvent(self, event): 111 | event.acceptProposedAction() 112 | 113 | def dropEvent(self, event): 114 | self.spinner.setVisible(True) 115 | 116 | # 获取并格式化本地路径 117 | self.raw_file_list = event.mimeData().urls() 118 | self.file_list = formatRawFileList(self.raw_file_list, self.file_list) 119 | 120 | # 放入子线程 121 | self.thread = threading.Thread(target=self.dropThread) 122 | self.thread.start() 123 | 124 | # 等待线程完成,不阻塞 UI 界面 125 | while self.thread.is_alive(): 126 | QCoreApplication.processEvents() 127 | 128 | self.dropFinish() 129 | 130 | def dropThread(self): 131 | start_time = time.time() 132 | 133 | # 拉取用户增加的视频格式 134 | self.config = readConfig() 135 | more_extension = self.config.get("Video", "more_extension") 136 | 137 | # 排除已分析过的内容 138 | self.split_list = [] 139 | for item in self.file_list: 140 | if item not in self.video_list + self.sc_list + self.tc_list: 141 | self.split_list.append([item, more_extension]) 142 | 143 | # 多进程启动 144 | results = self.pool.map(splitList, self.split_list) 145 | 146 | # 合并视频和字幕列表 147 | self.error_list = [] 148 | self.other_list = [] 149 | for result in results: 150 | if result[1] == "video": 151 | self.video_list.append(result[0]) 152 | elif result[1] == "sc": 153 | self.sc_list.append(result[0]) 154 | elif result[1] == "tc": 155 | self.tc_list.append(result[0]) 156 | elif result[1] == "error": 157 | self.error_list.append(result[0]) 158 | self.file_list.remove(result[0]) 159 | elif result[1] == "other": 160 | self.other_list.append(result[0]) 161 | self.file_list.remove(result[0]) 162 | 163 | self.used_time = (time.time() - start_time) * 1000 # 计时结束 164 | 165 | def dropFinish(self): 166 | self.video_list = natsorted(self.video_list) 167 | self.sc_list = natsorted(self.sc_list) 168 | self.tc_list = natsorted(self.tc_list) 169 | 170 | self.showInTable() 171 | self.spinner.setVisible(False) 172 | 173 | if len(self.split_list) == 0: 174 | self.showInfo("warning", "", "没有新增文件") 175 | elif self.used_time > 1000: 176 | used_time_s = "{:.2f}".format(self.used_time / 1000) # 取 2 位小数 177 | self.showInfo("success", f"已添加{len(self.split_list)}个文件", f"耗时{used_time_s}s") 178 | else: 179 | used_time_ms = "{:.0f}".format(self.used_time) # 舍弃小数 180 | self.showInfo("success", f"已添加{len(self.split_list)}个文件", f"耗时{used_time_ms}ms") 181 | 182 | if len(self.error_list) != 0: 183 | self.showInfo("error", "", f"有{len(self.error_list)}个字幕无法识别") 184 | 185 | if len(self.other_list) != 0: 186 | self.showInfo("warning", "", f"已过滤{len(self.other_list)}个文件") 187 | 188 | def showInTable(self): 189 | # 计算列表行数 190 | max_len = max(len(self.video_list), len(self.sc_list), len(self.tc_list)) 191 | self.table.setRowCount(max_len) 192 | 193 | video_id = 0 194 | for video_name in self.video_list: 195 | video_name_lonely = os.path.basename(video_name) 196 | self.table.setItem(video_id, 0, QTableWidgetItem(video_name_lonely)) 197 | video_id += 1 198 | 199 | sc_id = 0 200 | for sc_name in self.sc_list: 201 | sc_name_lonely = os.path.basename(sc_name) 202 | self.table.setItem(sc_id, 1, QTableWidgetItem(sc_name_lonely)) 203 | sc_id += 1 204 | 205 | tc_id = 0 206 | for tc_name in self.tc_list: 207 | tc_name_lonely = os.path.basename(tc_name) 208 | self.table.setItem(tc_id, 2, QTableWidgetItem(tc_name_lonely)) 209 | tc_id += 1 210 | 211 | self.table.resizeColumnsToContents() # 自动匹配列宽 212 | 213 | def showMenu(self, pos): 214 | menu = RoundMenu(parent=self) 215 | delete_this_video = Action(FluentIcon.CLOSE, "移除此视频") 216 | delete_this_subtitle = Action(FluentIcon.CLOSE, "移除此字幕") 217 | delete_this_line = Action(FluentIcon.DELETE, "移除整行内容") 218 | set_to_sc = Action(FluentIcon.FONT, "更正为简体字幕") 219 | set_to_tc = Action(FluentIcon.FONT, "更正为繁体字幕") 220 | 221 | # 必须选中单元格才会显示 222 | if self.table.itemAt(pos) is not None: 223 | # 微调菜单位置 224 | menu.exec(self.table.mapToGlobal(pos) + QPoint(0, 30), ani=True) 225 | 226 | # 计算单元格坐标 227 | clicked_item = self.table.itemAt(pos) 228 | row = self.table.row(clicked_item) 229 | column = self.table.column(clicked_item) 230 | 231 | # 配置不同的右键菜单 232 | if column == 0: 233 | menu.addAction(delete_this_video) 234 | menu.addAction(delete_this_line) 235 | elif column == 1: 236 | menu.addAction(delete_this_subtitle) 237 | menu.addAction(delete_this_line) 238 | menu.addSeparator() 239 | menu.addAction(set_to_tc) 240 | elif column == 2: 241 | menu.addAction(delete_this_subtitle) 242 | menu.addAction(delete_this_line) 243 | menu.addSeparator() 244 | menu.addAction(set_to_sc) 245 | 246 | # 绑定函数 247 | delete_this_video.triggered.connect(lambda: self.deleteThisFile(row, column)) 248 | delete_this_subtitle.triggered.connect(lambda: self.deleteThisFile(row, column)) 249 | delete_this_line.triggered.connect(lambda: self.deleteThisLine(row)) 250 | set_to_sc.triggered.connect(lambda: self.setToSc(row)) 251 | set_to_tc.triggered.connect(lambda: self.setToTc(row)) 252 | 253 | def deleteThisFile(self, row, column): 254 | if column == 0: 255 | del self.video_list[row] 256 | elif column == 1: 257 | del self.sc_list[row] 258 | elif column == 2: 259 | del self.tc_list[row] 260 | self.table.clearContents() 261 | self.table.setRowCount(0) 262 | self.showInTable() 263 | 264 | def deleteThisLine(self, row): 265 | if row < len(self.video_list): 266 | del self.video_list[row] 267 | if row < len(self.sc_list): 268 | del self.sc_list[row] 269 | if row < len(self.tc_list): 270 | del self.tc_list[row] 271 | self.table.clearContents() 272 | self.table.setRowCount(0) 273 | self.showInTable() 274 | 275 | def setToSc(self, row): 276 | pop = self.tc_list.pop(row) 277 | self.sc_list.append(pop) 278 | 279 | self.sc_list = natsorted(self.sc_list) 280 | self.tc_list = natsorted(self.tc_list) 281 | 282 | self.table.clearContents() 283 | self.table.setRowCount(0) 284 | self.showInTable() 285 | 286 | def setToTc(self, row): 287 | pop = self.sc_list.pop(row) 288 | self.tc_list.append(pop) 289 | 290 | self.sc_list = natsorted(self.sc_list) 291 | self.tc_list = natsorted(self.tc_list) 292 | 293 | self.table.clearContents() 294 | self.table.setRowCount(0) 295 | self.showInTable() 296 | 297 | def startRename(self): 298 | # 读取配置 299 | self.config = readConfig() 300 | self.loadConfig() 301 | 302 | # 命名前检查 303 | if not self.renameCheck(): 304 | return 305 | 306 | # 未勾选的语言加入 delete_list 307 | delete_list = [] 308 | if not self.allowSc.isChecked(): 309 | delete_list.extend(self.sc_list) 310 | if not self.allowTc.isChecked(): 311 | delete_list.extend(self.tc_list) 312 | 313 | # 删除未勾选的语言 314 | if self.remove_unused and delete_list: 315 | if self.removeCheck(delete_list): 316 | send2trash.send2trash(delete_list) 317 | else: 318 | return 319 | 320 | # 计算重命名数量 321 | rename_num = 0 322 | 323 | # 字幕重命名 324 | if self.allowSc.isChecked(): 325 | state_sc = renameAction( 326 | self.sc_extension, 327 | self.video_list, 328 | self.sc_list, 329 | self.move_to_folder, 330 | self.encode 331 | ) 332 | if state_sc == 516: 333 | self.showInfo("error", "重命名失败", "目标文件夹存在同名的简体字幕") 334 | return 335 | else: 336 | rename_num = rename_num + len(self.sc_list) 337 | 338 | if self.allowTc.isChecked(): 339 | state_tc = renameAction( 340 | self.tc_extension, 341 | self.video_list, 342 | self.tc_list, 343 | self.move_to_folder, 344 | self.encode 345 | ) 346 | if state_tc == 516: 347 | self.showInfo("error", "重命名失败", "目标文件夹存在同名的繁体字幕") 348 | return 349 | else: 350 | rename_num = rename_num + len(self.sc_list) 351 | 352 | self.initList() 353 | addRenameTimes(self.config, configPath()) 354 | addRenameNum(self.config, configPath(), rename_num) 355 | self.showInfo("success", "", "重命名成功") 356 | 357 | def loadConfig(self): 358 | self.allowSc.setChecked(self.config.getboolean("Application", "sc")) 359 | self.allowTc.setChecked(self.config.getboolean("Application", "tc")) 360 | 361 | self.sc_extension = self.config.get("Extension", "sc") 362 | self.tc_extension = self.config.get("Extension", "tc") 363 | 364 | self.remove_unused = self.config.getboolean("General", "remove_unused_sub") 365 | self.move_to_folder = self.config.getint("General", "move_renamed_sub") 366 | self.encode = self.config.get("General", "encode") 367 | 368 | def renameCheck(self): 369 | # 是否有视频与字幕文件 370 | if not self.video_list: 371 | self.showInfo("warning", "", "请添加视频文件") 372 | return False 373 | 374 | if not self.sc_list and not self.tc_list: 375 | self.showInfo("warning", "", "请添加字幕文件") 376 | return False 377 | 378 | # 必须勾选简体或繁体 379 | if not self.allowSc.isChecked() and not self.allowTc.isChecked(): 380 | self.showInfo("error", "", "请勾选需要重命名的字幕格式:简体或繁体") 381 | return False 382 | 383 | # 勾选的语言下必须存在字幕文件 384 | if self.allowSc.isChecked() and not self.sc_list: 385 | self.showInfo("error", "", "未发现待命名的简体字幕文件,请确认勾选情况") 386 | return False 387 | 388 | if self.allowTc.isChecked() and not self.tc_list: 389 | self.showInfo("error", "", "未发现待命名的繁体字幕文件,请确认勾选情况") 390 | return False 391 | 392 | # 简体繁体的扩展名不可相同 393 | if self.allowSc.isChecked() and self.allowTc.isChecked() \ 394 | and self.sc_extension == self.tc_extension: 395 | print(self.sc_extension) 396 | print(self.tc_extension) 397 | self.showInfo("error", "", "简体扩展名与繁体扩展名不可相同") 398 | return False 399 | 400 | # 视频与字幕个数需相等 401 | if (self.allowSc.isChecked() and len(self.video_list) != len(self.sc_list)) \ 402 | or (self.allowTc.isChecked() and len(self.video_list) != len(self.tc_list)): 403 | self.showInfo("error", "", "视频与字幕的数量不相等") 404 | return False 405 | 406 | return True 407 | 408 | def removeCheck(self, delete_list): 409 | # 获得 delete_list 文件名 410 | delete_list_lonely = [] 411 | for item in delete_list: 412 | item_lonely = os.path.basename(item) 413 | if len(item_lonely) > 60: # 截取最后 60 位 414 | item_lonely = "..." + item_lonely[-60:] 415 | delete_list_lonely.append(item_lonely) 416 | 417 | # 弹窗提醒待删除文件 418 | delete_file = "
".join(delete_list_lonely) # 转为字符串形式 419 | notice = MessageBox("下列文件将被删除", delete_file, self) 420 | if notice.exec(): 421 | return True 422 | else: 423 | return False 424 | 425 | def justRemoveSub(self): 426 | delete_list = [] 427 | if self.allowSc.isChecked(): 428 | delete_list.extend(self.sc_list) 429 | if self.allowTc.isChecked(): 430 | delete_list.extend(self.tc_list) 431 | 432 | if delete_list: 433 | if self.removeCheck(delete_list): 434 | send2trash.send2trash(delete_list) 435 | self.initList() 436 | self.showInfo("success", "", "删除成功") 437 | else: 438 | return 439 | else: 440 | self.showInfo("warning", "", "没有要删除的文件") 441 | 442 | def showInfo(self, state, title, content): 443 | info_state = { 444 | "info": InfoBar.info, 445 | "success": InfoBar.success, 446 | "warning": InfoBar.warning, 447 | "error": InfoBar.error 448 | } 449 | 450 | if state in info_state: 451 | info_state[state]( 452 | title=title, content=content, 453 | orient=Qt.Horizontal, isClosable=True, 454 | position=InfoBarPosition.TOP, 455 | duration=2000, parent=self 456 | ) 457 | 458 | 459 | class MyAboutWindow(QDialog, AboutWindow): 460 | def __init__(self): 461 | super().__init__() 462 | self.setupUI(self) 463 | self.initUI() 464 | self.config = readConfig() 465 | self.loadConfig() 466 | 467 | def initUI(self): 468 | StyleSheet.WINDOW.apply(self) # 应用主题样式表 469 | self.configPathButton.clicked.connect(self.openConfigPath) 470 | 471 | @staticmethod 472 | def openConfigPath(): 473 | config_path = configPath()[0] 474 | if config_path != "N/A": 475 | if platform.system() == "Windows": 476 | subprocess.call(["explorer", config_path]) 477 | elif platform.system() == "Darwin": 478 | subprocess.call(["open", config_path]) 479 | elif platform.system() == "Linux": 480 | subprocess.call(["xdg-open", config_path]) 481 | 482 | def loadConfig(self): 483 | self.openTimes.setText(self.config.get("Counter", "open_times")) 484 | self.renameTimes.setText(self.config.get("Counter", "rename_times")) 485 | self.renameNum.setText(self.config.get("Counter", "rename_num")) 486 | 487 | 488 | class MySettingWindow(QDialog, SettingWindow): 489 | def __init__(self): 490 | super().__init__() 491 | self.setupUI(self) 492 | self.initUI() 493 | self.config = readConfig() 494 | self.loadConfig() 495 | 496 | def initUI(self): 497 | StyleSheet.WINDOW.apply(self) # 应用主题样式表 498 | self.applyButton.clicked.connect(self.saveConfig) # 保存配置 499 | self.cancelButton.clicked.connect(lambda: self.close()) # 关闭窗口 500 | 501 | def loadConfig(self): 502 | self.themeSelectSwitch.setCurrentIndex(self.config.getint("Application", "theme")) 503 | self.videoFormat.setText(self.config.get("Video", "more_extension")) 504 | self.scFormat.setText(self.config.get("Extension", "sc")) 505 | self.tcFormat.setText(self.config.get("Extension", "tc")) 506 | self.removeSubSwitch.setChecked(self.config.getboolean("General", "remove_unused_sub")) 507 | self.moveSubSwitch.setCurrentIndex(self.config.getint("General", "move_renamed_sub")) 508 | self.encodeType.setCurrentText(self.config.get("General", "encode")) 509 | 510 | def saveConfig(self): 511 | self.config.set("Application", "theme", str(self.themeSelectSwitch.currentIndex())) 512 | self.config.set("Video", "more_extension", self.videoFormat.text()) 513 | self.config.set("Extension", "sc", self.scFormat.currentText()) 514 | self.config.set("Extension", "tc", self.tcFormat.currentText()) 515 | self.config.set("General", "remove_unused_sub", str(self.removeSubSwitch.isChecked()).lower()) 516 | self.config.set("General", "move_renamed_sub", str(self.moveSubSwitch.currentIndex())) 517 | self.config.set("General", "encode", self.encodeType.currentText()) 518 | 519 | with open(configPath()[1], "w", encoding="utf-8") as content: 520 | self.config.write(content) 521 | 522 | self.close() 523 | -------------------------------------------------------------------------------- /src/font/Study-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/src/font/Study-Bold.otf -------------------------------------------------------------------------------- /src/function.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import shutil 4 | import codecs 5 | import chardet 6 | 7 | from src.module.detectsub import detectSubLanguage 8 | 9 | 10 | def formatRawFileList(raw_file_list, file_list): 11 | for raw_file in raw_file_list: 12 | # 转换为文件路径 13 | file_path = raw_file.toLocalFile() 14 | 15 | # Windows 下调整路径分隔符 16 | if platform.system() == 'Windows': 17 | file_path = file_path.replace('/', '\\') 18 | 19 | # 解决 macOS 下路径无法识别 20 | if file_path.endswith('/'): 21 | file_path = file_path[:-1] 22 | 23 | # 排除文件夹 24 | if not os.path.isfile(file_path): 25 | continue 26 | 27 | file_list.append(file_path) 28 | 29 | file_list = list(set(file_list)) # 去重 30 | return file_list 31 | 32 | 33 | def splitList(comb_list): 34 | file_name = comb_list[0] 35 | file_struct = file_name.split(".") 36 | file_extension = file_struct[-1].lower() 37 | 38 | video_extension = ["mkv", "mp4", "avi", "flv", "webm", "m4v", "mov", "rm", "rmvb"] 39 | video_extension.extend([item.strip() for item in comb_list[1].split(",")]) 40 | 41 | subtitle_extension = ["ass", "ssa", "srt", "mks"] 42 | 43 | # 视频文件 44 | if file_extension in video_extension: 45 | return file_name, "video" 46 | 47 | # 字幕文件 48 | elif file_extension in subtitle_extension: 49 | try: 50 | sub_language = detectSubLanguage(file_name) 51 | except Exception as e: 52 | print(e) 53 | sub_language = "error" 54 | 55 | return file_name, sub_language 56 | 57 | # 其他文件 58 | else: 59 | return file_name, "other" 60 | 61 | 62 | # 重命名动作,简繁体会分别执行一次renameAction,因此不需要区分运行时是简体还是繁体 63 | # - lang_format: 用户定义的简繁体后缀 64 | # - video_list: 视频文件列表 65 | # - sub_list: 字幕文件列表 66 | # - move_to_folder: 是否要移动至视频文件夹 67 | # - encode: 是否要编码转换 68 | def renameAction(lang_format, video_list, sub_list, move_to_folder, encode): 69 | # 1 => 根据规则输出改名后的完整字幕路径列表 70 | new_sub_list = [] 71 | for i in range(len(video_list)): 72 | this_video_path = os.path.dirname(video_list[i]) # 视频路径 73 | this_video_name = os.path.splitext(os.path.basename(video_list[i]))[0] # 视频文件名(不含扩展名) 74 | this_sub_path = os.path.dirname(sub_list[i]) # 字幕路径 75 | this_sub_extension = os.path.splitext(os.path.basename(sub_list[i]))[-1] # 字幕扩展名 76 | 77 | if move_to_folder == 0: 78 | # 保持原位(append自动添加到末尾) 79 | new_sub_list.append(os.path.join(this_sub_path, this_video_name + lang_format + this_sub_extension)) 80 | else: 81 | # 移动至视频文件夹 82 | new_sub_list.append(os.path.join(this_video_path, this_video_name + lang_format + this_sub_extension)) 83 | 84 | # 2 => 检查目标目录是否存在同名文件 85 | for new_sub in new_sub_list: 86 | if os.path.exists(new_sub): 87 | return 516 88 | 89 | # 3 => 修改编码 90 | if encode == "UTF-8" or encode == "UTF-8-SIG": 91 | for this_sub in sub_list: 92 | # 识别 93 | with open(this_sub, "rb") as file: 94 | sub_data = file.read() 95 | result = chardet.detect(sub_data) 96 | encoding = result["encoding"] 97 | if encoding.lower() == "gb2312": # 修正解码错误 98 | encoding = "gb18030" 99 | 100 | # 忽略错误,强行转换,最为致命~ 101 | with codecs.open(this_sub, "r", encoding=encoding, errors="ignore") as file: 102 | content = file.read() 103 | with codecs.open(this_sub, "w", encoding=encode, errors="ignore") as file: 104 | file.write(content) 105 | 106 | # 4 => 重命名 107 | for i in range(len(new_sub_list)): 108 | # 重命名 109 | # noinspection PyTypeChecker 110 | shutil.copy(sub_list[i], new_sub_list[i]) 111 | 112 | # 若设置剪切,则删除源路径的字幕 113 | if move_to_folder != 1: 114 | os.remove(sub_list[i]) 115 | -------------------------------------------------------------------------------- /src/gui/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/src/gui/__init__.py -------------------------------------------------------------------------------- /src/gui/about.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import Qt 2 | from PySide6.QtWidgets import QLabel, QVBoxLayout, QHBoxLayout, QFrame 3 | from PySide6.QtGui import QIcon, QPixmap 4 | from qfluentwidgets import FluentIcon, ToolButton 5 | 6 | from src.module.resource import getResource 7 | from src.module.config import configPath 8 | from src.module.version import currentVersion 9 | 10 | 11 | class AboutWindow(object): 12 | def setupUI(self, this_window): 13 | this_window.setWindowTitle("关于") 14 | this_window.setWindowIcon(QIcon(getResource("image/icon.png"))) 15 | this_window.resize(550, -1) 16 | this_window.setFixedSize(self.size()) # 禁止拉伸窗口 17 | 18 | # LOGO 19 | 20 | self.logo = QLabel() 21 | self.logo.setFixedSize(291, 40) 22 | self.logo.setPixmap(QPixmap(getResource("image/logo.png"))) 23 | self.logo.setScaledContents(True) 24 | 25 | self.logoLayout = QHBoxLayout() 26 | self.logoLayout.addWidget(self.logo) 27 | 28 | self.logoFrame = QFrame() 29 | self.logoFrame.setLayout(self.logoLayout) 30 | 31 | # 版本 32 | 33 | self.versionLabel = QLabel(f"版本 {currentVersion()}") 34 | self.versionLabel.setObjectName("versionLabel") 35 | self.versionLabel.setAlignment(Qt.AlignCenter) 36 | 37 | # 计数 38 | 39 | self.openTimesTitle = QLabel("启动次数") 40 | self.openTimes = QLabel("0") 41 | self.openTimesCard = self.usageCard(self.openTimesTitle, self.openTimes) 42 | 43 | self.renameTimesTitle = QLabel("重命名次数") 44 | self.renameTimes = QLabel("0") 45 | self.renameTimesCard = self.usageCard(self.renameTimesTitle, self.renameTimes) 46 | 47 | self.renameNumTitle = QLabel("重命名数量") 48 | self.renameNum = QLabel("0") 49 | self.renameNumcard = self.usageCard(self.renameNumTitle, self.renameNum) 50 | 51 | self.usageCardLayout = QHBoxLayout() 52 | self.usageCardLayout.setSpacing(12) 53 | self.usageCardLayout.setContentsMargins(0, 0, 0, 0) 54 | self.usageCardLayout.addWidget(self.openTimesCard) 55 | self.usageCardLayout.addWidget(self.renameTimesCard) 56 | self.usageCardLayout.addWidget(self.renameNumcard) 57 | 58 | # 功能 59 | 60 | self.configPathTitle = QLabel("配置文件") 61 | self.configPathInfo = QLabel(configPath()[0]) 62 | 63 | # self.configPathButton = PushButton("打开", self) 64 | # self.configPathButton.setFixedWidth(80) 65 | self.configPathButton = ToolButton(FluentIcon.FOLDER, self) 66 | self.configPathCard = self.funcCard(self.configPathTitle, self.configPathInfo, self.configPathButton) 67 | 68 | # 叠叠乐 69 | 70 | layout = QVBoxLayout(this_window) 71 | layout.setSpacing(12) 72 | layout.setContentsMargins(24, 24, 24, 24) 73 | layout.addWidget(self.logoFrame) 74 | layout.addSpacing(-14) 75 | layout.addWidget(self.versionLabel) 76 | layout.addSpacing(24) 77 | layout.addLayout(self.usageCardLayout) 78 | layout.addWidget(self.configPathCard) 79 | 80 | def usageCard(self, usage_title, usage_times): 81 | usage_title.setObjectName("cardTitleLabel") 82 | usage_times.setObjectName("cardTitleLabel") 83 | 84 | self.card1 = QHBoxLayout() 85 | self.card1.setContentsMargins(16, 12, 16, 12) 86 | self.card1.addWidget(usage_title, 0) 87 | self.card1.addStretch(0) 88 | self.card1.addWidget(usage_times) 89 | 90 | self.cardFrame1 = QFrame() 91 | self.cardFrame1.setObjectName("cardFrame") 92 | self.cardFrame1.setLayout(self.card1) 93 | 94 | return self.cardFrame1 95 | 96 | def funcCard(self, card_title, card_info, card_func): 97 | card_title.setObjectName("cardTitleLabel") 98 | card_info.setObjectName("cardInfoLabel") 99 | 100 | self.infoPart = QVBoxLayout() 101 | self.infoPart.setSpacing(2) 102 | self.infoPart.setContentsMargins(0, 0, 0, 0) 103 | self.infoPart.addWidget(card_title) 104 | self.infoPart.addWidget(card_info) 105 | 106 | self.card2 = QHBoxLayout() 107 | self.card2.setContentsMargins(16, 16, 16, 16) 108 | self.card2.addLayout(self.infoPart, 0) 109 | self.card2.addStretch(0) 110 | self.card2.addWidget(card_func) 111 | 112 | self.cardFrame2 = QFrame() 113 | self.cardFrame2.setObjectName("cardFrame") 114 | self.cardFrame2.setLayout(self.card2) 115 | 116 | return self.cardFrame2 117 | -------------------------------------------------------------------------------- /src/gui/mainwindow.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import Qt, QMetaObject 2 | from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QHBoxLayout, QFrame, QAbstractItemView, QHeaderView 3 | from PySide6.QtGui import QFontDatabase, QFont, QIcon 4 | from qfluentwidgets import (PushButton, TableWidget, PrimaryPushButton, CheckBox, FluentIcon, ToolButton, 5 | IndeterminateProgressRing) 6 | from qfluentwidgets.common.style_sheet import setCustomStyleSheet 7 | 8 | from src.module.resource import getResource 9 | from src.module.version import currentVersion 10 | 11 | 12 | class MainWindow(object): 13 | def setupUI(self, this_window): 14 | # 配置字体 15 | font_id = QFontDatabase.addApplicationFont(getResource("src/font/Study-Bold.otf")) 16 | font_family = QFontDatabase.applicationFontFamilies(font_id) 17 | 18 | this_window.setWindowTitle(f"SubtitleRenamer {currentVersion()}") 19 | this_window.setWindowIcon(QIcon(getResource("image/icon.png"))) 20 | this_window.resize(1200, 660) 21 | this_window.setAcceptDrops(True) 22 | 23 | # 标题区域 24 | 25 | self.titleLabel = QLabel("SubtitleRenamer") 26 | self.titleLabel.setObjectName("titleLabel") 27 | self.titleLabel.setFont(QFont(font_family)) 28 | 29 | self.subtitleLabel = QLabel("有点厉害的动画字幕重命名工具") 30 | self.subtitleLabel.setObjectName('subtitleLabel') 31 | 32 | self.titleLayout = QVBoxLayout() 33 | self.titleLayout.setContentsMargins(0, 0, 0, 0) 34 | self.titleLayout.addWidget(self.titleLabel, 0, Qt.AlignTop) 35 | self.titleLayout.addWidget(self.subtitleLabel, 0, Qt.AlignTop) 36 | 37 | self.spinner = IndeterminateProgressRing() 38 | self.spinner.setFixedSize(24, 24) 39 | self.spinner.setStrokeWidth(3) 40 | self.spinner.setVisible(False) 41 | 42 | self.newVersionButton = PrimaryPushButton("有新版本", self, FluentIcon.LINK) 43 | self.newVersionButton.setVisible(False) 44 | 45 | self.aboutButton = ToolButton(FluentIcon.INFO, self) 46 | self.settingButton = PushButton("设置", self, FluentIcon.SETTING) 47 | 48 | self.headerLayout = QHBoxLayout() 49 | self.headerLayout.setContentsMargins(0, 0, 0, 0) 50 | self.headerLayout.addLayout(self.titleLayout) 51 | self.headerLayout.addStretch(0) 52 | self.headerLayout.addWidget(self.spinner, 0) 53 | self.headerLayout.addSpacing(16) 54 | self.headerLayout.addWidget(self.newVersionButton, 0) 55 | self.headerLayout.addSpacing(12) 56 | self.headerLayout.addWidget(self.aboutButton, 0) 57 | self.headerLayout.addSpacing(12) 58 | self.headerLayout.addWidget(self.settingButton, 0) 59 | 60 | # 表格区域 61 | 62 | self.table = TableWidget(self) 63 | self.table.verticalHeader().hide() # 隐藏左侧表头 64 | self.table.horizontalHeader().setHighlightSections(False) # 选中时表头不加粗 65 | self.table.setSelectionMode(QAbstractItemView.SingleSelection) # 单选模式 66 | self.table.setEditTriggers(QAbstractItemView.NoEditTriggers) # 禁止双击编辑 67 | self.table.setColumnCount(3) 68 | self.table.setHorizontalHeaderLabels(["视频文件", "简体字幕", "繁体字幕"]) 69 | # self.table.setColumnWidth(0, 376) # 1126 70 | # self.table.setColumnWidth(1, 375) 71 | # self.table.setColumnWidth(2, 375) 72 | 73 | # 自定义表格 QSS 74 | # styleSheetManager.deregister(self.table) # 禁用皮肤 75 | with open(getResource("src/style/table_light.qss"), encoding="utf-8") as file: 76 | table_style_light = file.read() 77 | with open(getResource("src/style/table_dark.qss"), encoding="utf-8") as file: 78 | table_style_dark = file.read() 79 | setCustomStyleSheet(self.table, table_style_light, table_style_dark) 80 | 81 | self.header = self.table.horizontalHeader() 82 | self.header.setSectionResizeMode(QHeaderView.ResizeMode.Stretch) # 列宽平均分配 83 | 84 | self.tableLayout = QHBoxLayout() 85 | self.tableLayout.setContentsMargins(0, 0, 0, 0) 86 | self.tableLayout.addWidget(self.table) 87 | 88 | self.tableFrame = QFrame() 89 | self.tableFrame.setObjectName("tableFrame") 90 | self.tableFrame.setLayout(self.tableLayout) 91 | 92 | # 执行区域 93 | 94 | self.allowSc = CheckBox("简体", self) 95 | # self.allowSc.setChecked(True) 96 | 97 | self.allowTc = CheckBox("繁体", self) 98 | # self.allowTc.setChecked(False) 99 | 100 | self.removeButton = PushButton("删除选中字幕", self) 101 | self.removeButton.setFixedWidth(120) 102 | 103 | self.separator = QFrame() 104 | self.separator.setObjectName("separator") 105 | self.separator.setFixedSize(1, 30) 106 | 107 | self.clearButton = PushButton("清空列表", self) 108 | self.clearButton.setFixedWidth(120) 109 | self.renameButton = PrimaryPushButton("重命名", self) 110 | self.renameButton.setFixedWidth(120) 111 | 112 | self.actionLayout = QHBoxLayout() 113 | self.actionLayout.addWidget(self.allowSc) 114 | self.actionLayout.addSpacing(32) 115 | self.actionLayout.addWidget(self.allowTc) 116 | self.actionLayout.addStretch(0) 117 | self.actionLayout.addWidget(self.removeButton) 118 | self.actionLayout.addSpacing(20) 119 | self.actionLayout.addWidget(self.separator) 120 | self.actionLayout.addSpacing(20) 121 | self.actionLayout.addWidget(self.clearButton) 122 | self.actionLayout.addSpacing(12) 123 | self.actionLayout.addWidget(self.renameButton) 124 | 125 | # 框架叠叠乐 126 | 127 | self.centralWidget = QWidget(this_window) 128 | 129 | self.vBoxLayout = QVBoxLayout(self.centralWidget) 130 | self.vBoxLayout.setSpacing(0) 131 | self.vBoxLayout.setContentsMargins(36, 20, 36, 24) 132 | self.vBoxLayout.addLayout(self.headerLayout) 133 | self.vBoxLayout.addSpacing(24) 134 | self.vBoxLayout.addWidget(self.tableFrame, 0) 135 | self.vBoxLayout.addSpacing(24) 136 | self.vBoxLayout.addLayout(self.actionLayout, 0) 137 | 138 | this_window.setCentralWidget(self.centralWidget) 139 | 140 | QMetaObject.connectSlotsByName(this_window) 141 | -------------------------------------------------------------------------------- /src/gui/setting.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import Qt 2 | from PySide6.QtGui import QIcon 3 | from PySide6.QtWidgets import QLabel, QVBoxLayout, QHBoxLayout, QFrame, QWidget 4 | from qfluentwidgets import (Theme, setTheme, PushButton, SwitchButton, ComboBox, PrimaryPushButton, EditableComboBox, 5 | LineEdit, setThemeColor, qconfig, SingleDirectionScrollArea, SmoothMode) 6 | 7 | from src.module.resource import getResource 8 | 9 | 10 | class SettingWindow(object): 11 | def setupUI(self, this_window): 12 | this_window.setWindowTitle("设置") 13 | this_window.setWindowIcon(QIcon(getResource("image/icon.png"))) 14 | this_window.resize(800, 580) 15 | this_window.setFixedSize(self.size()) # 禁止拉伸窗口 16 | 17 | # ================================================= 18 | # 主题设置 19 | self.themeTitle = QLabel("主题设置") 20 | self.themeTitle.setObjectName("settingTitle") 21 | self.themeTitle.setIndent(22) 22 | 23 | # 主题模式 24 | self.themeSelectTitle = QLabel("主题模式") 25 | self.themeSelectInfo = QLabel("当前主题:跟随系统") 26 | self.themeSelectSwitch = ComboBox(self) 27 | self.themeSelectSwitch.setMinimumWidth(240) 28 | self.themeSelectSwitch.setMaximumWidth(240) 29 | self.themeSelectSwitch.addItems(["跟随系统", "浅色模式", "深色模式"]) 30 | self.themeSelectSwitch.setCurrentIndex(0) # 默认第一个 31 | self.themeSelectSwitch.currentIndexChanged.connect(self.themeSelectFunction) 32 | self.themeSelectCard = self.settingCard(self.themeSelectTitle, self.themeSelectInfo, self.themeSelectSwitch) 33 | 34 | # ================================================= 35 | # 视频格式设置 36 | self.videoTypeTitle = QLabel("视频格式设置") 37 | self.videoTypeTitle.setObjectName("settingTitle") 38 | self.videoTypeTitle.setIndent(22) 39 | 40 | # 简体字幕扩展名 41 | self.videoTitle = QLabel("简体字幕扩展名") 42 | self.videoInfo = QLabel("用于支持更多视频格式,扩展名使用英文逗号分隔,如 rm, rmvb") 43 | self.videoFormat = LineEdit(self) 44 | self.videoFormat.setMinimumWidth(240) 45 | self.videoFormat.setMaximumWidth(240) 46 | self.videoFormat.setPlaceholderText("默认已支持常见视频文件") 47 | self.videoCard = self.settingCard(self.videoTitle, self.videoInfo, self.videoFormat) 48 | 49 | # ================================================= 50 | # 扩展名设置 51 | self.extensionTitle = QLabel("扩展名设置") 52 | self.extensionTitle.setObjectName("settingTitle") 53 | self.extensionTitle.setIndent(22) 54 | 55 | # 简体字幕扩展名 56 | self.scTitle = QLabel("简体字幕扩展名") 57 | self.scInfo = QLabel("默认为空,设置后会显示在字幕扩展名之前") 58 | self.scFormat = EditableComboBox(self) 59 | self.scFormat.setMinimumWidth(240) 60 | self.scFormat.setMaximumWidth(240) 61 | self.scFormat.addItems([".sc", ".chs", ".zh-Hans"]) 62 | self.scFormat.setPlaceholderText("不添加简体扩展名") 63 | self.scCard = self.settingCard(self.scTitle, self.scInfo, self.scFormat) 64 | 65 | # 繁体字幕扩展名 66 | self.tcTitle = QLabel("繁体字幕扩展名") 67 | self.tcInfo = QLabel("默认为空,设置后会显示在字幕扩展名之前") 68 | self.tcFormat = EditableComboBox(self) 69 | self.tcFormat.setMinimumWidth(240) 70 | self.tcFormat.setMaximumWidth(240) 71 | self.tcFormat.addItems([".tc", ".cht", ".zh-Hant"]) 72 | self.tcFormat.setPlaceholderText("不添加繁体扩展名") 73 | self.tcCard = self.settingCard(self.tcTitle, self.tcInfo, self.tcFormat) 74 | 75 | # ================================================= 76 | # 其他设置 77 | self.otherTitle = QLabel("其他设置") 78 | self.otherTitle.setObjectName("settingTitle") 79 | self.otherTitle.setIndent(22) 80 | 81 | # 删除多余字幕 82 | self.removeSubTitle = QLabel("删除多余字幕") 83 | self.removeSubInfo = QLabel("当前操作:没有选择的字幕语言将在重命名后被删除") 84 | self.removeSubSwitch = SwitchButton() 85 | self.removeSubSwitch.setChecked(True) # 默认开启 86 | self.removeSubSwitch.checkedChanged.connect(self.removeSubFunction) 87 | self.removeSubCard = self.settingCard(self.removeSubTitle, self.removeSubInfo, self.removeSubSwitch) 88 | 89 | # 移动字幕文件 90 | self.moveSubTitle = QLabel("移动字幕文件") 91 | self.moveSubInfo = QLabel("当前操作:重命名成功后,移动字幕到视频文件夹") 92 | self.moveSubSwitch = ComboBox(self) 93 | self.moveSubSwitch.setMinimumWidth(240) 94 | self.moveSubSwitch.setMaximumWidth(240) 95 | self.moveSubSwitch.addItems(["不移动", "复制字幕", "剪切字幕"]) 96 | self.moveSubSwitch.setCurrentIndex(0) # 默认第一个 97 | self.moveSubSwitch.currentIndexChanged.connect(self.moveSubFunction) 98 | self.moveSubCard = self.settingCard(self.moveSubTitle, self.moveSubInfo, self.moveSubSwitch) 99 | 100 | # 转换字幕编码 101 | self.encodeTitle = QLabel("转换字幕编码") 102 | self.encodeInfo = QLabel("重命名后将字幕编码转换为指定格式") 103 | self.encodeType = ComboBox(self) 104 | self.encodeType.setMinimumWidth(240) 105 | self.encodeType.setMaximumWidth(240) 106 | self.encodeType.addItems(["Never", "UTF-8", "UTF-8-SIG"]) 107 | self.encodeType.setCurrentIndex(0) # 默认第一个 108 | self.encodeCard = self.settingCard(self.encodeTitle, self.encodeInfo, self.encodeType) 109 | 110 | # ================================================= 111 | # 按钮 112 | self.cancelButton = PushButton("取消", self) 113 | self.cancelButton.setFixedWidth(120) 114 | 115 | self.applyButton = PrimaryPushButton("保存", self) 116 | self.applyButton.setFixedWidth(120) 117 | 118 | self.buttonLayout = QHBoxLayout() 119 | self.buttonLayout.setSpacing(12) 120 | self.buttonLayout.addStretch(0) 121 | self.buttonLayout.addWidget(self.cancelButton) 122 | self.buttonLayout.addWidget(self.applyButton) 123 | self.buttonLayout.addStretch(0) 124 | 125 | # ================================================= 126 | # 嵌套滚动区域到settingLayout中 127 | scrollWidget = QWidget() 128 | scrollWidget.setObjectName("scrollWidget") 129 | 130 | # 滚动区域 131 | scrollArea = SingleDirectionScrollArea(orient=Qt.Vertical) 132 | scrollArea.setWidgetResizable(True) 133 | scrollArea.setSmoothMode(SmoothMode.NO_SMOOTH) # 取消平滑滚动 134 | scrollArea.setWidget(scrollWidget) 135 | 136 | # 设置布局 137 | settingLayout = QVBoxLayout(scrollWidget) 138 | settingLayout.setSpacing(8) 139 | settingLayout.setContentsMargins(20, 20, 20, 0) # 上左右下 140 | settingLayout.addWidget(self.themeTitle) 141 | settingLayout.addWidget(self.themeSelectCard) 142 | settingLayout.addSpacing(12) 143 | settingLayout.addWidget(self.videoTypeTitle) 144 | settingLayout.addWidget(self.videoCard) 145 | settingLayout.addSpacing(12) 146 | settingLayout.addWidget(self.extensionTitle) 147 | settingLayout.addWidget(self.scCard) 148 | settingLayout.addWidget(self.tcCard) 149 | settingLayout.addSpacing(12) 150 | settingLayout.addWidget(self.otherTitle) 151 | settingLayout.addWidget(self.removeSubCard) 152 | settingLayout.addWidget(self.moveSubCard) 153 | settingLayout.addWidget(self.encodeCard) 154 | 155 | # 添加到窗口 156 | layout = QVBoxLayout(this_window) 157 | layout.setContentsMargins(0, 0, 0, 16) 158 | layout.addWidget(scrollArea) 159 | layout.addLayout(self.buttonLayout) 160 | 161 | def settingCard(self, card_title, card_info, card_func): 162 | card_title.setObjectName("cardTitleLabel") 163 | card_info.setObjectName("cardInfoLabel") 164 | 165 | self.infoPart = QVBoxLayout() 166 | self.infoPart.setSpacing(2) 167 | self.infoPart.setContentsMargins(0, 0, 0, 0) 168 | self.infoPart.addWidget(card_title) 169 | self.infoPart.addWidget(card_info) 170 | 171 | self.card = QHBoxLayout() 172 | self.card.setContentsMargins(20, 20, 20, 20) 173 | self.card.addLayout(self.infoPart, 0) 174 | self.card.addStretch(0) 175 | self.card.addWidget(card_func) 176 | 177 | self.cardFrame = QFrame() 178 | self.cardFrame.setObjectName("cardFrame") 179 | self.cardFrame.setLayout(self.card) 180 | 181 | return self.cardFrame 182 | 183 | def removeSubFunction(self, state): 184 | if state: 185 | self.removeSubInfo.setText("当前操作:没有选择的字幕语言将在重命名后被删除") 186 | else: 187 | self.removeSubInfo.setText("当前操作:仅重命名字幕,不删除任何文件") 188 | 189 | def moveSubFunction(self): 190 | if self.moveSubSwitch.currentIndex() == 0: 191 | self.moveSubInfo.setText("当前操作:仅重命名字幕,不移动文件位置") 192 | elif self.moveSubSwitch.currentIndex() == 1: 193 | self.moveSubInfo.setText("当前操作:重命名成功后,复制字幕到视频文件夹") 194 | elif self.moveSubSwitch.currentIndex() == 2: 195 | self.moveSubInfo.setText("当前操作:重命名成功后,剪切字幕到视频文件夹") 196 | 197 | def themeSelectFunction(self): 198 | if self.themeSelectSwitch.currentIndex() == 0: 199 | self.themeSelectInfo.setText("当前主题:跟随系统") 200 | setTheme(Theme.AUTO) 201 | if qconfig.theme == Theme.LIGHT: 202 | setThemeColor("#1B96DE") 203 | elif qconfig.theme == Theme.DARK: 204 | setThemeColor("#4EC8FA") 205 | elif self.themeSelectSwitch.currentIndex() == 1: 206 | self.themeSelectInfo.setText("当前主题:浅色模式") 207 | setTheme(Theme.LIGHT) 208 | setThemeColor("#1B96DE") 209 | elif self.themeSelectSwitch.currentIndex() == 2: 210 | self.themeSelectInfo.setText("当前主题:深色模式") 211 | setTheme(Theme.DARK) 212 | setThemeColor("#4EC8FA") 213 | -------------------------------------------------------------------------------- /src/module/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuthx/subtitle-renamer/c1ac277965063f88844aec772d535606dc534550/src/module/__init__.py -------------------------------------------------------------------------------- /src/module/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import configparser 4 | 5 | 6 | # 配置文件路径 7 | def configPath(): 8 | # 定位系统配置文件所在位置 9 | if platform.system() == "Windows": 10 | config_path = os.environ["APPDATA"] 11 | elif platform.system() == "Darwin": 12 | config_path = os.path.expanduser("~/Library/Application Support") 13 | elif platform.system() == "Linux": 14 | config_path = os.path.expanduser("~/.config") 15 | else: 16 | return "N/A" 17 | 18 | config_path = config_path + os.sep + "SubtitleRenamer" 19 | config_file = config_path + os.sep + "config.ini" 20 | 21 | # 是否存在该路径,否则创建 22 | if not os.path.exists(config_path): 23 | os.makedirs(config_path) 24 | 25 | return config_path, config_file 26 | 27 | 28 | # 初始化配置 29 | def initConfig(config_file): 30 | config = configparser.ConfigParser() 31 | 32 | config.add_section("Application") 33 | config.set("Application", "version", "1.7") 34 | config.set("Application", "theme", "0") 35 | config.set("Application", "sc", "true") 36 | config.set("Application", "tc", "false") 37 | 38 | config.add_section("Extension") 39 | config.set("Extension", "sc", "") 40 | config.set("Extension", "tc", "") 41 | 42 | config.add_section("General") 43 | config.set("General", "remove_unused_sub", "true") 44 | config.set("General", "move_renamed_sub", "0") 45 | config.set("General", "encode", "Never") 46 | 47 | config.add_section("Counter") 48 | config.set("Counter", "open_times", "0") 49 | config.set("Counter", "rename_times", "0") 50 | config.set("Counter", "rename_num", "0") 51 | 52 | config.add_section("Video") 53 | config.set("Video", "more_extension", "") 54 | 55 | # 写入配置内容 56 | with open(config_file, "w", encoding="utf-8") as content: 57 | config.write(content) 58 | 59 | 60 | # 检测配置文件合法性 61 | def checkConfig(config, config_file): 62 | if config.get("Application", "theme") not in ["0", "1", "2"]: 63 | config.set("Application", "theme", "0") 64 | 65 | if config.get("Application", "sc") not in ["true", "false"]: 66 | config.set("Application", "sc", "true") 67 | 68 | if config.get("Application", "tc") not in ["true", "false"]: 69 | config.set("Application", "tc", "false") 70 | 71 | if config.get("General", "remove_unused_sub") not in ["true", "false"]: 72 | config.set("General", "remove_unused_sub", "true") 73 | 74 | if config.get("General", "move_renamed_sub") not in ["0", "1", "2"]: 75 | config.set("General", "move_renamed_sub", "0") 76 | 77 | if config.get("General", "encode") not in ["Never", "UTF-8", "UTF-8-SIG"]: 78 | config.set("General", "encode", "Never") 79 | 80 | # 写入配置内容 81 | with open(config_file, "w", encoding="utf-8") as content: 82 | config.write(content) 83 | 84 | 85 | # 更新配置文件 86 | def updateConfigFile(config_file): 87 | config = configparser.ConfigParser() 88 | config.read(config_file, encoding="utf-8") 89 | 90 | # 记录计数器 91 | open_times = config.get("Counter", "open_times") 92 | rename_times = config.get("Counter", "rename_times") 93 | rename_num = config.get("Counter", "rename_num") 94 | 95 | # 版本不符则重建配置文件 96 | if not config.has_section("Application") or config.get("Application", "version") != "1.7": 97 | os.remove(config_file) 98 | initConfig(config_file) 99 | 100 | # 重新读取配置文件 101 | config = configparser.ConfigParser() 102 | config.read(config_file, encoding="utf-8") 103 | 104 | # 更新计数器 105 | config.set("Counter", "open_times", open_times) 106 | config.set("Counter", "rename_times", rename_times) 107 | config.set("Counter", "rename_num", rename_num) 108 | 109 | # 写入配置内容 110 | with open(config_file, "w", encoding="utf-8") as content: 111 | config.write(content) 112 | 113 | 114 | # 读取配置 115 | def readConfig(): 116 | config = configparser.ConfigParser() 117 | config_file = configPath()[1] 118 | 119 | # 不存在则创建新配置 120 | if not os.path.exists(config_file): 121 | initConfig(config_file) 122 | 123 | # 更新配置 124 | config.read(config_file, encoding="utf-8") 125 | updateConfigFile(config_file) 126 | 127 | # 检测合法性(再次读取获得新配置内容) 128 | config.read(config_file, encoding="utf-8") 129 | checkConfig(config, config_file) 130 | 131 | return config 132 | -------------------------------------------------------------------------------- /src/module/counter.py: -------------------------------------------------------------------------------- 1 | def addOpenTimes(config, config_path): 2 | open_times = int(config.get("Counter", "open_times")) + 1 3 | config.set("Counter", "open_times", str(open_times)) 4 | 5 | with open(config_path[1], "w", encoding="utf-8") as content: 6 | config.write(content) 7 | 8 | 9 | def addRenameTimes(config, config_path): 10 | rename_times = int(config.get("Counter", "rename_times")) + 1 11 | config.set("Counter", "rename_times", str(rename_times)) 12 | 13 | with open(config_path[1], "w", encoding="utf-8") as content: 14 | config.write(content) 15 | 16 | 17 | def addRenameNum(config, config_path, rename_num): 18 | rename_num = int(config.get("Counter", "rename_num")) + rename_num 19 | config.set("Counter", "rename_num", str(rename_num)) 20 | 21 | with open(config_path[1], "w", encoding="utf-8") as content: 22 | config.write(content) 23 | -------------------------------------------------------------------------------- /src/module/detectsub.py: -------------------------------------------------------------------------------- 1 | import re 2 | import chardet 3 | import hanzidentifier 4 | import ass 5 | 6 | 7 | def subEncoding(file_name): 8 | with open(file_name, "rb") as content: 9 | data = content.read() 10 | 11 | chardet_result = chardet.detect(data) 12 | encoding = chardet_result["encoding"] 13 | 14 | # 修正解码错误 15 | if encoding.lower() == "gb2312": 16 | encoding = "gb18030" 17 | 18 | return encoding 19 | 20 | 21 | def srtSubtitle(file_name): 22 | # 检测文本编码 23 | encoding = subEncoding(file_name) 24 | 25 | with open(file_name, "r", encoding=encoding) as file: 26 | result = file.read() 27 | 28 | # 匹配序号和时间 29 | srt_pattern = r'\d+\n\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}\n([\s\S]*?)' \ 30 | r'(?=\n\d+\n\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}|\Z)' 31 | 32 | # 提取正文内容 33 | matches = re.findall(srt_pattern, result) 34 | subtitle = [match.strip() for match in matches] 35 | 36 | return subtitle 37 | 38 | 39 | def assSubtitle(file_name): 40 | # 检测文本编码 41 | encoding = subEncoding(file_name) 42 | 43 | # 首先尝试用ass库解析 44 | try: 45 | with open(file_name, "r", encoding=encoding) as file: 46 | result = ass.parse(file).events 47 | 48 | subtitle = [] 49 | for item in result: 50 | # 转义样式中的斜杠 51 | new_item = item.text.replace("\\", "\\\\") 52 | 53 | # 匹配 {} 之外内容 54 | ass_pattern = r'\{[^{}]*\}' 55 | matches = re.sub(ass_pattern, '', new_item) 56 | 57 | # 排除单字的特效字幕 58 | if len(matches) == 1: 59 | continue 60 | 61 | # 排除空内容 62 | if not matches: 63 | continue 64 | 65 | subtitle.append(matches) 66 | 67 | return subtitle 68 | 69 | # 如果ass.parse失败,使用正则表达式解析 70 | except Exception as e: 71 | print(f"ass.parse解析失败,使用正则表达式解析: {e}") 72 | 73 | subtitle = [] 74 | try: 75 | with open(file_name, "r", encoding=encoding) as file: 76 | in_events_section = False 77 | 78 | for line in file: 79 | line = line.strip() 80 | 81 | # 检查是否进入了[Events]部分 82 | if line == "[Events]": 83 | in_events_section = True 84 | continue 85 | 86 | # 检查是否进入了其他部分 87 | if in_events_section and line.startswith("["): 88 | in_events_section = False 89 | 90 | # 只处理Events部分的Dialogue行 91 | if in_events_section and line.startswith("Dialogue:"): 92 | # 分割并获取最后一个部分(对话内容) 93 | parts = line.split(',', 9) # 最多分割9次,确保最后一个元素包含全部对话内容 94 | 95 | if len(parts) >= 10: 96 | text = parts[9] 97 | 98 | # 转义样式中的斜杠 99 | text = text.replace("\\", "\\\\") 100 | 101 | # 移除花括号内的ASS样式代码 102 | clean_text = re.sub(r'\{[^{}]*\}', '', text) 103 | 104 | # 移除多余空白 105 | clean_text = clean_text.strip() 106 | 107 | # 排除单字和空内容 108 | if len(clean_text) > 1 and clean_text: 109 | subtitle.append(clean_text) 110 | return subtitle 111 | 112 | except Exception as e: 113 | print(f"正则解析失败: {e}") 114 | raise e 115 | 116 | def detectSubLanguage(file_name): 117 | # 提取扩展名 118 | name_struct = file_name.split(".") 119 | file_extension = name_struct[-1].lower() 120 | 121 | # 提取纯字幕到列表 122 | if file_extension == "srt": 123 | subtitle = srtSubtitle(file_name) 124 | elif file_extension == "ass" or file_extension == "ssa": 125 | subtitle = assSubtitle(file_name) 126 | elif file_extension == "mks": 127 | subtitle = ["简体"] 128 | else: 129 | subtitle = ["简体"] 130 | 131 | 132 | # 字幕去重 133 | subtitle = list(set(subtitle)) 134 | 135 | # 计算简繁数量 136 | sc = tc = 0 137 | for item in subtitle: 138 | if hanzidentifier.is_simplified(item): 139 | sc += 1 140 | # print("sc: " + item) 141 | elif hanzidentifier.is_traditional(item): 142 | tc += 1 143 | # print("tc: " + item) 144 | 145 | # 打印数量 146 | print(f"简繁比 {sc}:{tc}") 147 | 148 | # 判断简繁,计算比例 0.8:1 149 | if sc * 0.8 > tc: 150 | return "sc" 151 | else: 152 | return "tc" 153 | -------------------------------------------------------------------------------- /src/module/resource.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | def getResource(path): 6 | if hasattr(sys, '_MEIPASS'): 7 | return os.path.join(sys._MEIPASS, path) 8 | return os.path.join(os.path.abspath("."), path) 9 | -------------------------------------------------------------------------------- /src/module/theme.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | from qfluentwidgets import StyleSheetBase, Theme, qconfig 3 | 4 | from src.module.resource import getResource 5 | 6 | 7 | # 定义样式表路径 8 | class StyleSheet(StyleSheetBase, Enum): 9 | WINDOW = "window" 10 | 11 | def path(self, theme=Theme.AUTO): 12 | theme = qconfig.theme if theme == Theme.AUTO else theme 13 | return getResource(f"src/style/style_{theme.value.lower()}.qss") 14 | -------------------------------------------------------------------------------- /src/module/version.py: -------------------------------------------------------------------------------- 1 | import re 2 | import requests 3 | 4 | 5 | def currentVersion(): 6 | current_version = "1.8.2" 7 | return current_version 8 | 9 | 10 | def latestVersion(): 11 | url = "https://raw.githubusercontent.com/nuthx/subtitle-renamer/main/build.spec" 12 | response = requests.get(url) 13 | response_text = response.text.split('\n') 14 | 15 | version_raw = response_text[-3].strip() 16 | re1 = re.findall(r'\'(.*?)\'', version_raw) 17 | latest_version = re1[0] 18 | 19 | return latest_version 20 | 21 | 22 | def newVersion(): 23 | current_version = currentVersion() 24 | latest_version = latestVersion() 25 | 26 | if current_version != latest_version: 27 | return True 28 | else: 29 | return False 30 | -------------------------------------------------------------------------------- /src/style/style_dark.qss: -------------------------------------------------------------------------------- 1 | MyMainWindow, 2 | MyAboutWindow, 3 | MySettingWindow { 4 | background: #1A1A1A; 5 | } 6 | 7 | #titleLabel { 8 | font-size: 32px; 9 | color: #EBEBEB; 10 | } 11 | 12 | #subtitleLabel { 13 | font-size: 13px; 14 | color: #AAA; 15 | } 16 | 17 | #separator { 18 | background: #444; 19 | } 20 | 21 | /* 设置 */ 22 | 23 | #settingTitle { 24 | font-size: 16px; 25 | color: #EBEBEB; 26 | } 27 | 28 | #cardTitleLabel { 29 | font-size: 14px; 30 | /* font-weight: bold; */ 31 | color: #EBEBEB; 32 | } 33 | 34 | #cardInfoLabel { 35 | font-size: 12px; 36 | color: #888; 37 | } 38 | 39 | #cardFrame { 40 | background: #242424; 41 | border: 1px solid #333; 42 | border-radius: 8px; 43 | } 44 | 45 | QScrollArea, 46 | #scrollWidget { 47 | background: transparent; 48 | border: none; 49 | } 50 | 51 | /* Info */ 52 | 53 | #versionLabel { 54 | color: #888; 55 | } 56 | -------------------------------------------------------------------------------- /src/style/style_light.qss: -------------------------------------------------------------------------------- 1 | MyMainWindow, 2 | MyAboutWindow, 3 | MySettingWindow { 4 | background: #F5F5F5; 5 | } 6 | 7 | #titleLabel { 8 | font-size: 32px; 9 | color: #444; 10 | } 11 | 12 | #subtitleLabel { 13 | font-size: 13px; 14 | color: #555; 15 | } 16 | 17 | #separator { 18 | background: #D8D8D8; 19 | } 20 | 21 | /* 设置 */ 22 | 23 | #settingTitle { 24 | font-size: 16px; 25 | color: #000; 26 | } 27 | 28 | #cardTitleLabel { 29 | font-size: 14px; 30 | /* font-weight: bold; */ 31 | color: #000; 32 | } 33 | 34 | #cardInfoLabel { 35 | font-size: 12px; 36 | color: #777; 37 | } 38 | 39 | #cardFrame { 40 | background: #FFF; 41 | border: 1px solid #EDEDED; 42 | border-radius: 8px; 43 | } 44 | 45 | QScrollArea, 46 | #scrollWidget { 47 | background: transparent; 48 | border: none; 49 | } 50 | 51 | /* Info */ 52 | 53 | #versionLabel { 54 | color: #777; 55 | } 56 | -------------------------------------------------------------------------------- /src/style/table_dark.qss: -------------------------------------------------------------------------------- 1 | QTableView { 2 | background: #242424; 3 | outline: none; 4 | border: 1px solid #333; 5 | selection-background-color: transparent; 6 | alternate-background-color: transparent; 7 | border-radius: 8px; 8 | } 9 | 10 | QTableView::item { 11 | background: transparent; 12 | border: 0px; 13 | padding-left: 8px; 14 | padding-right: 8px; 15 | height: 32px; 16 | } 17 | 18 | QHeaderView { 19 | background-color: transparent; 20 | } 21 | 22 | QHeaderView::section { 23 | background-color: transparent; 24 | color: #EBEBEB; 25 | padding-left: 4px; 26 | padding-right: 4px; 27 | border: 1px solid #333; 28 | margin-top: -1px; 29 | margin-bottom: 2px; 30 | font-size: 13px; 31 | font-weight: normal; 32 | } 33 | 34 | QHeaderView::section:horizontal { 35 | border-bottom: 1px solid #333; 36 | border-left: none; 37 | height: 32px; 38 | } 39 | 40 | QHeaderView::section:horizontal:last { 41 | border-right: none; 42 | } 43 | 44 | QHeaderView::section:checked { 45 | background-color: transparent; 46 | } 47 | -------------------------------------------------------------------------------- /src/style/table_light.qss: -------------------------------------------------------------------------------- 1 | QTableView { 2 | background: #FFF; 3 | outline: none; 4 | border: 1px solid #EDEDED; 5 | selection-background-color: transparent; 6 | alternate-background-color: transparent; 7 | border-radius: 8px; 8 | } 9 | 10 | QTableView::item { 11 | background: transparent; 12 | border: 0px; 13 | padding-left: 8px; 14 | padding-right: 8px; 15 | height: 32px; 16 | } 17 | 18 | QHeaderView { 19 | background-color: transparent; 20 | } 21 | 22 | QHeaderView::section { 23 | background-color: transparent; 24 | color: #000; 25 | padding-left: 4px; 26 | padding-right: 4px; 27 | border: 1px solid #EDEDED; 28 | margin-top: -1px; 29 | margin-bottom: 2px; 30 | font-size: 13px; 31 | font-weight: normal; 32 | } 33 | 34 | QHeaderView::section:horizontal { 35 | border-bottom: 1px solid #EDEDED; 36 | border-left: none; 37 | height: 32px; 38 | } 39 | 40 | QHeaderView::section:horizontal:last { 41 | border-right: none; 42 | } 43 | 44 | QHeaderView::section:checked { 45 | background-color: transparent; 46 | } 47 | -------------------------------------------------------------------------------- /version.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | ver = "1.8.2" 4 | ver_sp = [num for num in str(ver).split(".")] 5 | 6 | if len(ver) == 3: 7 | ver_alt = f"{ver_sp[0]}, {ver_sp[1]}, 0, 0" 8 | elif len(ver) == 5: 9 | ver_alt = f"{ver_sp[0]}, {ver_sp[1]}, {ver_sp[2]}, 0" 10 | 11 | 12 | def windowsVersion(): 13 | with open("version.txt", "r") as file: 14 | lines = file.readlines() 15 | 16 | re1 = re.findall(r'\((.*?)\)', lines[6]) 17 | lines[6] = lines[6].replace(re1[0], ver_alt) 18 | lines[7] = lines[7].replace(re1[0], ver_alt) 19 | 20 | re2 = re.findall(r'\'(.*?)\'', lines[30]) 21 | lines[30] = lines[30].replace(re2[1], ver) 22 | lines[33] = lines[33].replace(re2[1], ver) 23 | 24 | with open("version.txt", "w") as file: 25 | file.writelines(lines) 26 | 27 | 28 | def macVersion(): 29 | with open("build.spec", "r") as file: 30 | lines = file.readlines() 31 | 32 | re1 = re.findall(r'\'(.*?)\'', lines[51]) 33 | lines[51] = lines[51].replace(re1[0], ver) 34 | 35 | with open("build.spec", "w") as file: 36 | file.writelines(lines) 37 | 38 | 39 | def appVersion(): 40 | with open("src/module/version.py", "r") as file: 41 | lines = file.readlines() 42 | 43 | re1 = re.findall(r'\"(.*?)\"', lines[5]) 44 | lines[5] = lines[5].replace(re1[0], ver) 45 | 46 | 47 | with open("src/module/version.py", "w") as file: 48 | file.writelines(lines) 49 | 50 | 51 | windowsVersion() 52 | macVersion() 53 | appVersion() 54 | print(f"版本已更改至{ver}") 55 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | # UTF-8 2 | 3 | VSVersionInfo( 4 | ffi=FixedFileInfo( 5 | # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) 6 | # Set not needed items to zero 0. 7 | filevers=(1, 8, 2, 0), 8 | prodvers=(1, 8, 2, 0), 9 | # Contains a bitmask that specifies the valid bits. 10 | mask=0x3f, 11 | # Contains a bitmask that specifies the Boolean attributes of the file. 12 | flags=0x0, 13 | # The operating system for which this file was designed. 14 | # 0x4 - NT and there is no need to change it. 15 | OS=0x40004, 16 | # The general type of file. 17 | # 0x1 - the file is an application. 18 | fileType=0x1, 19 | # The function of the file. 20 | # 0x0 - the function is not defined for this fileType 21 | subtype=0x0, 22 | # Creation date and time stamp. 23 | date=(0, 0) 24 | ), 25 | kids=[ 26 | StringFileInfo( 27 | [ 28 | StringTable( 29 | u'080404b0', 30 | [StringStruct(u'FileDescription', u'SubtitleRenamer'), 31 | StringStruct(u'FileVersion', u'1.8.2'), 32 | StringStruct(u'LegalCopyright', u'Copyright (C) 2023 NuthX'), 33 | StringStruct(u'ProductName', u'SubtitleRenamer'), 34 | StringStruct(u'ProductVersion', u'1.8.2')]) 35 | ]), 36 | VarFileInfo([VarStruct(u'Translation', [2052, 1200])]) 37 | ] 38 | ) --------------------------------------------------------------------------------