Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Last active March 9, 2023 00:28
Show Gist options
  • Save cansadadeserfeliz/503cb2697110510536fa934e0b8234fc to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/503cb2697110510536fa934e0b8234fc to your computer and use it in GitHub Desktop.
Python Subtitles Renamer
import os
import re
import sys
import argparse
renaming_enabled = False
dir_path = os.path.dirname(os.path.realpath(__file__))
def rename_file(file_name, new_file_name):
if renaming_enabled:
print('\t\t', 'done')
os.rename(file_name, new_file_name)
def rename_the_nanny():
print('rename The Nanny')
for file_name in os.listdir(dir_path):
match = re.match('The Nanny - S0(\d)E(\d\d).*\.eng\.srt', file_name)
if match:
season, episode = match.groups()
new_file_name = f'The.Nanny.S0{season}.E{episode}.srt'
print('\t', file_name, 'will be renamed to', new_file_name)
rename_file(file_name, new_file_name)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--rename', action=argparse.BooleanOptionalAction, default=False, required=False)
args = parser.parse_args()
renaming_enabled = args.rename
print('rename?', renaming_enabled)
print('current path:', dir_path)
rename_the_nanny()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment