1

Sorry if this question is too basic, I've been searching python and regex and haven't found exactly what I need.

I have a bunch of television show files with names that end in S01EXX like the following:

filename.S01E01.mkv
filename.S01E02.mkv
filename.S01E03.mkv

Each of this is actually a double episode, so the above three should be named with the form:

filename.S01E01-E02.mkv
filename.S01E03-E04.mkv
filename.S01E05-E06.mkv

so each should be the episode number times 2 minus 1, and the episode number times 2. I know how to rename and split with python, I just don't know how to go about parsing out the episode numbers and how deal with the leading zero that will disappear when we get to 2 digit episode numbers.

Any help is much appreciated!

1 Answer 1

1

If the position of the episode number is constant, you can extract it using a slice:

e = int(filename[-6:-4])
new_filename = '%s%02d-E%02d%s' % (filename[:-6], e*2-1, e*2, filename[-4:])
Sign up to request clarification or add additional context in comments.

1 Comment

Filename slicing, combined with regex pattern matching, saved me a couple hours of labor today. Good combo!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.