├── .gitattributes ├── README.md ├── SrtSearch_1.6.exe ├── subtitles_search.ftc ├── 使用说明.docx ├── 度盘链接.txt ├── 源代码 ├── SrtSearch_1.6.py └── Srt_initial_v15.py ├── 点击设置字幕匹配软件配置.ini └── 软件声明_必读.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # subtitles_search 2 | 3 | 声明: 4 | 5 | 1. 本项目由abc2020个人开发,旨在学习 Python 语言,提高编程水平。本项目的所有代码, 6 | 程序,工具仅用于技术、学术交流,严禁用于商业和其他盈利目的,产生的一切后果由用户自行承担! 7 | 8 | 2. 请自觉遵守当地法律法规,产生的一切后果由用户自行承担。 9 | 10 | 3. 本项目仅仅是工具,不提供任何淫秽,色情的资源下载,用此工具产生的一切后果自行承担! 11 | 12 | 4. 作者保留最终决定权和最终解释权。 13 | 14 | 5. 不接受任何赞助 15 | 16 | 6. 下载之后请在24小时之内删除安装包以及软件 17 | 18 | 7. 禁止在中国大陆内任何社交平台或论坛转载 19 | 20 | 有问题请截图发邮箱 **abc2020gg@gmail.com** 21 | 22 | **使用说明:将字幕匹配到你的电影文件夹中方便使用** 23 | 24 | **具体说明请看 使用说明.docx** 25 | 26 | **现在该软件已经开源** -------------------------------------------------------------------------------- /SrtSearch_1.6.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abcabc2020/subtitles_search/fd4a38e520d2a89d499631ba062fbc0b83e82d81/SrtSearch_1.6.exe -------------------------------------------------------------------------------- /subtitles_search.ftc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abcabc2020/subtitles_search/fd4a38e520d2a89d499631ba062fbc0b83e82d81/subtitles_search.ftc -------------------------------------------------------------------------------- /使用说明.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abcabc2020/subtitles_search/fd4a38e520d2a89d499631ba062fbc0b83e82d81/使用说明.docx -------------------------------------------------------------------------------- /度盘链接.txt: -------------------------------------------------------------------------------- 1 | 链接:https://pan.baidu.com/s/1aZNNGO4sIjfpZP2o84xasg 2 | 提取码:2s89 3 | 密码:abc2020 4 | 扩展名改成zip解压,请勿在线解压!· -------------------------------------------------------------------------------- /源代码/SrtSearch_1.6.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import pandas as pd 3 | import time 4 | import re 5 | import sys 6 | import os 7 | from queue import Queue 8 | import time 9 | import xml.etree.ElementTree as ET 10 | import configparser 11 | import Srt_initial_v15 12 | import win32file 13 | import shutil 14 | import tkinter as tk 15 | from tkinter import filedialog 16 | ###################################################### 17 | print('作者:abc2020,SrtSearch_v1.5 如果有问题请发邮箱') 18 | print('注意:使用notepad++编辑配置文件!') 19 | print("请确认你的 '点击设置字幕匹配软件配置.ini'文件配置选项!按输入数字 1 继续:") 20 | strn=input("请输入:"); 21 | if int(strn)!=1: 22 | print('看来你还没有准备好,程序结束。') 23 | os.system('pause') 24 | sys.exit(1) 25 | ###################################################### 26 | 27 | #Filepath = filedialog.askopenfilename() #获得选择好的文件 28 | 29 | #StartNum=int (config.get("爬取设置","开始页面(最小为1)")) 30 | Consider_done=1 #考虑之前汉化过的问题 31 | #CsvPath=r'./98_Data/Csv_data/98CTest.csv' 32 | #FilePath=[] 33 | SrtPath=[] 34 | #txtPath=r'./transformjournal.txt' 35 | AllFileName=Queue()#记录更改文件名的 36 | localtime = time.localtime(time.time()) 37 | #dirnameC=0 38 | write1=0 39 | FinishDirName='分配完成' 40 | SrtData = pd.DataFrame(columns=['Code', '字幕路径']) 41 | Log=pd.DataFrame(columns=['Code', '字幕匹配说明','是否有匹配字幕','匹配字幕路径','匹配字幕数','影片路径']) 42 | #movieData=pd.DataFrame(columns=['Code', '影片路径']) 43 | movieData=Queue() 44 | #print ("本地时间为 :", localtime) 45 | moviepat='\\.mp4|\\.avi|\\.wmv|\\.mkv|\\.rmvb' 46 | makedir=0 47 | finishMovieDir='' 48 | movieMovie=1 49 | cmode='move' 50 | def configpathdeal(apath): 51 | if apath == '': 52 | print('待处理列表为空!程序退出!') 53 | os.system('pause') 54 | sys.exit(1) 55 | fp = re.split('[,,]', apath) # 多个分隔符,处理中文逗号,, 56 | for i in range(len(fp)): 57 | fp[i] = fp[i].strip() # 去空格 58 | return fp 59 | if not os.path.isfile('点击设置字幕匹配软件配置.ini'): 60 | print('点击设置字幕匹配软件配置.ini not exists!') 61 | Srt_initial_v15.inic() 62 | #os.system("TR_initial_config.exe") 63 | print('new 点击设置字幕匹配软件配置.ini!') 64 | config=configparser.ConfigParser() 65 | config.read('点击设置字幕匹配软件配置.ini',encoding='utf-8') 66 | #Consider_done=1 if config.get("程序设置","是否考虑以前汉化标识")=='是' else 0 67 | #Apath=config.get("路径设置","待处理文件路径(逗号隔开)") 68 | Spath=config.get("字幕文件库设置","字幕文件文件夹(逗号隔开)") 69 | SrtPath=configpathdeal(Spath) 70 | #FilePath=configpathdeal(Apath) 71 | cmode='copy' if config.get("程序设置","字幕是否拷贝(填否则进行剪切移动)")=='是' else 'move' 72 | Srtpat=config.get("程序设置","需要字幕后缀(逗号隔开)")#ass、srt、smi、ssa、sub 73 | if Srtpat=='': 74 | print('你的识别格式为空,将以默认的.srt格式识别,是否继续?按输入数字 1 继续:') 75 | strn = input("请输入:"); 76 | if int(strn) != 1: 77 | print('看来你还没有准备好,程序结束。') 78 | os.system('pause') 79 | sys.exit(1) 80 | Srtpat='\\.srt' 81 | 82 | else: 83 | Srtpat=re.split('[,,]',Srtpat) 84 | for i in range(len(Srtpat)): 85 | Srtpat[i]=Srtpat[i].strip() 86 | if not re.search('\.',Srtpat[i]): 87 | print("错误!识别影片后缀模板没有'.'!自动添加'.'!") 88 | Srtpat[i]='.'+Srtpat[i] 89 | Srtpat[i]='\\'+Srtpat[i] 90 | Srtpat="|".join(Srtpat) 91 | #CsvPath=config.get("程序设置","程序使用数据库路径") 92 | #dirnameC=1 if config.get("程序设置","是否更改上一层文件目录名字(需要保证一个文件夹下一个视频)")=='是' else 0 93 | makedir=1 if config.get("程序设置","是否为影片建立单独文件夹")=='是' else 0 94 | ###################################################### 95 | """ 96 | try: 97 | Data=pd.read_csv(CsvPath,encoding = 'utf_8_sig') 98 | except Exception as e: 99 | print('Wrong at read data in Pandas!') 100 | os.system('pause') 101 | sys.exit(1) 102 | print('import data success!') 103 | """ 104 | def FindMovFiles(path1):#递归找到所有文件 105 | #print('读入影片文件路径') 106 | abspath=path1 107 | abspath = os.path.abspath(path1) 108 | filelist = os.listdir(abspath) 109 | #total_num = len(filelist) 110 | for file in filelist: 111 | filepath=os.path.join(abspath,file) 112 | if os.path.isdir(filepath): 113 | if os.path.split(filepath)[1]!=FinishDirName: 114 | FindMovFiles(filepath) 115 | else: 116 | ext=os.path.splitext(file)[1] 117 | if re.search(moviepat,ext): 118 | code=CodeManifest(file) 119 | if code !='': 120 | ChineseS = '-c|-C|㊥' 121 | chinese = '' 122 | if re.search(ChineseS, file): # 是否中文 123 | chinese = '是' 124 | else: 125 | chinese = '否' 126 | i,splist=srtSearch(code) 127 | d=[code,filepath,i,splist,chinese]#番号,电影路径,字幕数量,字幕列表,是否中文 128 | movieData.put(d) 129 | 130 | #movieData=movieData.append({'Code':code,'影片路径':filepath},ignore_index=True) 131 | def FindSrtFiles(path1):#递归找到所有文件 132 | print('读入字幕文件路径') 133 | abspath=path1 134 | abspath = os.path.abspath(path1) 135 | filelist = os.listdir(abspath) 136 | #total_num = len(filelist) 137 | global SrtData 138 | for file in filelist: 139 | filepath=os.path.join(abspath,file) 140 | if os.path.isdir(filepath): 141 | if os.path.split(filepath)[1]!=FinishDirName: 142 | FindSrtFiles(filepath) 143 | else: 144 | ext=os.path.splitext(file)[1] 145 | bb=re.search(Srtpat,ext) 146 | if bb: 147 | code=CodeManifest(file) 148 | if code !='': 149 | SrtData=SrtData.append({'Code':code,'字幕路径':filepath},ignore_index=True) 150 | def srtSearch(code): 151 | #data2 = data.loc[data['Code'] == 'HND-792'].reset_index(drop=True, inplace=False).at[0, 'Title'] 152 | data_ten=SrtData.loc[SrtData['Code']==code] 153 | i=len(data_ten.index) 154 | spathlist=[] 155 | if i==0: 156 | print('dont find this code!') 157 | return 0,[] 158 | for ii in range(i): 159 | spathlist.append(data_ten['字幕路径'].iloc[ii]) 160 | return i,spathlist 161 | def CodeManifest(oldname): 162 | if oldname.find('-cd1')!=-1 or oldname.find('-cd2')!=-1: 163 | return '' 164 | code=re.search("[a-zA-Z]{2,5}[-_]?\d{2,4}",oldname)#提取番号 165 | if code: 166 | code=code.group() 167 | code=code.upper()#全部大写 168 | code=re.sub("[-_]",'',code) 169 | else: 170 | print("在{}匹配不到番号!".format(oldname)) 171 | return ''#普通电影 172 | return code 173 | def checkSrt(path1,mcode):#检查文件夹中是否已经存在字幕 174 | print('检查电影番号:{} 的文件夹中是否有对应字幕'.format(mcode)) 175 | abspath = path1 176 | abspath = os.path.abspath(path1) 177 | filelist = os.listdir(abspath) 178 | for file in filelist: 179 | filepath = os.path.join(abspath, file) 180 | if os.path.isdir(filepath): 181 | flag,path=checkSrt(filepath,mcode) 182 | if flag==1: 183 | return flag,path 184 | else: 185 | ext = os.path.splitext(file)[1] 186 | if re.search(Srtpat, ext): 187 | code = CodeManifest(file) 188 | if code != '': 189 | if code==mcode: 190 | return 1,filepath 191 | return 0,'' 192 | def checkMov(path1):#看看文件夹中是否只有一部影片 193 | # print('读入影片文件路径') 194 | abspath = path1 195 | abspath = os.path.abspath(path1) 196 | filelist = os.listdir(abspath) 197 | # total_num = len(filelist) 198 | n=0 199 | for file in filelist: 200 | filepath = os.path.join(abspath, file) 201 | if os.path.isdir(filepath): 202 | d=checkMov(filepath) 203 | n=n+d 204 | else: 205 | ext = os.path.splitext(file)[1] 206 | if re.search(moviepat, ext): 207 | code = CodeManifest(file) 208 | if code != '': 209 | n=n+1 210 | return n 211 | # movieData=movieData.append({'Code':code,'影片路径':filepath},ignore_index=True) 212 | def writeSrtTxt(txtpath,srtlist,code,nowsrtpath): 213 | with open(txtpath, 'a+', encoding='utf-8')as f: 214 | f.write('****************{} 任务****************\n'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 215 | f.write('{}:现有字幕原路径{}:'.format(code,nowsrtpath)) 216 | f.write('\n总字幕路径:\n') 217 | for i in srtlist: 218 | f.write(i) 219 | f.write('\n') 220 | 221 | def chooseSrt():#字幕分配处理 222 | global Log 223 | while not movieData.empty(): 224 | l=movieData.get() 225 | code=l[0] 226 | mpath=l[1] 227 | num=l[2] 228 | spath=l[3] 229 | c=l[4] 230 | srtpath='-' 231 | srtmatch='是' if num>0 else '否' 232 | old=os.path.split(mpath) 233 | name=os.path.split(os.path.splitext(mpath)[0])[1] 234 | dirpath=old[0] 235 | attach='' 236 | movsum=0 237 | if c=='是': 238 | print(code,'已经是中文字幕影片!') 239 | attach='已经是中文字幕影片,有标识符' 240 | else: 241 | flag, oldsrtpath = checkSrt(dirpath, code) 242 | if flag == 1: 243 | print('找到原有字幕') 244 | attach = '找到原有字幕' 245 | srtpath=oldsrtpath 246 | if num!=0 and write1==1: 247 | tp=os.path.join(dirpath,'字幕列表(有其他字幕).txt') 248 | writeSrtTxt(tp,spath,code,srtpath) 249 | else: 250 | if num==0: 251 | attach='未找到字幕' 252 | else: 253 | #####移动字幕### 254 | if makedir == 1: 255 | movsum=checkMov(dirpath) 256 | if movsum !=1: 257 | newdirpath = os.path.join(dirpath, code) 258 | if not os.path.exists(newdirpath): 259 | os.mkdir(newdirpath) 260 | dirpath = newdirpath 261 | shutil.move(mpath, dirpath) 262 | mpath = os.path.join(dirpath, old[1]) 263 | attach = '匹配到字幕' 264 | #srcpath=spath[0] 265 | srtpath=spath[0] 266 | srtext=os.path.splitext(srtpath)[1] 267 | #srtname=os.path.split(srcpath)[1] 268 | #dstpath=os.path.join(dirpath,name+srtext) 269 | #shutil.copyfile(srcpath,dstpath) 270 | dstpath=dirpath 271 | try: 272 | shutil.copy2(srtpath,dstpath) 273 | except Exception as e: 274 | with open(os.path.join(dstpath,'匹配失败可能是有同名影片.txt'), 'a+', encoding='utf-8')as f: 275 | f.close() 276 | Log = Log.append( 277 | {'Code': code, '是否有匹配字幕': srtmatch, '影片路径': mpath, '匹配字幕数': num, '匹配字幕路径': srtpath, 278 | '字幕匹配说明': '匹配到字幕但是因为字幕路径改变失败'}, ignore_index=True) 279 | continue 280 | #srtpath=os.path.join(dirpath,srtname) 281 | ######移动字幕文件夹#### 282 | ss=os.path.split(srtpath) 283 | if re.search("abc2020自提",ss[1])or re.search("自提",ss[1]) : 284 | print('恭喜 找到一个作者本人自提的字幕!') 285 | 286 | else: 287 | finishdir=os.path.join(os.path.dirname(srtpath),FinishDirName) 288 | mode=1 289 | srtpath=srtdirfinish(srtpath, finishdir, cmode, mode) 290 | #srtpath=os.path.join(finishdir,ss[1]) 291 | spath[0] = srtpath 292 | ############# 293 | if movsum==1: 294 | namelist = ['-poster.jpg', '-fanart.jpg', '.nfo'] 295 | for i in namelist: 296 | ip=os.path.join(dirpath,name+i) 297 | if os.path.exists(ip): 298 | os.remove(ip) 299 | if num==1: 300 | tp=os.path.join(dirpath,'字幕列表.txt') 301 | writeSrtTxt(tp, spath, code, srtpath) 302 | else: 303 | tp = os.path.join(dirpath, '字幕列表(有其他字幕).txt') 304 | writeSrtTxt(tp, spath, code, srtpath) 305 | 306 | 307 | 308 | # Log=pd.DataFrame(columns=['Code', '是否有匹配字幕','匹配字幕路径','匹配字幕数','影片路径']) 309 | Log=Log.append({'Code':code,'是否有匹配字幕':srtmatch,'影片路径':mpath,'匹配字幕数':num,'匹配字幕路径':srtpath,'字幕匹配说明':attach},ignore_index=True) 310 | def srtdirfinish(fpath,dstdir,str,mode): 311 | if not os.path.exists(dstdir): 312 | os.mkdir(dstdir) 313 | #dirpath=os.path.dirname(fpath) 314 | if str=='move': 315 | n=shutil.move(fpath,dstdir) 316 | elif str=='copy':###有问题 317 | if mode==1:#无单独文件夹字幕 318 | n=shutil.copy2(fpath,dstdir) 319 | elif mode==2:#自提字幕#需要在下面新建目录 320 | #dirpath = os.path.dirname(fpath) 321 | srtdirname=os.path.split(fpath)[1] 322 | dstdir=os.path.join(dstdir,srtdirname) 323 | try: 324 | n=shutil.copytree(fpath,dstdir) 325 | except Exception as e: 326 | print('目标文件目录已存在') 327 | n=dstdir 328 | return n 329 | for s in SrtPath: 330 | FindSrtFiles(s) 331 | print('读取字幕列表成功') 332 | while True: 333 | '''打开选择文件夹对话框''' 334 | root = tk.Tk() 335 | root.withdraw() 336 | 337 | file_pat = filedialog.askdirectory() # 获得选择好的文件夹 338 | #Filepath = filedialog.askopenfilename() # 获得选择好的文件 339 | finishMovieDir=os.path.join(file_pat,'分配完成') 340 | if makedir==1: 341 | if not os.path.exists(finishMovieDir): 342 | os.mkdir(finishMovieDir) 343 | FindMovFiles(file_pat) 344 | print('文件夹:',file_pat,'读取成功') 345 | chooseSrt() 346 | print('字幕匹配移动完成') 347 | txtpath=os.path.join(file_pat,'字幕匹配日志.csv') 348 | txt2path=os.path.join(file_pat,'成功匹配.csv') 349 | t=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 350 | timeline=[t for x in range(2,len(Log.index)+2)] 351 | Log.insert(loc=0,column='任务时间',value=timeline) 352 | #with open(txtpath, 'a+', encoding='utf-8')as f: 353 | #f.write('****************{} 任务****************\n'.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) 354 | #f.close() 355 | Log.to_csv(txtpath, mode='a', index=False, header=True, encoding='utf_8_sig') 356 | L1= Log.loc[Log['字幕匹配说明']=='匹配到字幕'].reset_index(drop=True,inplace=False) 357 | if L1.empty: 358 | print('{}这个文件夹没有匹配到字幕'.format(file_pat)) 359 | L1.to_csv(txt2path, mode='a', index=False, header=True, encoding='utf_8_sig') 360 | print('日志写入成功') 361 | Log.drop(Log.index, inplace=True) 362 | Log.drop(columns=['任务时间'],inplace=True) 363 | print('字幕匹配完成,详情请查阅文件夹中的 成功匹配.csv 和 字幕替换日志.csv') 364 | print('按任意键继续选择文件夹匹配:') 365 | os.system('pause') 366 | 367 | 368 | 369 | 370 | 371 | -------------------------------------------------------------------------------- /源代码/Srt_initial_v15.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import configparser 3 | import os 4 | def inic(): 5 | cf = configparser.ConfigParser() 6 | cf['字幕文件库设置'] = { 7 | '字幕文件文件夹(逗号隔开)':'' 8 | } 9 | cf['程序设置']={ 10 | '需要字幕后缀(逗号隔开)':'ass,srt,smi,ssa,sub', 11 | '是否为影片建立单独文件夹':'是', 12 | '字幕是否拷贝(填否则进行剪切移动)': '是' 13 | } 14 | f = open('点击设置字幕匹配软件配置.ini', 'w', encoding='utf-8') 15 | cf.write(f) 16 | f.close() 17 | if __name__=="__main__": 18 | inic() -------------------------------------------------------------------------------- /点击设置字幕匹配软件配置.ini: -------------------------------------------------------------------------------- 1 | [字幕文件库设置] 2 | 字幕文件文件夹(逗号隔开) = 3 | 4 | [程序设置] 5 | 需要字幕后缀(逗号隔开) = .ass,.srt,.smi,.ssa,.sub,.vtt 6 | 是否为影片建立单独文件夹 = 是 7 | 字幕是否拷贝(填否则进行剪切移动) = 是 8 | 9 | -------------------------------------------------------------------------------- /软件声明_必读.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abcabc2020/subtitles_search/fd4a38e520d2a89d499631ba062fbc0b83e82d81/软件声明_必读.txt --------------------------------------------------------------------------------