Last active
April 27, 2023 03:19
-
-
Save anthony1x6000/6dd1eb384f6f5e97785afaf42d92f637 to your computer and use it in GitHub Desktop.
Removes anime sub file naming watermarks so kodi isnt broken
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import keyboard | |
| import re | |
| from time import sleep | |
| import pyperclip | |
| print(""" | |
| Sometimes subtitle teams put their watermark before the title of a show you watch. Kodi is sometimes confused by this. | |
| This script it meant to eliminate those problems by removing the bit of square bracketed text before a show title. | |
| For example, | |
| NichijouE23.srt | |
| will become: NichijouE23.srt | |
| It also removes version naming schemes because Kodi doesn't like that either. | |
| This script renames all files, not just subtitles. | |
| Usage: | |
| - Have this window selected first and then your other window second so the program can properly swap between both windows with alt+tab. | |
| - Select top most file. | |
| - Press F9 to execute once. | |
| - Press F10 to specify a loop count and then execute. You'll probably just want to enter the number of files that you want to remove the brackets from. | |
| """) | |
| def analyze_text(text): | |
| print("{:<10} {}".format("Text:", text)) | |
| new_text = re.sub(r'\[[^\]]*\]', '', text) | |
| new_text = re.sub(r'(\d)v\d', r'\1', new_text) | |
| print("{:<10} {}".format("New text:", new_text)) | |
| return new_text | |
| def execute_keystrokes(home_skip): | |
| sleepTime = 0.09 | |
| keyboard.press_and_release('f2') | |
| sleep(sleepTime) | |
| keyboard.press_and_release('ctrl+a') | |
| keyboard.press_and_release('ctrl+c') | |
| sleep(sleepTime) | |
| text = pyperclip.paste() | |
| new_text = analyze_text(text) | |
| pyperclip.copy(new_text) | |
| keyboard.press_and_release('ctrl+v') | |
| sleep(sleepTime) | |
| keyboard.press_and_release('enter') | |
| sleep(sleepTime) | |
| keyboard.press_and_release('home') | |
| sleep(sleepTime) | |
| for i in range(home_skip): | |
| keyboard.press_and_release('down') | |
| sleep(sleepTime) | |
| def execute_keystrokes_multiple_times(): | |
| home_skip = 0 | |
| keyboard.press_and_release('alt+tab') | |
| num_times = int(input("Enter repetition count: ")) + 1 | |
| home_skip = int(input("Enter home skip count (number of folders at top of file list): ")) + 1 | |
| keyboard.press_and_release('alt+tab') | |
| sleep(0.2) | |
| for i in range(num_times): | |
| execute_keystrokes(home_skip) | |
| print("Done.") | |
| def execute_keystrokes_init(): | |
| home_skip = 1 | |
| execute_keystrokes(home_skip) | |
| keyboard.add_hotkey('f9', execute_keystrokes_init) | |
| keyboard.add_hotkey('f10', execute_keystrokes_multiple_times) | |
| keyboard.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment