Last active
December 21, 2015 20:29
-
-
Save cnsoft/6361818 to your computer and use it in GitHub Desktop.
#This uitls can copy srt file to destination folder. when i download Lynda.com - iOS SDK Essential Training (2012)
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 | |
| #coding=utf-8 | |
| #This uitls can copy srt file to destination folder. | |
| #you should install python runtime first. python.2.6 is prefered. | |
| # @Atuthor cnsoft 2012-10-05 midnight | |
| import os | |
| import os.path | |
| import shutil | |
| #movroot = "d:\\Lynda.com-Building.and.Monetizing.Game.Apps.for.iOS\\Lynda.com-Building.and.Monetizing.Game.Apps.for.iOS" | |
| #srtroot = "C:\\Users\\cnsoft\\Desktop\\cy_stage2\\train_tools\\Building and Monetizing Game Apps for iOS[SRT]" | |
| movroot= "D:\\temp\\Lynda.com - iOS SDK Essential Training (2012)" | |
| srtroot= "C:\\Users\\cnsoft\\Desktop\\cy_stage2\\train_tools\\iOS SDK Essential Training (2012)[SRT]" | |
| outputs = [] | |
| srtfilelist ={} | |
| def fetchSrts(): | |
| rootdir = srtroot | |
| for parent,dirnames,filenames in os.walk(rootdir): | |
| for file in filenames: | |
| if file.endswith('.srt'): | |
| #srtfilelist.append(parent+os.sep+file) | |
| reskey = getResKey(file) | |
| srtfilelist[reskey] = parent+os.sep+file,file | |
| #print srtfilelist | |
| return srtfilelist | |
| def walkDir(): | |
| rootdir = movroot | |
| nofind = [] | |
| for parent,dirnames,filenames in os.walk(rootdir): | |
| for file in filenames: | |
| if file.endswith('.mov'): #find mov file. | |
| #shutil.copy( parent+os.sep+file , target_dir ) | |
| srtname,old = getSrtName(file) | |
| if srtname is None: | |
| #print 'not find srtfile with key',getResKey(file) ,old | |
| nofind.append(("%s:%s")%(parent,file)) | |
| else: | |
| shutil.copy(srtname,parent) | |
| old = parent+os.sep+ old | |
| new = parent+os.sep+ file[:-4] + '.srt' | |
| if os.path.exists(new): | |
| os.remove(new) | |
| os.rename(old,new) | |
| print 'not find record', nofind | |
| def getResKey(movname): | |
| srtname = movname[:-4] #remove .mov | |
| index0 = srtname.find('.') | |
| if index0 == -1: | |
| index0 = srtname.find(' ') | |
| if index0 == -1: | |
| index0 = 0 | |
| else: | |
| index0 +=1 | |
| srtname = srtname[index0:] | |
| return srtname.capitalize() | |
| def getSrtName(movname): | |
| #to find the srtname. | |
| reskey = getResKey(movname) | |
| if not srtfilelist.has_key(reskey): | |
| reskey = reskey.capitalize() | |
| srtname = srtfilelist.get(reskey,(None,None)) #srtname + ".srt" | |
| #todo 80% word same. is also taken as key.. | |
| return srtname | |
| if __name__ == "__main__": | |
| fetchSrts() | |
| walkDir() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment