mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-27 12:00:32 +08:00
2.5.7 修复连接不上qb之后的处理逻辑,修复后缀丢失的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
import os.path
|
||||
from pathlib import PurePath, PureWindowsPath
|
||||
|
||||
|
||||
@@ -27,6 +28,7 @@ class Renamer:
|
||||
return recent_info, torrent_count
|
||||
|
||||
def split_path(self, path: str):
|
||||
suffix = os.path.splitext(path)[-1]
|
||||
path = path.replace(settings.download_path, "")
|
||||
path_parts = PurePath(path).parts \
|
||||
if PurePath(path).name != path \
|
||||
@@ -45,7 +47,7 @@ class Renamer:
|
||||
download_path = path_parts[1]
|
||||
except IndexError:
|
||||
download_path = ""
|
||||
return path_name, season, folder_name, download_path
|
||||
return path_name, season, folder_name, suffix, download_path
|
||||
|
||||
def run(self):
|
||||
recent_info, torrent_count = self.get_torrent_info()
|
||||
@@ -53,9 +55,10 @@ class Renamer:
|
||||
for info in recent_info:
|
||||
name = info.name
|
||||
torrent_hash = info.hash
|
||||
path_name, season, folder_name, _ = self.split_path(info.content_path)
|
||||
path_name, season, folder_name, suffix, _ = self.split_path(info.content_path)
|
||||
|
||||
try:
|
||||
new_name = self._renamer.download_parser(name, folder_name, season, settings.method)
|
||||
new_name = self._renamer.download_parser(name, folder_name, season, suffix, settings.method)
|
||||
if path_name != new_name:
|
||||
self.client.rename_torrent_file(torrent_hash, path_name, new_name)
|
||||
rename_count += 1
|
||||
@@ -71,7 +74,7 @@ class Renamer:
|
||||
recent_info, _ = self.get_torrent_info()
|
||||
for info in recent_info:
|
||||
torrent_hash = info.hash
|
||||
_, season, folder_name, download_path = self.split_path(info.content_path)
|
||||
_, season, folder_name, _, download_path = self.split_path(info.content_path)
|
||||
new_path = os.path.join(settings.download_path, folder_name, f"Season {season}")
|
||||
# print(new_path)
|
||||
self.client.move_torrent(torrent_hash, new_path)
|
||||
|
||||
@@ -12,8 +12,8 @@ from downloader.exceptions import ConflictError
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@qb_connect_failed_wait
|
||||
class QbDownloader:
|
||||
@qb_connect_failed_wait
|
||||
def __init__(self, host, username, password):
|
||||
self._client = Client(
|
||||
host=host,
|
||||
@@ -30,12 +30,15 @@ class QbDownloader:
|
||||
)
|
||||
time.sleep(settings.connect_retry_interval)
|
||||
|
||||
@qb_connect_failed_wait
|
||||
def prefs_init(self, prefs):
|
||||
return self._client.app_set_preferences(prefs=prefs)
|
||||
|
||||
@qb_connect_failed_wait
|
||||
def get_app_prefs(self):
|
||||
return self._client.app_preferences()
|
||||
|
||||
@qb_connect_failed_wait
|
||||
def torrents_info(self, status_filter, category):
|
||||
return self._client.torrents_info(status_filter, category)
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class RawParser:
|
||||
if l > compare:
|
||||
compare = l
|
||||
compare_idx = idx
|
||||
return split[compare_idx], split
|
||||
return split[compare_idx].strip(), split
|
||||
|
||||
@staticmethod
|
||||
def find_tags(other):
|
||||
|
||||
@@ -31,6 +31,7 @@ class DownloadParser:
|
||||
def rename_pn(self, info_dict):
|
||||
name = info_dict["name"]
|
||||
season = info_dict["season"]
|
||||
suffix = info_dict["suffix"]
|
||||
n = re.split(r"[\[\]()【】()]", name)
|
||||
file_name = name.replace(f"[{n[1]}]", "")
|
||||
if season < 10:
|
||||
@@ -42,13 +43,14 @@ class DownloadParser:
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{title} S{season}E{match_obj.group(2)}{path.splitext(name)[-1]}",
|
||||
f"{title} S{season}E{match_obj.group(2)}{suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
def rename_advance(self, info_dict):
|
||||
name = info_dict["name"]
|
||||
folder_name = info_dict["folder_name"]
|
||||
suffix = info_dict["suffix"]
|
||||
season = info_dict["season"]
|
||||
n = re.split(r"[\[\]()【】()]", name)
|
||||
file_name = name.replace(f"[{n[1]}]", "")
|
||||
@@ -60,12 +62,13 @@ class DownloadParser:
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{folder_name} S{season}E{match_obj.group(2)}{path.splitext(name)[-1]}",
|
||||
f"{folder_name} S{season}E{match_obj.group(2)}{suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
def rename_no_season_pn(self, info_dict):
|
||||
name = info_dict["name"]
|
||||
suffix = info_dict["suffix"]
|
||||
n = re.split(r"[\[\]()【】()]", name)
|
||||
file_name = name.replace(f"[{n[1]}]", "")
|
||||
for rule in self.rules:
|
||||
@@ -75,38 +78,33 @@ class DownloadParser:
|
||||
new_name = re.sub(
|
||||
r"[\[\]]",
|
||||
"",
|
||||
f"{title} E{match_obj.group(2)}{path.splitext(name)[-1]}",
|
||||
f"{title} E{match_obj.group(2)}{suffix}",
|
||||
)
|
||||
return new_name
|
||||
|
||||
def download_rename(self, name, folder_name, season, method):
|
||||
def rename_none(self, info_dict):
|
||||
return info_dict["name"]
|
||||
|
||||
def download_rename(self, name, folder_name, season,suffix, method):
|
||||
info_dict = {
|
||||
"name": name,
|
||||
"folder_name": folder_name,
|
||||
"season": season,
|
||||
"suffix": suffix
|
||||
}
|
||||
method_dict = {
|
||||
"normal": self.rename_normal,
|
||||
"pn": self.rename_pn,
|
||||
"advance": self.rename_advance,
|
||||
"no_season_pn": self.rename_no_season_pn,
|
||||
"none": self.rename_none
|
||||
}
|
||||
logger.debug(f"Name: {folder_name}, File type: {path.splitext(name)[-1]}, Season {season}")
|
||||
return method_dict[method](info_dict)
|
||||
# if method.lower() == "pn":
|
||||
# return self.rename_pn(name, season)
|
||||
# elif method.lower() == "normal":
|
||||
# return self.rename_normal(name, season)
|
||||
# elif method.lower() == "none":
|
||||
# return name
|
||||
# elif method.lower() == "advance":
|
||||
# return self.rename_advance(name, folder_name, season)
|
||||
# elif method.lower() == "no_season_pn":
|
||||
# return self.rename_no_season_pn(name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = "[NC-Raws] 來自深淵 烈日的黃金鄉 - 01 (Baha 1920x1080 AVC AAC MP4) [89D4923F].mp4"
|
||||
rename = DownloadParser()
|
||||
new_name = rename.download_rename(name, "Made abyess", 1, "pn")
|
||||
new_name = rename.download_rename(name, "Made abyess", 1, ".mp4", "pn")
|
||||
print(new_name)
|
||||
@@ -14,8 +14,8 @@ class TitleParser:
|
||||
def raw_parser(self, raw):
|
||||
return self._raw_parser.analyse(raw)
|
||||
|
||||
def download_parser(self, download_raw, folder_name, season, method=settings.method):
|
||||
return self._download_parser.download_rename(download_raw, folder_name, season, method)
|
||||
def download_parser(self, download_raw, folder_name, season, suffix, method=settings.method):
|
||||
return self._download_parser.download_rename(download_raw, folder_name, season, suffix, method)
|
||||
|
||||
def return_dict(self, raw):
|
||||
tmdb = TMDBMatcher()
|
||||
|
||||
Reference in New Issue
Block a user