From da3415ee83dcd6eae77867a52b2aa995877296fc Mon Sep 17 00:00:00 2001 From: Abcuders Date: Sun, 16 Jul 2023 06:17:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ETMDBApi=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoAnimeMv.py | 99 +++++++++++++++++++++++------------------ Client.py | 8 ++-- DOCS.md | 8 ++-- README.md | 11 ++++- TutorialsforDummies2.md | 7 ++- config.ini.Template | 1 + 6 files changed, 81 insertions(+), 53 deletions(-) diff --git a/AutoAnimeMv.py b/AutoAnimeMv.py index 5ec4d1f..949dc9b 100644 --- a/AutoAnimeMv.py +++ b/AutoAnimeMv.py @@ -16,10 +16,11 @@ def Start_PATH():# 初始化 # 版本 数据库缓存 Api数据缓存 Log数据集 分隔符 - global Versions,AimeListCache,BgmAPIDataCache,LogData,Separator,Proxy,TgBotMsgData,PyPath - Versions = '2.5.3' + global Versions,AimeListCache,BgmAPIDataCache,TMDBAPIDataCache,LogData,Separator,Proxy,TgBotMsgData,PyPath + Versions = '2.6.0' AimeListCache = None BgmAPIDataCache = {} + TMDBAPIDataCache = {} LogData = f'\n\n[{strftime("%Y-%m-%d %H:%M:%S",localtime(time()))}] INFO: Running....' Separator = '\\' if name == 'nt' else '/' TgBotMsgData = '' @@ -87,16 +88,16 @@ def Processing_Main(LorT):# 核心处理 break SE,EP,RAWSE,RAWEP,RAWName = flag ASSList = Auxiliary_IDEASS(RAWName,RAWSE,RAWEP,LorT[1]) - BgmApiName = Auxiliary_BgmApi(RAWName) - Sorting_Mv(File,RAWName,SE,EP,ASSList,BgmApiName) + ApiName = Auxiliary_Api(RAWName) + Sorting_Mv(File,RAWName,SE,EP,ASSList,ApiName) else:# 唯一有效的文件列表 for File in LorT: flag = Processing_Identification(File) if flag == None: break SE,EP,RAWSE,RAWEP,RAWName = flag - BgmApiName = Auxiliary_BgmApi(RAWName) - Sorting_Mv(File,RAWName,SE,EP,None,BgmApiName) + ApiName = Auxiliary_Api(RAWName) + Sorting_Mv(File,RAWName,SE,EP,None,ApiName) def Processing_Identification(File:str):# 识别 AnimeFileCheckFlag = Auxiliary_AnimeFileCheck(File) @@ -121,7 +122,7 @@ def Processing_Identification(File:str):# 识别 Auxiliary_Log(f'当前文件属于{AnimeFileCheckFlag},跳过处理','INFO') # Sorting 进行整理工作 -def Sorting_Mv(FileName,RAWName,SE,EP,ASSList,BgmApiName):# 文件处理 +def Sorting_Mv(FileName,RAWName,SE,EP,ASSList,ApiName):# 文件处理 def FileML(src,dst): global TgBotMsgData if USELINK == True: @@ -142,7 +143,7 @@ def FileML(src,dst): move(src,dst) Auxiliary_Log(f'Move-{dst} << {src}') TgBotMsgData = TgBotMsgData + (f'Move-{src} << {dst}\n') - NewDir = f'{Path}{Separator}{CategoryName}{Separator}{BgmApiName}{Separator}Season{SE}{Separator}' if BgmApiName != None else f'{Path}{Separator}{CategoryName}{Separator}{RAWName}{Separator}Season{SE}{Separator}' + NewDir = f'{Path}{Separator}{CategoryName}{Separator}{ApiName}{Separator}Season{SE}{Separator}' if ApiName != None else f'{Path}{Separator}{CategoryName}{Separator}{RAWName}{Separator}Season{SE}{Separator}' NewName = f'S{SE}E{EP}' if path.exists(NewDir) == False: makedirs(NewDir) @@ -187,6 +188,7 @@ def Auxiliary_READConfig():# 读取外置Config.ini文件并更新 HTTPSPROXY = '' # Https代理 ALLPROXY = '' # 全部代理 USEBGMAPI = True # 使用BgmApi + USETMDBAPI = True #使用TMDBApi USELINK = False # 使用硬链接开关 LINKFAILSUSEMOVEFLAGS = False #硬链接失败时使用MOVE PRINTLOGFLAG = False # 打印log开关 @@ -386,6 +388,8 @@ def Auxiliary_PROXY(): # 代理 def Auxiliary_Http(Url,flag='GET',json=None):# 网络 headers = {'User-Agent':f'Abcuders/AutoAnimeMv/{Versions}(https://github.com/Abcuders/AutoAnimeMv)'} + if 'themoviedb' in Url: + headers['Authorization'] = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI0MjkxYzA0NGYyZTNmMThhYzQ3NzNjNzU1YzM3NzA5OSIsInN1YiI6IjY0MjZlMTg1YTNlNGJhMDExMTQ5OGI2MSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.Q0Rn4QdnCelhzozE07jgUQwJFzdJrLXGhaSBphnzYuQ" try: if flag != 'GET': HttpData = post(Url,json,headers=headers) @@ -412,50 +416,59 @@ def Auxiliary_Updata():# 更新 else: Auxiliary_Exit('更新数据存在问题') -def Auxiliary_BgmApi(Name):# BgmApi相关,返回一个标准的中文名称 - global USEBGMAPI,BgmAPIDataCache - if USEBGMAPI == True: - if Name not in BgmAPIDataCache: - def NameSplit(Name): - if findall(r'[\u4e00-\u9fa5]+',Name,flags=I) != []: # 获取匹配到的汉字 - NameList = findall(r'[\u4e00-\u9fa5]+',Name,flags=I) - else:# 匹配其他语言 - NameList = Name.split('-') - for i in range(NameList.count('')): - NameList.remove('') - Auxiliary_Log(f'番剧名称分段 待查询的番剧名称列表 >> {NameList}') - return NameList - def BgmApi(Name): +def Auxiliary_Api(Name): + def BgmApi(Name):# BgmApi相关,返回一个标准的中文名称 + global USEBGMAPI,BgmAPIDataCache + if USEBGMAPI == True: + if Name not in BgmAPIDataCache: try: BgmApiData = literal_eval(Auxiliary_Http(f"https://api.bgm.tv/search/subject/{Name}?type=2&responseGroup=small&max_results=1")) except: - Auxiliary_Log(f'BgmApi无法检索到关于 {Name} 内容','WARNING') + Auxiliary_Log(f'BgmApi没有检索到关于 {Name} 内容','WARNING') return None else: - return BgmApiData - - BgmApiData = BgmApi(Name) - if BgmApiData == None: - NameList = NameSplit(Name) - for i in NameList: - BgmApiData = BgmApi(i) - if BgmApiData != None: - break + if 'BgmApiData' != None: + ApiName = unquote(BgmApiData['list'][0]['name_cn'],encoding='UTF-8',errors='replace') + ApiName = sub('第.*?季','',ApiName,flags=I).strip('- []【】 ') + Auxiliary_Log(f'{ApiName} << bgmApi查询结果') + BgmAPIDataCache[Name] = ApiName + return ApiName + else: + return None + else: + Auxiliary_Log(f'{BgmAPIDataCache[Name]} << bgmApi缓存查询结果') + return BgmAPIDataCache[Name] + else: + Auxiliary_Log('没有使用BgmApi进行检索') + return None - if 'BgmApiData' != None: - ApiName = unquote(BgmApiData['list'][0]['name_cn'],encoding='UTF-8',errors='replace') - ApiName = sub('第.*?季','',ApiName,flags=I).strip('- []【】 ') - Auxiliary_Log(f'{ApiName} << bgmApi查询结果') - BgmAPIDataCache[Name] = ApiName - return ApiName + def TMDBApi(Name):# TMDBApi相关,返回一个标准的中文名称 + global USETMDBAPI,TMDBAPIDataCache + if USETMDBAPI == True: + if Name not in TMDBAPIDataCache: + TMDBApiData = literal_eval(Auxiliary_Http(f'https://api.themoviedb.org/3/search/tv?query={Name}&include_adult=true&language=zh&page=1').replace('false','False').replace('true','True')) + if TMDBApiData['results'] != []: + ApiName = TMDBApiData['results'][0]['name'] + ApiName = sub('第.*?季','',ApiName,flags=I).strip('- []【】 ') + Auxiliary_Log(f'{ApiName} << TMDBApi查询结果') + TMDBAPIDataCache[Name] = ApiName + return ApiName + else: + Auxiliary_Log(f'TMDBApi没有检索到关于 {Name} 内容','WARNING') + return None else: - return None + Auxiliary_Log(f'{TMDBAPIDataCache[Name]} << TMDBApi缓存查询结果') + return TMDBAPIDataCache[Name] else: - Auxiliary_Log(f'{BgmAPIDataCache[Name]} << bgmApi缓存查询结果') - return BgmAPIDataCache[Name] + Auxiliary_Log('没有使用TMDBApi进行检索') + return None + + if search(r'[\u4e00-\u9fa5]+',Name,flags=I) != None: # 获取匹配到的汉字 + Name = search(r'[\u4e00-\u9fa5]+',Name,flags=I).group(1) + ApiName = BgmApi(Name) else: - Auxiliary_Log('没有使用BgmApi进行检索') - return None + ApiName = TMDBApi(Name) + return ApiName def Auxiliary_Exit(LogMsg):# 因可预见错误离场 Auxiliary_Log(LogMsg,'EXIT',flag='PRINT') diff --git a/Client.py b/Client.py index f26037e..064e5cd 100644 --- a/Client.py +++ b/Client.py @@ -18,8 +18,8 @@ def QbInit(QbIp,QbPort,QbUserName,QbPassword): VERIFY_WEBUI_CERTIFICATE=False,# 关闭ssl验证 RAISE_NOTIMPLEMENTEDERROR_FOR_UNIMPLEMENTED_API_ENDPOINTS=True,# 无Api功能时引发NotImplementedError ) - QbClient = Client(**QbInfo) try: + QbClient = Client(**QbInfo) QbClient.auth_log_in() except LoginFailed as err: Auxiliary_Exit(f'qb登录失败 >> {err}') @@ -82,6 +82,7 @@ def DistributeClient(Ip,DefaultPort):# 分发端口 while True: try: DClient.sendall(RASEncrypt(TGBOTDEVICESFLAG)) + sleep(3) Data = AESDEncrypt(DClient.recv(1024)) except timeout: Auxiliary_Log('连接超时重试') @@ -203,7 +204,8 @@ def Auxiliary_READConfig(): if 'USERQBAPI' in globals() and USERQBAPI == True: QbClient = QbInit(QBIP,QBPORT,QBUSERNAME,QBPASSWORD) - Auxiliary_Log('QB 已连接') + if 'QbClient' in locals(): + Auxiliary_Log('QB 已连接') while True: try: DistributeData = DistributeClient(Ip,DefaultPort) @@ -218,7 +220,7 @@ def Auxiliary_READConfig(): Auxiliary_Log('不存在config.ini,使用内置变量') if __name__ == '__main__': - Versions = '0.1.1' + Versions = '0.1.2' Ip = '103.101.204.76' #Ip = '127.0.0.1' DefaultPort = 13324 diff --git a/DOCS.md b/DOCS.md index 38ab57f..8053f05 100644 --- a/DOCS.md +++ b/DOCS.md @@ -92,6 +92,7 @@ HTTPPROXY = '' # Http代理 HTTPSPROXY = 'http://192.168.1.1:7890' # Https代理 ALLPROXY = '' # 全部代理 USEBGMAPI = True # 使用BgmApi +USETMDBAPI = True #使用TMDBApi USELINK = True # 使用硬链接开关 LINKFAILSUSEMOVEFLAGS = False #硬链接失败时使用MOVE RMLOGSFLAG = '7' # 日志文件超时删除 @@ -123,7 +124,6 @@ QBPASSWORD = '' # Qb密码 * `RMLOGSFLAG` 配置项是用来控制工具删除保存天数达到和超过 `RMLOGSFLAG` 的值的配置,默认为 7 天,如果您不想删除请设置为 `False` -* `USEBOTFLAG`用来开启TgBot通知的开关 * **注意如果有部分新配置没有解释,那么此配置即是内测功能,您可以来Tg群体验** @@ -154,16 +154,16 @@ QBPASSWORD = '' # Qb密码 [2023-06-19 18:24:47] INFO: 匹配出的剧集 ==> 01 [2023-06-19 18:24:47] INFO: 通过剧集截断文件名 ==> Made-in-Abyss [2023-06-19 18:24:47] INFO: D:\D\Test\\Made-in-Abyss\Season01\已存在 -[2023-06-19 18:24:49] INFO: Link-D:\D\Test\[Airota][Made in Abyss][01][BDRip 1080p HEVC-10bit FLAC].CHS.ass << D:\D\Test\\Made-in-Abyss\Season01\S01E01.other.ass +[2023-06-19 18:24:49] INFO: Link-D:\D\Test\\Made-in-Abyss\Season01\S01E01.chs.ass << D:\D\Test\[Airota][Made in Abyss][01][BDRip 1080p HEVC-10bit FLAC].CHS.ass [2023-06-19 18:24:49] INFO: -------------------------------------------------------------------------------- [2023-06-19 18:24:49] INFO: 匹配出的剧集 ==> 01 [2023-06-19 18:24:49] INFO: 通过剧集截断文件名 ==> Jigokuraku -[2023-06-19 18:24:53] INFO: Link-D:\D\Test\[BeanSub&FZSD&LoliHouse] Jigokuraku - 01 [WebRip 1080p HEVC-10bit AAC ASSx2].简体中文.ass << D:\D\Test\\Jigokuraku\Season01\S01E01.chs.ass +[2023-06-19 18:24:53] INFO: Link-D:\D\Test\\Jigokuraku\Season01\S01E01.chs.ass << D:\D\Test\[BeanSub&FZSD&LoliHouse] Jigokuraku - 01 [WebRip 1080p HEVC-10bit AAC ASSx2].简体中文.ass [2023-06-19 18:24:53] INFO: -------------------------------------------------------------------------------- [2023-06-19 18:24:53] INFO: 匹配出的剧集 ==> 09 [2023-06-19 18:24:53] INFO: 通过剧集截断文件名 ==> Jigokuraku [2023-06-19 18:24:53] INFO: D:\D\Test\\Jigokuraku\Season01\已存在 -[2023-06-19 18:24:54] INFO: Link-D:\D\Test\[BeanSub&FZSD&LoliHouse] Jigokuraku - 09 [WebRip 1080p HEVC-10bit AAC ASSx2].简体中文.ass << D:\D\Test\\Jigokuraku\Season01\S01E09.chs.ass +[2023-06-19 18:24:54] INFO: Link-D:\D\Test\\Jigokuraku\Season01\S01E09.chs.ass << D:\D\Test\[BeanSub&FZSD&LoliHouse] Jigokuraku - 09 [WebRip 1080p HEVC-10bit AAC ASSx2].简体中文.ass [2023-06-19 18:24:54] INFO: 一切工作已经完成,用时7.112677097320557 ``` diff --git a/README.md b/README.md index 56ed910..fb72761 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ ## 待更新的功能 - [x] BgmApi支持 - - [ ] TMDBApi支持 + - [x] TMDBApi支持 - [ ] 本地番剧信息缓存 - [ ] 完全番剧特典支持 - [x] 清理过时日志 @@ -160,4 +160,11 @@ python3 -m pip install zhconv # Star History -[![Star History Chart](https://api.star-history.com/svg?repos=Abcuders/AutoAnimeMv&type=Date)](https://star-history.com/#Abcuders/AutoAnimeMv) + + + + + Star History Chart + + + diff --git a/TutorialsforDummies2.md b/TutorialsforDummies2.md index 0a1af5b..6b41b5d 100644 --- a/TutorialsforDummies2.md +++ b/TutorialsforDummies2.md @@ -18,4 +18,9 @@ *** # 🔥 前言 * **想必来到这里的大哥哥们都是杂~鱼吧,居然连README.md都看不懂,真的是杂~鱼一条啊,杂~鱼杂~鱼** -* **没办法,~~毕竟大哥哥们可都是只对二次元起O欲什么事都不会的废物肥宅~~,想当然是不会这种事的吧,就让我来手把手教杂鱼哥哥,你可是要心怀感激呀嘿嘿 ♡♡** \ No newline at end of file +* **没办法,~~毕竟大哥哥们可都是只对二次元起O欲什么事都不会的废物肥宅~~,想当然是不会这种事的吧,就让我来手把手教杂鱼哥哥,你可是要心怀感激呀嘿嘿 ♡♡** + +# 结语 +* **想不到居然有这么多杂~鱼专程来看呢,果然还是一个喜欢挨骂的变态呢变~态~杂~鱼~先~生** + +![AAM](https://count.getloli.com/get/@AAM) \ No newline at end of file diff --git a/config.ini.Template b/config.ini.Template index dd9063a..0a81215 100644 --- a/config.ini.Template +++ b/config.ini.Template @@ -4,6 +4,7 @@ HTTPPROXY = '' # Http代理 HTTPSPROXY = 'http://192.168.1.1:7890' # Https代理 ALLPROXY = '' # 全部代理 USEBGMAPI = True # 使用BgmApi +USETMDBAPI = True #使用TMDBApi USELINK = True # 使用硬链接开关 LINKFAILSUSEMOVEFLAGS = False #硬链接失败时使用MOVE RMLOGSFLAG = '7' # 日志文件超时删除