Skip to content

Instantly share code, notes, and snippets.

@MechaDragonX
Last active March 8, 2025 08:07
Show Gist options
  • Select an option

  • Save MechaDragonX/e77801ddc466d139711408c96d9ca797 to your computer and use it in GitHub Desktop.

Select an option

Save MechaDragonX/e77801ddc466d139711408c96d9ca797 to your computer and use it in GitHub Desktop.
Messy code to rename a folder of subtitles files from an extrernal source with names akin to the video files in it so they play automatically in MPV or VLC. I have to do this often since I download Japaense language subtitles from Netflix or other sources to match western created rips of anime and movies. The parts of the name cannot be obtained…
import os
dir = os.path.dirname(os.path.realpath(__file__))
print(dir)
before_number_name = input('Please provide file name before number.\nExample: Given "[Sokudo] The Melancholy of Haruhi Suzumiya 2006 - 01 [1080p BD][AV1][dual audio]",\npaste "[Sokudo] The Melancholy of Haruhi Suzumiya 2006 - ": ')
print()
after_number_name = input('Please provide file name after number.\nExample: Given "[Sokudo] The Melancholy of Haruhi Suzumiya 2006 - 01 [1080p BD][AV1][dual audio]",\npaste " [1080p BD][AV1][dual audio]": ')
print()
sub_file_type = input('Type "1" for SRT. Type "2" for ASS: ')
ext = ''
if sub_file_type == '1':
ext = '.srt'
elif sub_file_type == '2':
ext = '.ass'
else:
print('Please type 1 or 2 next time')
exit(1)
print()
i = 1
for file in os.listdir(dir):
filename = os.fsdecode(file)
if filename.endswith(ext):
os.rename(f'{dir}/{filename}', f'{dir}/{before_number_name}{i:02d}{after_number_name}.ja{ext}')
i += 1
print('Complete!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment