From 429bf38d34d27acf787bf7f28d30b7c93e7b45c9 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Thu, 19 May 2022 17:20:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E5=8C=B9=E9=85=8D=E8=A7=84?= =?UTF-8?q?=E5=88=99=EF=BC=8C=E9=80=82=E9=85=8D=E7=BB=9D=E5=A4=A7=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=B9=95=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoBangumi2.0/app/auto_set_rule.py | 4 +- AutoBangumi2.0/app/collect_bangumi_info.py | 123 +++++++------ AutoBangumi2.0/app/rename_qb.py | 8 +- AutoBangumi2.0/app/rule.json | 48 +++++ test/bangumi.json | 194 ++++++++++++++++++++- test/rule.json | 46 ++--- test/test.py | 136 +++++++++------ test/test2.py | 12 +- 8 files changed, 417 insertions(+), 154 deletions(-) create mode 100644 AutoBangumi2.0/app/rule.json diff --git a/AutoBangumi2.0/app/auto_set_rule.py b/AutoBangumi2.0/app/auto_set_rule.py index 267f25a0..3a76e6ca 100644 --- a/AutoBangumi2.0/app/auto_set_rule.py +++ b/AutoBangumi2.0/app/auto_set_rule.py @@ -39,10 +39,10 @@ class SetRule: self.qb.rss_set_rule(rule_name=bangumi_name, rule_def=rule) def run(self): - sys.stdout.write(f"[{time.strftime('%X')}] Start adding rules." + "\n") + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] Start adding rules." + "\n") sys.stdout.flush() for info in self.bangumi_info: self.set_rule(info["title"], info["season"]) - sys.stdout.write(f"[{time.strftime('%X')}] Finished." + "\n") + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] Finished." + "\n") sys.stdout.flush() diff --git a/AutoBangumi2.0/app/collect_bangumi_info.py b/AutoBangumi2.0/app/collect_bangumi_info.py index 8114d7a9..17b2608c 100644 --- a/AutoBangumi2.0/app/collect_bangumi_info.py +++ b/AutoBangumi2.0/app/collect_bangumi_info.py @@ -9,69 +9,80 @@ import re class CollectRSS: def __init__(self, config, info): - self.info = info - self.config = config - self.bangumi_title = [] - - def collect_info(self): - episode_rules = [r'(.*)\[(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)', - r'(.*)\[E(\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)?\](.*)', - r'(.*)\[第(\d*\.*\d*)话(?:END)?\](.*)', - r'(.*)\[第(\d*\.*\d*)話(?:END)?\](.*)', - r'(.*)第(\d*\.*\d*)话(?:END)?(.*)', - r'(.*)第(\d*\.*\d*)話(?:END)?(.*)', - r'(.*)- (\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?:END)? (.*)'] - url = self.config["rss_link"] - rss = requests.get(url, 'utf-8') + self.bangumi_list = [] + with open("rule.json") as f: + self.rules = json.load(f) + rss = requests.get(config["rss_link"], 'utf-8') soup = BeautifulSoup(rss.text, 'xml') - item = soup.find_all('item') - for a in item: - name = a.title.string - pattern = r'\[|\]|\u3010|\u3011|\★|\*|\(|\)|\(|\)|\_' - for i in range(2): - n = re.split(pattern, name) - try: - if re.search("\d{2,3}^月", n[1]) is None: - name = re.sub(f'\[{n[1]}\]|【{n[1]}】|★{n[1]}★', '', name).strip() - else: - break - except IndexError: - break - for rule in episode_rules: - match_obj = re.match(rule, name, re.I) - if match_obj is not None: - new_name = re.sub(r'\[|\]', '', f'{match_obj.group(1)}') - new_name = re.split(r'/', new_name)[-1].strip() - if new_name not in self.bangumi_title: - self.bangumi_title.append(new_name) + self.items = soup.find_all('item') + self.info = info + + def get_info_list(self): + split_rule = r"\[|\]|\【|\】|\★|\(|\)|\(|\)" + last_rule = r"(.*)( \-)" + for item in self.items: + name = item.title.string + exit_flag = False + for rule in self.rules: + for group in rule["group_name"]: + if re.search(group, name): + exit_flag = True + n = re.split(split_rule, name) + while '' in n: + n.remove('') + while ' ' in n: + n.remove(' ') + try: + bangumi_title = n[rule['name_position']].strip() + except IndexError: + continue + sub_title = re.sub(r"[^\x00-\xff]{1,}| \d{1,2}|\·","",bangumi_title) + b = re.split(r"\/|\_", sub_title) + while '' in b: + b.remove('') + pre_name = max(b, key=len, default='').strip() + if pre_name != '': + bangumi_title = pre_name + for i in range(2): + match_obj = re.match(last_rule, bangumi_title, re.I) + if match_obj is not None: + bangumi_title = match_obj.group(1).strip() + match_obj = re.match(r"(S\d{1,2}(.*))", bangumi_title, re.I) + if match_obj is not None: + bangumi_title = match_obj.group(2).strip() + if bangumi_title not in self.bangumi_list: + self.bangumi_list.append(bangumi_title) + break + if exit_flag: + break + if not exit_flag: + print(f"ERROR Not match with {name}") + + def put_info_json(self): + season_match = r"(.*)(Season \d{1,2}|S\d{1,2}|第.*季)" - def write_info(self): - bangumi_info = self.info had_data = [] - for data in bangumi_info: + for data in self.info: had_data.append(data["title"]) - for title in self.bangumi_title: - a = re.match(r'(.*)(S.\d)', title, re.I) - if a is not None: - title = a.group(1).strip() - season = a.group(2).strip() + + for title in self.bangumi_list: + match_title_season = re.match(season_match, title, re.I) + if match_title_season is not None: + json_title = match_title_season.group(1).strip() + json_season = match_title_season.group(2) else: - season = '' - if title not in had_data: - bangumi_info.append({ - "title": title, - "season": season + json_season = '' + json_title = title + if json_title not in had_data: + self.info.append({ + "title": json_title, + "season": json_season }) - sys.stdout.write(f"[{time.strftime('%X')}] add {title} {season}" + "\n") + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] add {json_title} {json_season}" + "\n") sys.stdout.flush() - # 写入数据 with open("/config/bangumi.json", 'w', encoding='utf8') as f: - json.dump(bangumi_info, f, indent=4, separators=(',', ': '), ensure_ascii=False) + json.dump(self.info, f, indent=4, separators=(',', ': '), ensure_ascii=False) def run(self): - sys.stdout.write(f"[{time.strftime('%X')}] Start scanning RSS Feed." + "\n") - sys.stdout.flush() - self.collect_info() - self.write_info() - sys.stdout.write(f"[{time.strftime('%X')}] Finished." + "\n") - sys.stdout.flush() \ No newline at end of file + self.get_info_list() + self.put_info_json() \ No newline at end of file diff --git a/AutoBangumi2.0/app/rename_qb.py b/AutoBangumi2.0/app/rename_qb.py index ca5169ff..2ae4e3ff 100644 --- a/AutoBangumi2.0/app/rename_qb.py +++ b/AutoBangumi2.0/app/rename_qb.py @@ -54,7 +54,7 @@ class QbittorrentRename: def rename(self): if self.path_name != self.new_name: self.qbt_client.torrents_rename_file(torrent_hash=self.hash, old_path=self.path_name, new_path=self.new_name) - sys.stdout.write(f"[{time.strftime('%X')}] {self.path_name} >> {self.new_name}") + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] {self.path_name} >> {self.new_name}") self.count += 1 else: return @@ -66,9 +66,9 @@ class QbittorrentRename: self.path_name = None def print_result(self): - sys.stdout.write(f"[{time.strftime('%X')}] 已完成对{self.torrent_count}个文件的检查" + '\n') - sys.stdout.write(f"[{time.strftime('%X')}] 已对其中{self.count}个文件进行重命名" + '\n') - sys.stdout.write(f"[{time.strftime('%X')}] 完成" + '\n') + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] 已完成对{self.torrent_count}个文件的检查" + '\n') + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] 已对其中{self.count}个文件进行重命名" + '\n') + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] 完成" + '\n') sys.stdout.flush() def run(self): diff --git a/AutoBangumi2.0/app/rule.json b/AutoBangumi2.0/app/rule.json new file mode 100644 index 00000000..e5ead51b --- /dev/null +++ b/AutoBangumi2.0/app/rule.json @@ -0,0 +1,48 @@ +[ + { + "group_name": [ + "Lilith-Raws", + "NC-Raws", + "Skymoon-Raws", + "天月搬运组", + "LoliHouse", + "猎户不鸽发布组", + "NaN-Raws", + "猎户随缘发布组", + "桜都字幕组", + "澄空学园&雪飘工作室", + "千夏字幕组", + "IET字幕组", + "离谱Sub", + "酷漫404", + "星空字幕组", + "轻之国度字幕组", + "枫叶字幕组", + "雪飘工作室", + "豌豆字幕组", + "云光字幕组", + "悠哈璃羽字幕社", + "桜都字幕组", + "ANi", + "❀拨雪寻春❀", + "极彩字幕组", + "悠哈璃羽字幕社", + "漫猫字幕组", + "MingY" + ], + "name_position": 1 + }, + { + "group_name": [ + "喵萌奶茶屋", + "爱恋字母社", + "诸神字幕组", + "驯兽师联盟", + "夏沐字幕组", + "幻樱", + "动漫国字幕组", + "SweetSub&圆环记录攻略组" + ], + "name_position": 2 + } +] \ No newline at end of file diff --git a/test/bangumi.json b/test/bangumi.json index f6a2d0cb..672169a8 100644 --- a/test/bangumi.json +++ b/test/bangumi.json @@ -1,6 +1,198 @@ [ { - "title": "simple", + "title": "Aharen-san wa Hakarenai", + "season": "" + }, + { + "title": "Tomodachi Game", + "season": "" + }, + { + "title": "Ousama Ranking", + "season": "" + }, + { + "title": "Komi-san wa, Komyushou Desu.", + "season": "" + }, + { + "title": "Detective Conan: Zero no Tea Time", + "season": "" + }, + { + "title": "Tate no Yuusha no Nariagari", + "season": "S02" + }, + { + "title": "Deaimon", + "season": "" + }, + { + "title": "Ya Boy Kongming", + "season": "" + }, + { + "title": "Kawaii dake ja Nai Shikimori-san", + "season": "" + }, + { + "title": "相合之物", + "season": "" + }, + { + "title": "Kunoichi Tsubaki no Mune no Uchi", + "season": "" + }, + { + "title": "RPG Fudousan", + "season": "" + }, + { + "title": "Deaimon Recipe for Happiness", + "season": "" + }, + { + "title": "Machikado Mazoku", + "season": "S2" + }, + { + "title": "辉夜姬想让人告白 一超级浪漫一", + "season": "" + }, + { + "title": "辉夜大小姐想让我告白 一终极浪漫一", + "season": "" + }, + { + "title": "RPG", + "season": "" + }, + { + "title": "间谍家家酒", + "season": "" + }, + { + "title": "间谍过家家", + "season": "" + }, + { + "title": "RPG Real Estate", + "season": "" + }, + { + "title": "Bubble", + "season": "" + }, + { + "title": "盾之勇者成名录_", + "season": "第二季" + }, + { + "title": "The Rising of the Shield Hero", + "season": "S2" + }, + { + "title": "Tate no Yuusha no Nariagari", + "season": "S2" + }, + { + "title": "A", + "season": "" + }, + { + "title": "Shijou Saikyou no Daimaou", + "season": "" + }, + { + "title": "Birdie Wing", + "season": "" + }, + { + "title": "Interstellar Wanderer", + "season": "" + }, + { + "title": "4", + "season": "" + }, + { + "title": "Yuusha Yamemasu", + "season": "" + }, + { + "title": "Birdie Wing: Golf Girls' Story", + "season": "" + }, + { + "title": "理科生坠入情网故尝试证明", + "season": "" + }, + { + "title": "小鸟之翼", + "season": "" + }, + { + "title": "Birdie Wing Golf Girls Story", + "season": "" + }, + { + "title": "Shin Ikki Tousen", + "season": "" + }, + { + "title": "Yuusha, Yamemasu", + "season": "" + }, + { + "title": "夏日时光 / 夏日重现", + "season": "" + }, + { + "title": "Kaginado", + "season": "S02" + }, + { + "title": "Seijo no Maryoku wa Bannou Desu", + "season": "" + }, + { + "title": "键等_", + "season": "第二季" + }, + { + "title": "Date A Live IV", + "season": "" + }, + { + "title": "KAGINADO", + "season": "S2" + }, + { + "title": "Kaginado", + "season": "S2" + }, + { + "title": "勇者、辞职不干了", + "season": "" + }, + { + "title": "Im Quitting Heroing", + "season": "" + }, + { + "title": "Foodie Boys Classic of Mountains & Seas", + "season": "" + }, + { + "title": "My Journey in an Alternate World", + "season": "" + }, + { + "title": "A Record Of Mortal's Journey To Immortality", + "season": "" + }, + { + "title": "Magia Record Final Season", "season": "" } ] \ No newline at end of file diff --git a/test/rule.json b/test/rule.json index 197e7140..e5ead51b 100644 --- a/test/rule.json +++ b/test/rule.json @@ -5,24 +5,7 @@ "NC-Raws", "Skymoon-Raws", "天月搬运组", - "LoliHouse" - ], - "first_position": [1], - "split": "/|-", - "name_position": [-2], - "episode_position":[-1] - }, - { - "group_name": [ - "桜都字幕组" - ], - "first_position": [1,2], - "split": "/|-", - "name_position": [-2], - "episode_position":[-1] - }, - { - "group_name": [ + "LoliHouse", "猎户不鸽发布组", "NaN-Raws", "猎户随缘发布组", @@ -38,10 +21,16 @@ "雪飘工作室", "豌豆字幕组", "云光字幕组", - "悠哈璃羽字幕社" - ], - "name_position": [1,2], - "second_split": false + "悠哈璃羽字幕社", + "桜都字幕组", + "ANi", + "❀拨雪寻春❀", + "极彩字幕组", + "悠哈璃羽字幕社", + "漫猫字幕组", + "MingY" + ], + "name_position": 1 }, { "group_name": [ @@ -51,16 +40,9 @@ "驯兽师联盟", "夏沐字幕组", "幻樱", - "动漫国字幕组" + "动漫国字幕组", + "SweetSub&圆环记录攻略组" ], - "name_position": [2,3], - "second_split": false - }, - { - "group_name": [ - "漫猫字幕组" - ], - "name_position": [3,4], - "second_split": false + "name_position": 2 } ] \ No newline at end of file diff --git a/test/test.py b/test/test.py index 129c5779..2fbbb764 100644 --- a/test/test.py +++ b/test/test.py @@ -1,57 +1,93 @@ import re +import sys +import time import requests from bs4 import BeautifulSoup import json -url = "https://mikanani.me/RSS/Classic" -rss = requests.get(url, 'utf-8') -soup = BeautifulSoup(rss.text, 'xml') -items = soup.find_all('item') -with open("rule.json") as f: - rules = json.load(f) -split_rule = r"\[|\]|\【|\】|\★|\(|\)|\(|\)" -bangumi_list = [] -bangumi_title = '' -for item in items: - name = item.title.string - bangumi_title = '' - exit_flag = False - for rule in rules: - for group in rule["group_name"]: - if re.search(group, name): - exit_flag = True - n = re.split(split_rule, name) - while '' in n: - n.remove('') - for i in rule["name_position"]: - bangumi_title = bangumi_title + ' ' + n[i].strip() - if bangumi_title not in bangumi_list: - bangumi_list.append(bangumi_title) - break - if exit_flag: - break -season_rule = r"Season \d{1,2}|S\d{1,2}|第.*季|.*期" -episode_rule = r"\d{1,2}|第\d{1,2}话" -for item in bangumi_list: - season = re.findall(season_rule, item) - title = re.sub(season_rule, '', item) - try: - season = season[-1] - except IndexError: - season = "" - episode = re.findall(episode_rule, title) - try: - episode = episode[-1] - except IndexError: - episode = "" - title = re.sub(episode_rule, '', title) - t = re.split(r"/|_", title) - while "" in t: - t.remove("") - name = t[-1].strip() - print(name) - print(season) - print(episode) -print(bangumi_list) \ No newline at end of file +class CollectRSS: + def __init__(self, info): + self.bangumi_list = [] + with open("rule.json") as f: + self.rules = json.load(f) + url = "https://mikanani.me/RSS/Classic" + rss = requests.get(url, 'utf-8') + soup = BeautifulSoup(rss.text, 'xml') + self.items = soup.find_all('item') + self.info = info + + def get_info_list(self): + split_rule = r"\[|\]|\【|\】|\★|\(|\)|\(|\)" + last_rule = r"(.*)( \-)" + for item in self.items: + name = item.title.string + exit_flag = False + for rule in self.rules: + for group in rule["group_name"]: + if re.search(group, name): + exit_flag = True + n = re.split(split_rule, name) + while '' in n: + n.remove('') + while ' ' in n: + n.remove(' ') + try: + bangumi_title = n[rule['name_position']].strip() + except IndexError: + continue + sub_title = re.sub(r"[^\x00-\xff]{1,}| \d{1,2}|\·","",bangumi_title) + b = re.split(r"\/|\_", sub_title) + while '' in b: + b.remove('') + pre_name = max(b, key=len, default='').strip() + if pre_name != '': + bangumi_title = pre_name + for i in range(2): + match_obj = re.match(last_rule, bangumi_title, re.I) + if match_obj is not None: + bangumi_title = match_obj.group(1).strip() + match_obj = re.match(r"(S\d{1,2}(.*))", bangumi_title, re.I) + if match_obj is not None: + bangumi_title = match_obj.group(2).strip() + if bangumi_title not in self.bangumi_list: + self.bangumi_list.append(bangumi_title) + break + if exit_flag: + break + if not exit_flag: + print(f"ERROR Not match with {name}") + + def put_info_json(self): + season_match = r"(.*)(Season \d{1,2}|S\d{1,2}|第.*季)" + + had_data = [] + for data in self.info: + had_data.append(data["title"]) + + for title in self.bangumi_list: + match_title_season = re.match(season_match, title, re.I) + if match_title_season is not None: + json_title = match_title_season.group(1).strip() + json_season = match_title_season.group(2) + else: + json_season = '' + json_title = title + if json_title not in had_data: + self.info.append({ + "title": json_title, + "season": json_season + }) + sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}] add {json_title} {json_season}" + "\n") + sys.stdout.flush() + with open("bangumi.json", 'w', encoding='utf8') as f: + json.dump(self.info, f, indent=4, separators=(',', ': '), ensure_ascii=False) + + +if __name__ == "__main__": + with open("bangumi.json") as f: + info = json.load(f) + cr = CollectRSS(info) + cr.get_info_list() + cr.put_info_json() \ No newline at end of file diff --git a/test/test2.py b/test/test2.py index a3684833..2ed93c65 100644 --- a/test/test2.py +++ b/test/test2.py @@ -1,10 +1,4 @@ -import re +import time +import sys -import requests - -name = "[IET字幕组][闪电十一人 FF篇][01][1080P][WebRip][繁日双语][AVC AAC][MP4]" -split_rule = r"\[|\]|\【|\】|\★|\(|\)|\(|\)" -n = re.split(split_rule, name) -while '' in n: - n.remove('') -print(n) \ No newline at end of file +sys.stdout.write(f"[{time.strftime('%Y-%m-%d %X')}]") \ No newline at end of file