Created
September 24, 2017 13:09
-
-
Save paravar/3aab49879f7a251018876bebd6fc1d95 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/local/bin/python3 | |
""" This script is to rename the files | |
"Friends Season ## Episode ## - *.avi" | |
to | |
"Friends S##E## - *.avi" | |
Example: | |
This: | |
"Friends Season 09 Episode 01 - The One Where No One Proposes.avi" | |
will be changed to: | |
"Friends S09e01 - The One Where No One Proposes.avi" | |
""" | |
import os | |
import shutil | |
import re | |
series_pattern = re.compile(r"""^(.*) #matches everything before 'Season' | |
(Season ) #matches 'Season_' | |
(/d{2}) #matches Season number | |
( Episode ) #matches '_Episode_' | |
(/d{2}) #matches Episode number | |
(.*)$ #matches everything after Episode number | |
""", re.VERBOSE) | |
sample_string = "Friends Season 09 Episode 01 - The One Where No One Proposes\ | |
.avi" | |
result = series_pattern.search(sample_string) | |
print(result.group()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
16:56 ~/python/lab/ali_pracitices/batch_rename >>./batch_rename.py
Traceback (most recent call last):
File "./batch_rename.py", line 29, in
print(result.group())
AttributeError: 'NoneType' object has no attribute 'group'
17:04 ~/python/lab/ali_pracitices/batch_rename >>