Skip to content

Instantly share code, notes, and snippets.

@paravar
Created September 24, 2017 13:09
Show Gist options
  • Save paravar/3aab49879f7a251018876bebd6fc1d95 to your computer and use it in GitHub Desktop.
Save paravar/3aab49879f7a251018876bebd6fc1d95 to your computer and use it in GitHub Desktop.
#! /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())
@paravar
Copy link
Author

paravar commented Sep 24, 2017

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 >>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment