Created
November 26, 2013 19:38
-
-
Save varvaruc/7664782 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bin/env python | |
| #Script redenumire subtitrari dupa numele fisierului video | |
| # before https://dl.dropboxusercontent.com/u/69732156/before.png | |
| # after https://dl.dropboxusercontent.com/u/69732156/after.png | |
| import os | |
| import re | |
| VID_EXTS = ['.avi', '.mkv', '.mp4'] | |
| SUB_EXTS = ['.sub', '.srt'] | |
| files = os.listdir('.') | |
| vids = filter(lambda x : x[-4:] in VID_EXTS, files) | |
| srts = filter(lambda x : x[-4:] in SUB_EXTS, files) | |
| regEx = re.compile('(.*)([sS](\d{1,2})[eE](\d{1,2}))|((\d{1,2})[xX](\d{1,2}))(.*)\.\w{3}') | |
| for vid in vids: | |
| vidMatch = regEx.search(vid) | |
| season_vid = vidMatch.group(3) | |
| episode_vid = vidMatch.group(4) | |
| for srt in srts: | |
| srtMatch = regEx.search(srt) | |
| season_srt = srtMatch.group(6) | |
| episode_srt = srtMatch.group(7) | |
| if season_srt == season_vid and episode_srt == episode_vid: | |
| new_name = vid[:-4] + srt[-4:] | |
| print srt, "->", new_name | |
| os.rename(srt, new_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment