Skip to content

Instantly share code, notes, and snippets.

@astrograzl
Last active March 16, 2018 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrograzl/b052ef01f6636764fcf36ebb5842f2af to your computer and use it in GitHub Desktop.
Save astrograzl/b052ef01f6636764fcf36ebb5842f2af to your computer and use it in GitHub Desktop.
Rename subtitle files with respekt to movie filenames.
#!python
# coding: utf-8
"""Rename subtitle files with respekt to movie filenames.
$ python reset.py "Movies*.mkv" "Subtitles*.srt"
The quotation marks are important to prohibit shell expanse of the filenames
mask. It is expected, that the files will be sorted in the same right order.
"""
import os
import sys
import glob
assert len(sys.argv) == 3
MOVIES = sorted(glob.glob(sys.argv[1]))
SUBTIT = sorted(glob.glob(sys.argv[2]))
assert len(MOVIES) == len(SUBTIT)
for mov, sub in zip(MOVIES, SUBTIT):
new = mov[:-3] + sub[-3:]
os.rename(sub, new)
print("{}\t==>\t{}".format(sub, new))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment