├── LICENSE ├── README.md ├── manage_av.py └── rerename.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 ximikang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AV_manage 2 | 3 | > 为了格式化小姐姐的番号,去掉没有用的名词,只保留番号 4 | 5 | 6 | 将脚本文件放到小姐姐目录下,运行就可以使用。 7 | 8 | `rerename.py`可以撤回所有操作 9 | 10 | 11 | 接下来可能会做一个可视化界面吧,更好的管理 12 | -------------------------------------------------------------------------------- /manage_av.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import json 4 | 5 | def getnewname(oldname): 6 | try: 7 | [uppath, filename] = os.path.split(oldname) 8 | [filename, exname] = os.path.splitext(filename) 9 | p = re.compile(r"([a-zA-Z]{3,4})(-|00|_|)([0-9]{3})((-|_|)[CcRr]){0,}") 10 | m = p.search(filename) 11 | if m == None: 12 | return oldname 13 | else: 14 | AVname = str.upper(m.group(1)) 15 | AVindex = m.group(3) 16 | AVChineseSub = m.group(4) 17 | if(AVChineseSub): 18 | newname = AVname+'-'+AVindex+'-'+AVChineseSub+exname 19 | else: 20 | newname = AVname+'-'+AVindex+exname 21 | newname = os.path.join(uppath, newname) 22 | return newname 23 | except: 24 | print('AVre error') 25 | return oldname 26 | 27 | def getallfile(path): 28 | def _getallfile(path,l): 29 | its = os.listdir(path) 30 | for i in its: 31 | if os.path.isfile(os.path.join(path,i)): 32 | l.append(os.path.join(path,i)) 33 | else: 34 | _getallfile(os.path.join(path,i),l) 35 | file = [] 36 | _getallfile(path,file) 37 | return file 38 | 39 | def moveCname(namelog): 40 | def nameadd(name,add): 41 | upname, exname = os.path.splitext(name) 42 | name = upname+'-'+str(add)+exname 43 | return name 44 | newnamelist = [x[1] for x in namelog] 45 | cname = {} 46 | for index,newname in enumerate(newnamelist): 47 | if(newnamelist.count(newname) == 1): 48 | pass 49 | else: 50 | if newname in cname.keys(): 51 | pass 52 | else: 53 | cname[newname] = [] 54 | for i,n in enumerate(newnamelist): 55 | if(newname == n): 56 | cname[newname].append(i) 57 | for basefilename in cname.keys(): 58 | for ifile in range(len(cname[basefilename])): 59 | namebeadded = nameadd(basefilename,ifile) 60 | newnamelist[cname[basefilename][ifile]] = namebeadded 61 | for index, newname in enumerate(newnamelist): 62 | namelog[index][1] = newname 63 | return namelog 64 | 65 | def rename(logs): 66 | for index,log in enumerate(logs): 67 | try: 68 | os.renames(log[0],log[1]) 69 | except: 70 | print('ERROR:',log) 71 | 72 | def savejson(log): 73 | logjson = json.dumps(log) 74 | with open(os.path.join(os.getcwd(),'log.josn'),'w',encoding = 'utf-8') as f: 75 | f.write(logjson) 76 | if __name__ == "__main__": 77 | path = os.getcwd() 78 | allfile = getallfile(os.getcwd()) 79 | log = [] 80 | for oldname in allfile: 81 | houzhui = os.path.splitext(oldname)[1] 82 | if(houzhui in [".mp4",".avi",".wmv",".rmvb"]): 83 | newname = getnewname(str(oldname)) 84 | if(newname != oldname): 85 | log.append([oldname,newname]) 86 | log = moveCname(log) 87 | rename(log) 88 | savejson(log) -------------------------------------------------------------------------------- /rerename.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | def readjson(): 4 | #logjson = json.dumps(log) 5 | with open(os.path.join(os.getcwd(),'log.josn'),'r',encoding = 'utf-8') as f: 6 | logjson = f.read() 7 | return logjson 8 | 9 | def rerename(logs): 10 | for index,log in enumerate(logs): 11 | try: 12 | os.renames(log[1],log[0]) 13 | except: 14 | print('ERROR:',log) 15 | if __name__ == "__main__": 16 | logjson = readjson() 17 | log = json.loads(logjson) 18 | rerename(log) 19 | --------------------------------------------------------------------------------