mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-05-11 10:35:50 +08:00
修复重命名组件出现的问题
This commit is contained in:
@@ -74,7 +74,6 @@ def run():
|
||||
quit()
|
||||
download_client.rss_feed()
|
||||
rss_collector = RSSCollector()
|
||||
renamer = Renamer(download_client)
|
||||
while True:
|
||||
bangumi_data = load_data_file()
|
||||
try:
|
||||
@@ -87,7 +86,7 @@ def run():
|
||||
time.sleep(settings.first_sleep)
|
||||
bangumi_data["first_run"] = False
|
||||
save_data_file(bangumi_data)
|
||||
renamer.run()
|
||||
Renamer(download_client).run()
|
||||
time.sleep(settings.sleep_time)
|
||||
except Exception as e:
|
||||
if args.debug:
|
||||
|
||||
@@ -8,6 +8,7 @@ class Episode:
|
||||
def __init__(self) -> None:
|
||||
self.raw: str = None
|
||||
self.name: str = None
|
||||
self.official: str = None
|
||||
|
||||
@dataclass
|
||||
class SeasonInfo:
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
from thefuzz import fuzz
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO 模糊匹配模块
|
||||
class FuzzMatch:
|
||||
def __init__(self, anidb_data):
|
||||
self.match_data = anidb_data
|
||||
|
||||
def match(self, title, info):
|
||||
compare_value = []
|
||||
for type in ["main", "en", "ja", "zh-Hans", "zh-Hant"]:
|
||||
if info[type] is not None:
|
||||
a = fuzz.ratio(title.replace(" ", "").lower(), info[type].replace(" ", "").lower())
|
||||
compare_value.append(a)
|
||||
for compare in info["other"]:
|
||||
a = fuzz.ratio(title.replace(" ", "").lower(), compare.replace(" ", "").lower())
|
||||
compare_value.append(a)
|
||||
return max(compare_value)
|
||||
|
||||
# class FuzzMatch:
|
||||
# def __init__(self, anidb_data):
|
||||
# self.match_data = anidb_data
|
||||
#
|
||||
# def fuzz(self, raw_name):
|
||||
# fuzz.radio()
|
||||
def find_max_name(self, title):
|
||||
value = []
|
||||
for info in self.match_data:
|
||||
a = self.match(title, info)
|
||||
value.append([a, info])
|
||||
logger.debug(max(value))
|
||||
return max(value)
|
||||
|
||||
@@ -17,14 +17,14 @@ class Renamer:
|
||||
self.torrent_count = len(self.recent_info)
|
||||
|
||||
def print_result(self):
|
||||
logger.info(f"Finished checking {self.torrent_count} file's name.")
|
||||
logger.info(f"Finished checking {self.torrent_count} files' name.")
|
||||
logger.info(f"Renamed {self.rename_count} files.")
|
||||
logger.info(f"Finished rename process.")
|
||||
|
||||
def run(self):
|
||||
method_dict = {"pn": self._renamer.rename_pn, "normal": self._renamer.rename_normal}
|
||||
if settings.method not in method_dict:
|
||||
logger.error(f"error method")
|
||||
logger.error(f"Error method")
|
||||
else:
|
||||
for i in range(0, self.torrent_count):
|
||||
info = self.recent_info[i]
|
||||
@@ -35,11 +35,13 @@ class Renamer:
|
||||
else PureWindowsPath(info.content_path).name
|
||||
try:
|
||||
new_name = method_dict[settings.method](name)
|
||||
logger.debug(f"{path_name}")
|
||||
logger.debug(f"{new_name}")
|
||||
logger.debug(f"Origin name: {path_name}")
|
||||
logger.debug(f"New name: {new_name}")
|
||||
if path_name != new_name:
|
||||
self.client.rename_torrent_file(hash, path_name, new_name)
|
||||
self.rename_count += 1
|
||||
else:
|
||||
continue
|
||||
except:
|
||||
logger.warning(f"{path_name} rename failed")
|
||||
if settings.remove_bad_torrent:
|
||||
|
||||
@@ -97,11 +97,11 @@ def get_title(id):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ids = get_list(2022, 2)
|
||||
ids = get_list(2022, 0)
|
||||
json = []
|
||||
for id in ids:
|
||||
data = get_title(id)
|
||||
print(data)
|
||||
time.sleep(2.5)
|
||||
json.append(data)
|
||||
json_config.save("season_summer.json", json)
|
||||
json_config.save("season_winter.json", json)
|
||||
|
||||
Reference in New Issue
Block a user